|
24 | 24 |
|
25 | 25 | use PackageFactory\ComponentEngine\Module\ModuleId; |
26 | 26 | use PackageFactory\ComponentEngine\Parser\Ast\EnumDeclarationNode; |
| 27 | +use PackageFactory\ComponentEngine\Parser\Ast\ExpressionNode; |
27 | 28 | use PackageFactory\ComponentEngine\Parser\Ast\IdentifierNode; |
| 29 | +use PackageFactory\ComponentEngine\Target\Php\Transpiler\Expression\ExpressionTranspiler; |
28 | 30 | use PackageFactory\ComponentEngine\Test\Unit\TypeSystem\Scope\Fixtures\DummyScope; |
29 | 31 | use PackageFactory\ComponentEngine\Target\Php\Transpiler\Identifier\IdentifierTranspiler; |
30 | 32 | use PackageFactory\ComponentEngine\TypeSystem\Type\EnumType\EnumStaticType; |
| 33 | +use PackageFactory\ComponentEngine\TypeSystem\Type\StringType\StringType; |
31 | 34 | use PHPUnit\Framework\TestCase; |
32 | 35 |
|
33 | 36 | final class IdentifierTranspilerTest extends TestCase |
@@ -82,4 +85,36 @@ public function transpilesIdentifierNodesReferringToEnums(): void |
82 | 85 | $actualTranspilationResult |
83 | 86 | ); |
84 | 87 | } |
| 88 | + |
| 89 | + public static function identifierInParenthesisExamples(): mixed |
| 90 | + { |
| 91 | + // @todo find a better place for these tests, as we actually test the ExpressionNode |
| 92 | + return [ |
| 93 | + '(foo)' => ['(foo)', '$this->foo'], |
| 94 | + '((foo))' => ['((foo))', '$this->foo'], |
| 95 | + '(((foo)))' => ['(((foo)))', '$this->foo'] |
| 96 | + ]; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * @dataProvider identifierInParenthesisExamples |
| 101 | + * @test |
| 102 | + */ |
| 103 | + public function identifierInParenthesis(string $expression, string $expectedTranspilationResult): void |
| 104 | + { |
| 105 | + $expressionTranspiler = new ExpressionTranspiler( |
| 106 | + scope: new DummyScope([ |
| 107 | + "foo" => StringType::get() |
| 108 | + ]) |
| 109 | + ); |
| 110 | + |
| 111 | + $actualTranspilationResult = $expressionTranspiler->transpile( |
| 112 | + ExpressionNode::fromString($expression) |
| 113 | + ); |
| 114 | + |
| 115 | + $this->assertEquals( |
| 116 | + $expectedTranspilationResult, |
| 117 | + $actualTranspilationResult |
| 118 | + ); |
| 119 | + } |
85 | 120 | } |
0 commit comments