@@ -12,6 +12,7 @@ public function setUp(): void {
1212 }
1313
1414 public function testNullableString (): void {
15+ // private ?string $nullableString;
1516 $ parser = (new ParserFactory )->create (ParserFactory::PREFER_PHP7 );
1617 $ filename = sprintf ('%s/php8/product/Product.php ' , $ this ->fixtureDir );
1718 try {
@@ -20,22 +21,23 @@ public function testNullableString(): void {
2021 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
2122 }
2223
23- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [0 ], PhpTypeExpression::TYPE , ['hoge ' , 'fuga ' , 'product ' ]);
24+ $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [0 ], PhpTypeExpression::VAR , ['hoge ' , 'fuga ' , 'product ' ]);
2425 $ types = $ expression ->getTypes ();
2526
2627 $ this ->assertSame ([], $ types [0 ]->getNamespace (), 'namespace ' );
2728 $ this ->assertSame ('string ' , $ types [0 ]->getName (), 'name ' );
2829 $ this ->assertSame (true , $ types [0 ]->getNullable (), 'nullable ' );
2930 }
3031 public function testIntOrString (): void {
32+ // private int|string $intOrString;
3133 $ parser = (new ParserFactory )->create (ParserFactory::PREFER_PHP7 );
3234 $ filename = sprintf ('%s/php8/product/Product.php ' , $ this ->fixtureDir );
3335 try {
3436 $ ast = $ parser ->parse (file_get_contents ($ filename ));
3537 } catch (Error $ error ) {
3638 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
3739 }
38- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [1 ], PhpTypeExpression::TYPE , ['hoge ' , 'fuga ' , 'product ' ]);
40+ $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [1 ], PhpTypeExpression::VAR , ['hoge ' , 'fuga ' , 'product ' ]);
3941 $ types = $ expression ->getTypes ();
4042
4143 $ this ->assertSame ([], $ types [0 ]->getNamespace (), 'namespace ' );
@@ -46,48 +48,84 @@ public function testIntOrString(): void {
4648 $ this ->assertSame (false , $ types [1 ]->getNullable (), 'nullable ' );
4749 }
4850 public function testPrice (): void {
51+ // private Price $price;
4952 $ parser = (new ParserFactory )->create (ParserFactory::PREFER_PHP7 );
5053 $ filename = sprintf ('%s/php8/product/Product.php ' , $ this ->fixtureDir );
5154 try {
5255 $ ast = $ parser ->parse (file_get_contents ($ filename ));
5356 } catch (Error $ error ) {
5457 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
5558 }
56- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [2 ], PhpTypeExpression::TYPE , ['hoge ' , 'fuga ' , 'product ' ]);
59+ $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [2 ], PhpTypeExpression::VAR , ['hoge ' , 'fuga ' , 'product ' ]);
5760 $ types = $ expression ->getTypes ();
5861
5962 $ this ->assertSame (['hoge ' , 'fuga ' , 'product ' ], $ types [0 ]->getNamespace (), 'namespace ' );
6063 $ this ->assertSame ('Name ' , $ types [0 ]->getName (), 'name ' );
6164 $ this ->assertSame (false , $ types [0 ]->getNullable (), 'nullable ' );
6265 }
6366 public function testException (): void {
67+ // private \Exception $error;
6468 $ parser = (new ParserFactory )->create (ParserFactory::PREFER_PHP7 );
6569 $ filename = sprintf ('%s/php8/product/Product.php ' , $ this ->fixtureDir );
6670 try {
6771 $ ast = $ parser ->parse (file_get_contents ($ filename ));
6872 } catch (Error $ error ) {
6973 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
7074 }
71- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [4 ], PhpTypeExpression::TYPE , ['hoge ' , 'fuga ' , 'product ' ]);
75+ $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [4 ], PhpTypeExpression::VAR , ['hoge ' , 'fuga ' , 'product ' ]);
7276 $ types = $ expression ->getTypes ();
7377
7478 $ this ->assertSame ([], $ types [0 ]->getNamespace (), 'namespace ' );
7579 $ this ->assertSame ('Exception ' , $ types [0 ]->getName (), 'name ' );
7680 $ this ->assertSame (false , $ types [0 ]->getNullable (), 'nullable ' );
7781 }
7882 public function testRelated (): void {
83+ // private bar\Boo $boo;
7984 $ parser = (new ParserFactory )->create (ParserFactory::PREFER_PHP7 );
8085 $ filename = sprintf ('%s/php8/product/Product.php ' , $ this ->fixtureDir );
8186 try {
8287 $ ast = $ parser ->parse (file_get_contents ($ filename ));
8388 } catch (Error $ error ) {
8489 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
8590 }
86- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [5 ], PhpTypeExpression::TYPE , ['hoge ' , 'fuga ' , 'product ' ]);
91+ $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [5 ], PhpTypeExpression::VAR , ['hoge ' , 'fuga ' , 'product ' ]);
8792 $ types = $ expression ->getTypes ();
8893
8994 $ this ->assertSame (['hoge ' , 'fuga ' , 'product ' , 'bar ' ], $ types [0 ]->getNamespace (), 'namespace ' );
9095 $ this ->assertSame ('Boo ' , $ types [0 ]->getName (), 'name ' );
9196 $ this ->assertSame (false , $ types [0 ]->getNullable (), 'nullable ' );
9297 }
98+ public function testAbsolute (): void {
99+ // private \hoge\fuga\product\bar\Boo $boo2;
100+ $ parser = (new ParserFactory )->create (ParserFactory::PREFER_PHP7 );
101+ $ filename = sprintf ('%s/php8/product/Product.php ' , $ this ->fixtureDir );
102+ try {
103+ $ ast = $ parser ->parse (file_get_contents ($ filename ));
104+ } catch (Error $ error ) {
105+ throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
106+ }
107+ $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [6 ], PhpTypeExpression::VAR , ['hoge ' , 'fuga ' , 'product ' ]);
108+ $ types = $ expression ->getTypes ();
109+
110+ $ this ->assertSame (['hoge ' , 'fuga ' , 'product ' , 'bar ' ], $ types [0 ]->getNamespace (), 'namespace ' );
111+ $ this ->assertSame ('Boo ' , $ types [0 ]->getName (), 'name ' );
112+ $ this ->assertSame (false , $ types [0 ]->getNullable (), 'nullable ' );
113+ }
114+ public function testDocString (): void {
115+ // /** @var bur\Bon $docString */
116+ // private bar\Boo $docString;
117+ $ parser = (new ParserFactory )->create (ParserFactory::PREFER_PHP7 );
118+ $ filename = sprintf ('%s/php8/product/Product.php ' , $ this ->fixtureDir );
119+ try {
120+ $ ast = $ parser ->parse (file_get_contents ($ filename ));
121+ } catch (Error $ error ) {
122+ throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
123+ }
124+ $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [7 ], PhpTypeExpression::VAR , ['hoge ' , 'fuga ' , 'product ' ]);
125+ $ types = $ expression ->getTypes ();
126+
127+ $ this ->assertSame (['hoge ' , 'fuga ' , 'product ' , 'bur ' ], $ types [0 ]->getNamespace (), 'namespace ' );
128+ $ this ->assertSame ('Bon ' , $ types [0 ]->getName (), 'name ' );
129+ $ this ->assertSame (false , $ types [0 ]->getNullable (), 'nullable ' );
130+ }
93131}
0 commit comments