mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-24 18:13:00 +01:00
Adding ability to overwrite config params for throw-away clients in the service builder
This commit is contained in:
parent
6d0908cc56
commit
be121121c0
@ -148,8 +148,14 @@ class ServiceBuilder extends AbstractHasDispatcher implements ServiceBuilderInte
|
||||
}
|
||||
}
|
||||
|
||||
// Get the configured parameters and merge in any parameters provided for throw-away clients
|
||||
$config = $this->builderConfig[$name]['params'];
|
||||
if (is_array($throwAway)) {
|
||||
$config = $throwAway + $config;
|
||||
}
|
||||
|
||||
$class = $this->builderConfig[$name]['class'];
|
||||
$client = $class::factory($this->builderConfig[$name]['params']);
|
||||
$client = $class::factory($config);
|
||||
|
||||
if (!$throwAway) {
|
||||
$this->clients[$name] = $client;
|
||||
|
@ -301,4 +301,26 @@ class ServiceBuilderTest extends \Guzzle\Tests\GuzzleTestCase
|
||||
$b = new ServiceBuilder($this->arrayData);
|
||||
$this->assertSame($b->get('billy.mock'), $b->get('Hello!'));
|
||||
}
|
||||
|
||||
public function testCanOverwriteParametersForThrowawayClients()
|
||||
{
|
||||
$b = new ServiceBuilder($this->arrayData);
|
||||
|
||||
$c1 = $b->get('michael.mock');
|
||||
$this->assertEquals('michael', $c1->getConfig('username'));
|
||||
|
||||
$c2 = $b->get('michael.mock', array('username' => 'jeremy'));
|
||||
$this->assertEquals('jeremy', $c2->getConfig('username'));
|
||||
}
|
||||
|
||||
public function testGettingAThrowawayClientWithParametersDoesNotAffectGettingOtherClients()
|
||||
{
|
||||
$b = new ServiceBuilder($this->arrayData);
|
||||
|
||||
$c1 = $b->get('michael.mock', array('username' => 'jeremy'));
|
||||
$this->assertEquals('jeremy', $c1->getConfig('username'));
|
||||
|
||||
$c2 = $b->get('michael.mock');
|
||||
$this->assertEquals('michael', $c2->getConfig('username'));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user