33namespace OrcaServices \NovaApi \Test \Traits ;
44
55use Cake \Chronos \Chronos ;
6- use GuzzleHttp \Handler \MockHandler ;
7- use GuzzleHttp \HandlerStack ;
86use GuzzleHttp \Psr7 \Response ;
97use OrcaServices \NovaApi \Client \NovaApiClient ;
108use OrcaServices \NovaApi \Configuration \NovaApiConfiguration ;
9+ use OrcaServices \NovaApi \Factory \NovaHttpClientFactory ;
1110use OrcaServices \NovaApi \Parameter \NovaIdentifierParameter ;
1211
1312/**
@@ -27,24 +26,22 @@ protected function createNovaApiClient(array $responses): NovaApiClient
2726 Chronos::setTestNow ('2019-09-01 00:00:00 ' );
2827
2928 $ settings = $ this ->getSettings ();
29+ $ this ->getContainer ()->set (NovaApiConfiguration::class, new NovaApiConfiguration ($ settings ));
3030
3131 // To make real http calls, just comment out this line
32- $ settings = $ this ->mockNovaGuzzleClient ($ settings , $ responses );
33-
34- $ this ->getContainer ()->set (NovaApiConfiguration::class, new NovaApiConfiguration ($ settings ));
32+ $ this ->mockNovaGuzzleClient ($ responses );
3533
3634 return $ this ->getContainer ()->get (NovaApiClient::class);
3735 }
3836
3937 /**
4038 * Mock NOVA Guzzle client and single sign on (SSO).
4139 *
42- * @param array $settings The nova api settings
4340 * @param array $responses The mocked responses
4441 *
45- * @return array
42+ * @return void
4643 */
47- protected function mockNovaGuzzleClient (array $ settings , array $ responses ): array
44+ protected function mockNovaGuzzleClient (array $ responses )
4845 {
4946 // Append the login as first response
5047 $ loginResponse = new Response ();
@@ -54,9 +51,7 @@ protected function mockNovaGuzzleClient(array $settings, array $responses): arra
5451
5552 array_unshift ($ responses , $ loginResponse );
5653
57- $ settings ['default ' ]['handler ' ] = HandlerStack::create (new MockHandler ($ responses ));
58-
59- return $ settings ;
54+ $ this ->getContainer ()->get (NovaHttpClientFactory::class)->setMockedResponses ($ responses );
6055 }
6156
6257 /**
0 commit comments