66
77use BehatHttpMockContext \Collection \ExtendedHttpMockClientCollection ;
88use BehatHttpMockContext \Context \HttpMockContext ;
9- use ExtendedMockHttpClient \Builder \RequestMockBuilder ;
10- use ExtendedMockHttpClient \ExtendedMockHttpClient ;
11- use ExtendedMockHttpClient \Model \HttpFixture ;
12- use PHPUnit \Framework \TestCase ;
9+ use BehatHttpMockContext \Tests \Unit \AbstractUnitTest ;
1310use RuntimeException ;
1411use stdClass ;
1512use Symfony \Component \DependencyInjection \Container ;
16- use Symfony \Component \HttpClient \Response \ MockResponse ;
13+ use Symfony \Component \HttpClient \CurlHttpClient ;
1714
18- class MockContextTest extends TestCase
15+ class MockContextTest extends AbstractUnitTest
1916{
2017 public function testFailingObjectInCollection (): void
2118 {
2219 $ this ->expectException (RuntimeException::class);
2320
24- $ mockCollection = new ExtendedHttpMockClientCollection (
25- ['string ' ]
26- );
21+ $ notMockedHttpClient = new CurlHttpClient ();
22+ $ mockCollection = new ExtendedHttpMockClientCollection ([ $ notMockedHttpClient ]);
2723
2824 $ mockContext = new HttpMockContext (
2925 new Container (),
3026 $ mockCollection
3127 );
3228
33- self ::assertCount (1 , $ mockCollection ->getHandlers ());
29+ self ::assertCount (1 , $ mockCollection ->getHttpClients ());
3430
3531 $ mockContext ->afterScenario ();
3632 }
3733
3834 public function testSuccess (): void
3935 {
40- $ client = new ExtendedMockHttpClient ('http://test.test ' );
41- $ client ->addFixture (new HttpFixture (
42- (new RequestMockBuilder ())->build (),
43- new MockResponse ('response body ' , [
44- 'http_code ' => 200
45- ])
46- ));
47-
48- $ mockCollection = new ExtendedHttpMockClientCollection ([
49- new ExtendedMockHttpClient ('macpaw.com ' )
50- ]);
36+ $ client = $ this ->createHttpClient ('http://test.test ' );
37+ $ httpFixture = $ client ->createFixture (
38+ null ,
39+ null ,
40+ null ,
41+ null ,
42+ 200 ,
43+ 'response body '
44+ );
45+ $ client ->addFixture ($ httpFixture );
46+
47+ $ mockCollection = new ExtendedHttpMockClientCollection ([$ client ]);
5148
5249 $ mockContext = new HttpMockContext (
5350 new Container (),
5451 $ mockCollection
5552 );
5653
57- self ::assertCount (1 , $ mockCollection ->getHandlers ());
54+ self ::assertCount (1 , $ mockCollection ->getHttpClients ());
5855
5956 $ mockContext ->afterScenario ();
6057
61- self ::assertCount (1 , $ mockCollection ->getHandlers ());
58+ self ::assertCount (1 , $ mockCollection ->getHttpClients ());
6259 }
6360
6461 public function testServiceNotFound (): void
6562 {
6663 $ this ->expectException (RuntimeException::class);
6764 $ this ->expectErrorMessage ('Service not found ' );
68- $ client = new ExtendedMockHttpClient ('http://test.test ' );
69- $ client ->addFixture (new HttpFixture (
70- (new RequestMockBuilder ())->build (),
71- new MockResponse ('response body ' , [
72- 'http_code ' => 200
73- ])
74- ));
75-
76- $ mockCollection = new ExtendedHttpMockClientCollection ([
77- new ExtendedMockHttpClient ('macpaw.com ' )
78- ]);
65+
66+ $ client = $ this ->createHttpClient ('http://test.test ' );
67+ $ httpFixture = $ client ->createFixture (
68+ null ,
69+ null ,
70+ null ,
71+ null ,
72+ 200 ,
73+ 'response body '
74+ );
75+ $ client ->addFixture ($ httpFixture );
76+
77+ $ mockCollection = new ExtendedHttpMockClientCollection ([ $ client ]);
7978
8079 $ mockContext = new HttpMockContext (
8180 new Container (),
8281 $ mockCollection
8382 );
8483
85- self ::assertCount (1 , $ mockCollection ->getHandlers ());
84+ self ::assertCount (1 , $ mockCollection ->getHttpClients ());
8685
8786 $ mockContext ->iMockHttpClientNextResponse ('test ' , 204 );
8887 }
@@ -92,17 +91,18 @@ public function testFailedClientService(): void
9291 $ this ->expectException (RuntimeException::class);
9392 $ this ->expectErrorMessage ('You should replace HTTP client service using ExtendedMockHttpClient ' );
9493
95- $ client = new ExtendedMockHttpClient ('http://test.test ' );
96- $ client ->addFixture (new HttpFixture (
97- (new RequestMockBuilder ())->build (),
98- new MockResponse ('response body ' , [
99- 'http_code ' => 200
100- ])
101- ));
102-
103- $ mockCollection = new ExtendedHttpMockClientCollection ([
104- new ExtendedMockHttpClient ('macpaw.com ' )
105- ]);
94+ $ client = $ this ->createHttpClient ('http://test.test ' );
95+ $ httpFixture = $ client ->createFixture (
96+ null ,
97+ null ,
98+ null ,
99+ null ,
100+ 200 ,
101+ 'response body '
102+ );
103+ $ client ->addFixture ($ httpFixture );
104+
105+ $ mockCollection = new ExtendedHttpMockClientCollection ([ $ client ]);
106106
107107 $ container = new Container ();
108108 $ container ->set ('test ' , new stdClass ());
0 commit comments