mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-25 02:22:57 +01:00
Enabling magic methods by default. Magic methods return result not command.
This commit is contained in:
parent
e255685f78
commit
e74cf3ce3e
@ -33,7 +33,7 @@ class Client extends HttpClient implements ClientInterface
|
||||
/**
|
||||
* @var bool Whether or not magic methods are enabled
|
||||
*/
|
||||
protected $enableMagicMethods = false;
|
||||
protected $enableMagicMethods = true;
|
||||
|
||||
/**
|
||||
* @var CommandFactoryInterface
|
||||
@ -76,12 +76,12 @@ class Client extends HttpClient implements ClientInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method used to retrieve a command. Magic method must be enabled on the client to use this functionality.
|
||||
* Magic method used to retrieve a command. Magic methods must be enabled on the client to use this functionality.
|
||||
*
|
||||
* @param string $method Name of the command object to instantiate
|
||||
* @param array $args Arguments to pass to the command
|
||||
*
|
||||
* @return CommandInterface
|
||||
* @return mixed Returns the result of the command
|
||||
* @throws BadMethodCallException when a command is not found or magic methods are disabled
|
||||
*/
|
||||
public function __call($method, $args = null)
|
||||
@ -90,7 +90,7 @@ class Client extends HttpClient implements ClientInterface
|
||||
throw new BadMethodCallException("Missing method {$method}. This client has not enabled magic methods.");
|
||||
}
|
||||
|
||||
return $this->getCommand($method, isset($args[0]) ? $args[0] : array());
|
||||
return $this->getCommand($method, isset($args[0]) ? $args[0] : array())->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,9 +210,10 @@ class ClientTest extends \Guzzle\Tests\GuzzleTestCase
|
||||
* @covers Guzzle\Service\Client::__call
|
||||
* @expectedException BadMethodCallException
|
||||
*/
|
||||
public function testMagicCallBehaviorIsDisabledByDefault()
|
||||
public function testMagicCallBehaviorCanBeDisabled()
|
||||
{
|
||||
$client = new Client();
|
||||
$client->enableMagicMethods(false);
|
||||
$client->foo();
|
||||
}
|
||||
|
||||
@ -236,12 +237,10 @@ class ClientTest extends \Guzzle\Tests\GuzzleTestCase
|
||||
public function testMagicCallBehaviorExecuteExecutesCommands()
|
||||
{
|
||||
$client = new Mock\MockClient();
|
||||
$client->enableMagicMethods(true);
|
||||
$client->setDescription($this->service);
|
||||
$client->getEventDispatcher()->addSubscriber(new MockPlugin(array(new Response(200))));
|
||||
$cmd = $client->mockCommand();
|
||||
$this->assertInstanceOf('Guzzle\Tests\Service\Mock\Command\MockCommand', $cmd);
|
||||
$this->assertFalse($cmd->isExecuted());
|
||||
$result = $client->mockCommand();
|
||||
$this->assertInstanceOf('Guzzle\Http\Message\Response', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user