|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @see https://github.com/open-code-modeling/php-code-ast for the canonical source repository |
| 5 | + * @copyright https://github.com/open-code-modeling/php-code-ast/blob/master/COPYRIGHT.md |
| 6 | + * @license https://github.com/open-code-modeling/php-code-ast/blob/master/LICENSE.md MIT License |
| 7 | + */ |
| 8 | + |
| 9 | +declare(strict_types=1); |
| 10 | + |
| 11 | +namespace OpenCodeModelingTest\CodeAst\Code; |
| 12 | + |
| 13 | +use Generator; |
| 14 | +use OpenCodeModeling\CodeAst\Code\ValueGenerator; |
| 15 | +use PhpParser\Node; |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | + |
| 18 | +final class ValueGeneratorTest extends TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * Values are: type, expected output |
| 22 | + * |
| 23 | + * @return Generator |
| 24 | + */ |
| 25 | + public function provideTypes(): Generator |
| 26 | + { |
| 27 | + yield 'null' => [null, Node\Expr\ConstFetch::class]; |
| 28 | + yield 'string' => ['test string', Node\Scalar\String_::class]; |
| 29 | + yield 'bool' => [true, Node\Expr\ConstFetch::class]; |
| 30 | + yield 'int' => [1, Node\Scalar\LNumber::class]; |
| 31 | + yield 'integer' => [10, Node\Scalar\LNumber::class]; |
| 32 | + yield 'float' => [2.523, Node\Scalar\DNumber::class]; |
| 33 | + yield 'double' => [7E-10, Node\Scalar\DNumber::class]; |
| 34 | + yield 'array' => [['one', 'two'], Node\Expr\Array_::class]; |
| 35 | + yield 'other node expression' => [new Node\Expr\Array_(), Node\Expr\Array_::class]; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * @test |
| 40 | + * @dataProvider provideTypes |
| 41 | + * @param mixed $value |
| 42 | + * @param string $expectedGeneratedValue |
| 43 | + */ |
| 44 | + public function it_supports_type($value, string $expectedGeneratedValue): void |
| 45 | + { |
| 46 | + $value = new ValueGenerator($value); |
| 47 | + |
| 48 | + $this->assertInstanceOf($expectedGeneratedValue, $value->generate()); |
| 49 | + } |
| 50 | +} |
0 commit comments