Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Google/AdsApi/Common/AdsGuzzleHttpClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public function __construct(
public function generateHttpClient()
{
$config = $this->config;
if (!array_key_exists('handler', $config)
|| $config['handler'] === null) {
$config['handler'] = HandlerStack::create();
}

$config['handler'] = isset($config['handler'])
? clone $config['handler']
: HandlerStack::create();

// Add a logging middleware required by this library.
$config['handler']->before(
Expand Down
22 changes: 17 additions & 5 deletions tests/Google/AdsApi/Common/AdsGuzzleHttpClientFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function testGenerateHttpClient_userProvidedStack()
);
$stack->before('http_errors', Middleware::tap());
$client = new Client(['handler' => $stack]);
$originalStack = clone $stack;

$httpClientFactory = new AdsGuzzleHttpClientFactory(
$logger,
Expand All @@ -80,7 +81,12 @@ public function testGenerateHttpClient_userProvidedStack()

$this->assertNotNull($httpClient);
$this->assertInstanceOf(Client::class, $httpClient);
$this->assertEquals($stack, $httpClient->getConfig()['handler']);
$this->assertEquals($originalStack, $stack, 'Stack of original HTTP client should stay unchanged');
$this->assertNotEquals(
$stack,
$httpClient->getConfig()['handler'],
'Stack of factory created HTTP client should have logging middleware, thus differ from original'
);
}

/**
Expand All @@ -97,10 +103,11 @@ public function testGenerateHttpClient_userProvidedConfigs()
GuzzleLogMessageHandler::log($logger, $guzzleLogMessageFormatter)
);
$client = new Client([
'handler' => $stack,
'verify' => true,
'cookies' => false
'handler' => $stack,
'verify' => true,
'cookies' => false
]);
$originalStack = clone $stack;

$httpClientFactory = new AdsGuzzleHttpClientFactory(
$logger,
Expand All @@ -111,7 +118,12 @@ public function testGenerateHttpClient_userProvidedConfigs()

$this->assertNotNull($httpClient);
$this->assertInstanceOf(Client::class, $httpClient);
$this->assertEquals($stack, $httpClient->getConfig()['handler']);
$this->assertEquals($originalStack, $stack, 'Stack of original HTTP client should stay unchanged');
$this->assertNotEquals(
$stack,
$httpClient->getConfig()['handler'],
'Stack of factory created HTTP Client should have logging middleware, thus differ from original'
);
$this->assertTrue($httpClient->getConfig()['verify']);
$this->assertFalse($httpClient->getConfig()['cookies']);
}
Expand Down