99use TypeLang \Mapper \Tests \Context \Context ;
1010use TypeLang \Mapper \Tests \Extension \ContextArgumentTransformerExtension \AsTestingContext ;
1111use TypeLang \Mapper \Type \TypeInterface ;
12+ use TypeLang \Parser \Node \Stmt \TypeStatement ;
1213
1314/**
1415 * @api
@@ -19,6 +20,8 @@ final class TypeContext extends Context
1920{
2021 private ?TypeInterface $ current = null ;
2122
23+ private ?TypeStatement $ statement = null ;
24+
2225 /**
2326 * @api
2427 */
@@ -37,14 +40,41 @@ public function setCurrent(TypeInterface $type): TypeInterface
3740 return $ this ->current = $ type ;
3841 }
3942
40- #[Given('/^type "(?P<type>[a-zA-Z0-9_\x80-\xff \\\\]+?)"$/ ' )]
41- public function givenType (string $ type ): void
43+ /**
44+ * @api
45+ */
46+ public function getStatement (): TypeStatement
47+ {
48+ Assert::assertNotNull ($ this ->statement , 'Type statement is not set ' );
49+
50+ return $ this ->statement ;
51+ }
52+
53+ /**
54+ * @api
55+ */
56+ public function setStatement (TypeStatement $ type ): TypeStatement
57+ {
58+ return $ this ->statement = $ type ;
59+ }
60+
61+ #[Given('/^type statement "(?P<type>.+?)"$/ ' )]
62+ public function givenTypeStatement (string $ type ): void
63+ {
64+ $ parser = $ this ->from (TypeParserContext::class)
65+ ->getCurrent ();
66+
67+ $ this ->setStatement ($ parser ->getStatementByDefinition ($ type ));
68+ }
69+
70+ #[Given('/^type "(?P<class>[a-zA-Z0-9_\x80-\xff \\\\]+?)"$/ ' )]
71+ public function givenType (string $ class ): void
4272 {
43- $ this ->givenTypeWith ($ type );
73+ $ this ->givenTypeWith ($ class );
4474 }
4575
46- #[Given('/^type "(?P<type >[a-zA-Z0-9_\x80-\xff \\\\]+?)" with (?P<args>.+?)$/ ' )]
47- public function givenTypeWith (string $ type , string $ args = '{} ' ): void
76+ #[Given('/^type "(?P<class >[a-zA-Z0-9_\x80-\xff \\\\]+?)" with (?P<args>.+?)$/ ' )]
77+ public function givenTypeWith (string $ class , string $ args = '{} ' ): void
4878 {
4979 try {
5080 $ arguments = \json_decode ($ args , true , flags: \JSON_THROW_ON_ERROR );
@@ -53,6 +83,6 @@ public function givenTypeWith(string $type, string $args = '{}'): void
5383 }
5484
5585 // @phpstan-ignore-next-line
56- $ this ->setCurrent (new $ type (...$ arguments ));
86+ $ this ->setCurrent (new $ class (...$ arguments ));
5787 }
5888}
0 commit comments