@@ -31,11 +31,36 @@ public function testCanCreateInstance(): void
3131 }
3232
3333
34- public function testCanBuild (): void
34+ public function testBuildWithClient (): void
3535 {
36- $ this ->assertInstanceOf (
37- HttpClientDecorator::class,
38- $ this ->sut ()->build ($ this ->createStub (\GuzzleHttp \Client::class)),
39- );
36+ $ client = new \GuzzleHttp \Client ();
37+ $ decorator = $ this ->sut ()->build ($ client );
38+ $ this ->assertSame ($ client , $ decorator ->client );
39+ }
40+
41+
42+ public function testBuildWithoutClientAndConfig (): void
43+ {
44+ $ decorator = $ this ->sut ()->build ();
45+ $ this ->assertInstanceOf (HttpClientDecorator::class, $ decorator );
46+ $ this ->assertNotEmpty ($ decorator ->client ->getConfig ('allow_redirects ' ));
47+ }
48+
49+
50+ public function testBuildWithConfig (): void
51+ {
52+ $ config = ['timeout ' => 10.0 , 'connect_timeout ' => 5.0 ];
53+ $ decorator = $ this ->sut ()->build (null , $ config );
54+
55+ $ this ->assertEqualsWithDelta (10.0 , $ decorator ->client ->getConfig ('timeout ' ), PHP_FLOAT_EPSILON );
56+ $ this ->assertEqualsWithDelta (5.0 , $ decorator ->client ->getConfig ('connect_timeout ' ), PHP_FLOAT_EPSILON );
57+ $ this ->assertNotEmpty ($ decorator ->client ->getConfig ('allow_redirects ' ));
58+ }
59+
60+
61+ public function testBuildWithConfigOverridingDefaults (): void
62+ {
63+ $ decorator = $ this ->sut ()->build (null , ['allow_redirects ' => false ]);
64+ $ this ->assertFalse ($ decorator ->client ->getConfig ('allow_redirects ' ));
4065 }
4166}
0 commit comments