File tree Expand file tree Collapse file tree 4 files changed +82
-2
lines changed Expand file tree Collapse file tree 4 files changed +82
-2
lines changed Original file line number Diff line number Diff line change @@ -39,9 +39,9 @@ matrix:
3939 - php : 7.3
4040 env : SYMFONY_REQUIRE=4.3.*
4141 - php : 7.3
42- env : SYMFONY_REQUIRE=4.4.*
42+ env : SYMFONY_REQUIRE=4.4.* DEPENDENCIES="symfony/http-client:^4.4"
4343 - php : 7.3
44- env : SYMFONY_REQUIRE=5.0.*
44+ env : SYMFONY_REQUIRE=5.0.* DEPENDENCIES="symfony/http-client:^5.0"
4545
4646 # Test with httplug 1.x clients
4747 - php : 7.2
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Http \HttplugBundle \ClientFactory ;
4+
5+ use Psr \Http \Message \ResponseFactoryInterface ;
6+ use Psr \Http \Message \StreamFactoryInterface ;
7+ use Symfony \Component \HttpClient \HttpClient ;
8+ use Symfony \Component \HttpClient \HttplugClient ;
9+
10+ /**
11+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
12+ */
13+ class SymfonyFactory implements ClientFactory
14+ {
15+ /**
16+ * @var ResponseFactoryInterface
17+ */
18+ private $ responseFactory ;
19+
20+ /**
21+ * @var StreamFactoryInterface
22+ */
23+ private $ streamFactory ;
24+
25+ /**
26+ * @param ResponseFactoryInterface $responseFactory
27+ * @param StreamFactoryInterface $streamFactory
28+ */
29+ public function __construct (ResponseFactoryInterface $ responseFactory , StreamFactoryInterface $ streamFactory )
30+ {
31+ $ this ->responseFactory = $ responseFactory ;
32+ $ this ->streamFactory = $ streamFactory ;
33+ }
34+
35+ /**
36+ * {@inheritdoc}
37+ */
38+ public function createClient (array $ config = [])
39+ {
40+ if (!class_exists (HttplugClient::class)) {
41+ throw new \LogicException ('To use the Symfony client you need to install the "symfony/http-client" package. ' );
42+ }
43+
44+ return new HttplugClient (HttpClient::create ($ config ), $ this ->responseFactory , $ this ->streamFactory );
45+ }
46+ }
Original file line number Diff line number Diff line change 9393 <service id =" httplug.factory.socket" class =" Http\HttplugBundle\ClientFactory\SocketFactory" public =" false" >
9494 <argument type =" service" id =" httplug.message_factory" />
9595 </service >
96+ <service id =" httplug.factory.symfony" class =" Http\HttplugBundle\ClientFactory\SymfonyFactory" public =" false" >
97+ <argument type =" service" id =" httplug.psr17_response_factory" />
98+ <argument type =" service" id =" httplug.psr17_stream_factory" />
99+ </service >
96100 </services >
97101</container >
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Http \HttplugBundle \Tests \Unit \ClientFactory ;
4+
5+ use Http \HttplugBundle \ClientFactory \SymfonyFactory ;
6+ use PHPUnit \Framework \TestCase ;
7+ use Psr \Http \Message \ResponseFactoryInterface ;
8+ use Psr \Http \Message \StreamFactoryInterface ;
9+ use Symfony \Component \HttpClient \HttplugClient ;
10+
11+ /**
12+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
13+ */
14+ class SymfonyFactoryTest extends TestCase
15+ {
16+ public function testCreateClient (): void
17+ {
18+ if (!class_exists (HttplugClient::class)) {
19+ $ this ->markTestSkipped ('Symfony Http client is not installed ' );
20+ }
21+
22+ $ factory = new SymfonyFactory (
23+ $ this ->getMockBuilder (ResponseFactoryInterface::class)->getMock (),
24+ $ this ->getMockBuilder (StreamFactoryInterface::class)->getMock ()
25+ );
26+ $ client = $ factory ->createClient ();
27+
28+ $ this ->assertInstanceOf (HttplugClient::class, $ client );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments