22
33namespace Nicofuma \SwaggerBundle \Tests \Behat \Context ;
44
5- use BootstrapBundle \Tests \Behat \Context \Traits \ClientContextTrait ;
5+ use Behat \Mink \Driver \BrowserKitDriver ;
6+ use Behat \Mink \Exception \UnsupportedDriverActionException ;
67use FR3D \SwaggerAssertions \PhpUnit \SymfonyAssertsTrait ;
78use Nicofuma \SwaggerBundle \Validator \ValidatorMap ;
89use Sanpi \Behatch \Context \BaseContext ;
910
1011class SwaggerContext extends BaseContext
1112{
12- use ClientContextTrait;
1313 use SymfonyAssertsTrait;
1414
1515 /** @var ValidatorMap */
@@ -36,4 +36,38 @@ public function theResponseMatchSwagger()
3636
3737 $ this ->assertResponseMatch ($ response , $ schemaManager , $ request ->getPathInfo (), $ request ->getMethod ());
3838 }
39+
40+ /**
41+ * @return \Symfony\Component\BrowserKit\Client
42+ *
43+ * @throws UnsupportedDriverActionException
44+ */
45+ protected function getClient ()
46+ {
47+ $ driver = $ this ->getSession ()->getDriver ();
48+
49+ if (!$ driver instanceof BrowserKitDriver) {
50+ throw new UnsupportedDriverActionException ('This step is only supported by the BrowserKitDriver, not the %s one ' , $ driver );
51+ }
52+
53+ return $ driver ->getClient ();
54+ }
55+
56+ /**
57+ * Get the last response.
58+ *
59+ * @return \Symfony\Component\HttpFoundation\Response
60+ */
61+ protected function getResponse ()
62+ {
63+ return $ this ->getClient ()->getResponse ();
64+ }
65+
66+ /**
67+ * @return \Symfony\Component\HttpFoundation\Request
68+ */
69+ public function getRequest ()
70+ {
71+ return $ this ->getClient ()->getRequest ();
72+ }
3973}
0 commit comments