@@ -20,7 +20,7 @@ public function testNullableString(): void {
2020 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
2121 }
2222
23- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [0 ], PhpTypeExpression::TYPE );
23+ $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [0 ], PhpTypeExpression::TYPE , [ ' hoge ' , ' fuga ' , ' product ' ] );
2424 $ types = $ expression ->getTypes ();
2525
2626 $ this ->assertSame ([], $ types [0 ]->getNamespace (), 'namespace ' );
@@ -35,8 +35,7 @@ public function testIntOrString(): void {
3535 } catch (Error $ error ) {
3636 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
3737 }
38- // var_dump($ast[0]->stmts[1]->stmts[1]);die();
39- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [1 ], PhpTypeExpression::TYPE );
38+ $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [1 ], PhpTypeExpression::TYPE , ['hoge ' , 'fuga ' , 'product ' ]);
4039 $ types = $ expression ->getTypes ();
4140
4241 $ this ->assertSame ([], $ types [0 ]->getNamespace (), 'namespace ' );
@@ -46,4 +45,49 @@ public function testIntOrString(): void {
4645 $ this ->assertSame ('string ' , $ types [1 ]->getName (), 'name ' );
4746 $ this ->assertSame (false , $ types [1 ]->getNullable (), 'nullable ' );
4847 }
48+ public function testPrice (): void {
49+ $ parser = (new ParserFactory )->create (ParserFactory::PREFER_PHP7 );
50+ $ filename = sprintf ('%s/php8/product/Product.php ' , $ this ->fixtureDir );
51+ try {
52+ $ ast = $ parser ->parse (file_get_contents ($ filename ));
53+ } catch (Error $ error ) {
54+ throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
55+ }
56+ $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [2 ], PhpTypeExpression::TYPE , ['hoge ' , 'fuga ' , 'product ' ]);
57+ $ types = $ expression ->getTypes ();
58+
59+ $ this ->assertSame (['hoge ' , 'fuga ' , 'product ' ], $ types [0 ]->getNamespace (), 'namespace ' );
60+ $ this ->assertSame ('Name ' , $ types [0 ]->getName (), 'name ' );
61+ $ this ->assertSame (false , $ types [0 ]->getNullable (), 'nullable ' );
62+ }
63+ public function testException (): void {
64+ $ parser = (new ParserFactory )->create (ParserFactory::PREFER_PHP7 );
65+ $ filename = sprintf ('%s/php8/product/Product.php ' , $ this ->fixtureDir );
66+ try {
67+ $ ast = $ parser ->parse (file_get_contents ($ filename ));
68+ } catch (Error $ error ) {
69+ throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
70+ }
71+ $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [4 ], PhpTypeExpression::TYPE , ['hoge ' , 'fuga ' , 'product ' ]);
72+ $ types = $ expression ->getTypes ();
73+
74+ $ this ->assertSame ([], $ types [0 ]->getNamespace (), 'namespace ' );
75+ $ this ->assertSame ('Exception ' , $ types [0 ]->getName (), 'name ' );
76+ $ this ->assertSame (false , $ types [0 ]->getNullable (), 'nullable ' );
77+ }
78+ public function testRelated (): void {
79+ $ parser = (new ParserFactory )->create (ParserFactory::PREFER_PHP7 );
80+ $ filename = sprintf ('%s/php8/product/Product.php ' , $ this ->fixtureDir );
81+ try {
82+ $ ast = $ parser ->parse (file_get_contents ($ filename ));
83+ } catch (Error $ error ) {
84+ throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
85+ }
86+ $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [5 ], PhpTypeExpression::TYPE , ['hoge ' , 'fuga ' , 'product ' ]);
87+ $ types = $ expression ->getTypes ();
88+
89+ $ this ->assertSame (['hoge ' , 'fuga ' , 'product ' , 'bar ' ], $ types [0 ]->getNamespace (), 'namespace ' );
90+ $ this ->assertSame ('Boo ' , $ types [0 ]->getName (), 'name ' );
91+ $ this ->assertSame (false , $ types [0 ]->getNullable (), 'nullable ' );
92+ }
4993}
0 commit comments