11<?php
22namespace Tests \Functional \BehatContext ;
33
4- use Behat \Behat \Context \Context ;
54use Behat \Gherkin \Node \PyStringNode ;
6- use DemoApp \AbstractKernel ;
7- use DemoApp \DefaultKernel ;
85use PHPUnit \Framework \Assert ;
9- use Symfony \Component \HttpFoundation \Request ;
106use Symfony \Component \HttpFoundation \Response ;
117use Yoanm \JsonRpcServer \Domain \JsonRpcMethodInterface ;
128
139/**
1410 * Defines application features from the specific context.
1511 */
16- class DemoAppContext implements Context
12+ class DemoAppContext extends AbstractContext
1713{
1814 /** @var Response|null */
1915 private $ lastResponse ;
@@ -23,14 +19,11 @@ class DemoAppContext implements Context
2319 */
2420 public function whenISendFollowingPayloadToDemoApp ($ httpMethod , $ uri , PyStringNode $ payload )
2521 {
26- $ this ->lastResponse = null ;
27-
28- $ kernel = $ this ->getDemoAppKernel ();
29- $ kernel ->boot ();
30- $ request = Request::create ($ uri , $ httpMethod , [], [], [], [], $ payload ->getRaw ());
31- $ this ->lastResponse = $ kernel ->handle ($ request );
32- $ kernel ->terminate ($ request , $ this ->lastResponse );
33- $ kernel ->shutdown ();
22+ $ this ->lastResponse = $ this ->sendHttpContentTo (
23+ $ uri ,
24+ $ httpMethod ,
25+ $ payload ->getRaw ()
26+ );
3427 }
3528
3629 /**
@@ -41,8 +34,8 @@ public function thenIShouldHaveAResponseFromDemoAppWithFollowingContent($httpCod
4134 Assert::assertInstanceOf (Response::class, $ this ->lastResponse );
4235 // Decode payload to get ride of indentation, spacing, etc
4336 Assert::assertEquals (
44- json_decode ($ payload ->getRaw (), true ),
45- json_decode ($ this ->lastResponse ->getContent (), true )
37+ $ this -> jsonDecode ($ payload ->getRaw ()),
38+ $ this -> jsonDecode ($ this ->lastResponse ->getContent ())
4639 );
4740 Assert::assertSame ((int ) $ httpCode , $ this ->lastResponse ->getStatusCode ());
4841 }
@@ -76,15 +69,4 @@ public function thenCollectorShouldHaveAMethodWithName($methodClass, $methodName
7669 sprintf ('Method "%s" is not an instance of "%s" ' , $ methodName , $ methodClass )
7770 );
7871 }
79-
80- /**
81- * @return AbstractKernel
82- */
83- protected function getDemoAppKernel ()
84- {
85- $ env = 'prod ' ;
86- $ debug = true ;
87-
88- return new DefaultKernel ($ env , $ debug );
89- }
9072}
0 commit comments