|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\PhpDocParser\Ast\ToString; |
| 4 | + |
| 5 | +use Generator; |
| 6 | +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprArrayItemNode; |
| 7 | +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprArrayNode; |
| 8 | +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprFalseNode; |
| 9 | +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprFloatNode; |
| 10 | +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode; |
| 11 | +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprNullNode; |
| 12 | +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode; |
| 13 | +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprTrueNode; |
| 14 | +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode; |
| 15 | +use PHPStan\PhpDocParser\Ast\Node; |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | + |
| 18 | +class ConstExprToStringTest extends TestCase |
| 19 | +{ |
| 20 | + |
| 21 | + /** |
| 22 | + * @dataProvider provideConstExprCases |
| 23 | + */ |
| 24 | + public function testToString(string $expected, Node $node): void |
| 25 | + { |
| 26 | + $this->assertSame($expected, (string) $node); |
| 27 | + } |
| 28 | + |
| 29 | + public static function provideConstExprCases(): Generator |
| 30 | + { |
| 31 | + yield from [ |
| 32 | + ['null', new ConstExprNullNode()], |
| 33 | + ['true', new ConstExprTrueNode()], |
| 34 | + ['false', new ConstExprFalseNode()], |
| 35 | + ['8', new ConstExprIntegerNode('8')], |
| 36 | + ['21.37', new ConstExprFloatNode('21.37')], |
| 37 | + ['foo', new ConstExprStringNode('foo')], |
| 38 | + ['FooBar', new ConstFetchNode('', 'FooBar')], |
| 39 | + ['Foo\\Bar::Baz', new ConstFetchNode('Foo\\Bar', 'Baz')], |
| 40 | + ['[]', new ConstExprArrayNode([])], |
| 41 | + [ |
| 42 | + '[foo, 4 => foo, bar => baz]', |
| 43 | + new ConstExprArrayNode([ |
| 44 | + new ConstExprArrayItemNode(null, new ConstExprStringNode('foo')), |
| 45 | + new ConstExprArrayItemNode(new ConstExprIntegerNode('4'), new ConstExprStringNode('foo')), |
| 46 | + new ConstExprArrayItemNode(new ConstExprStringNode('bar'), new ConstExprStringNode('baz')), |
| 47 | + ]), |
| 48 | + ], |
| 49 | + ]; |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments