1
0
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:
Michael Dowling 2012-10-24 20:23:10 -07:00
parent e255685f78
commit e74cf3ce3e
2 changed files with 8 additions and 9 deletions

View File

@ -33,7 +33,7 @@ class Client extends HttpClient implements ClientInterface
/** /**
* @var bool Whether or not magic methods are enabled * @var bool Whether or not magic methods are enabled
*/ */
protected $enableMagicMethods = false; protected $enableMagicMethods = true;
/** /**
* @var CommandFactoryInterface * @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 string $method Name of the command object to instantiate
* @param array $args Arguments to pass to the command * @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 * @throws BadMethodCallException when a command is not found or magic methods are disabled
*/ */
public function __call($method, $args = null) 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."); 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();
} }
/** /**

View File

@ -210,9 +210,10 @@ class ClientTest extends \Guzzle\Tests\GuzzleTestCase
* @covers Guzzle\Service\Client::__call * @covers Guzzle\Service\Client::__call
* @expectedException BadMethodCallException * @expectedException BadMethodCallException
*/ */
public function testMagicCallBehaviorIsDisabledByDefault() public function testMagicCallBehaviorCanBeDisabled()
{ {
$client = new Client(); $client = new Client();
$client->enableMagicMethods(false);
$client->foo(); $client->foo();
} }
@ -236,12 +237,10 @@ class ClientTest extends \Guzzle\Tests\GuzzleTestCase
public function testMagicCallBehaviorExecuteExecutesCommands() public function testMagicCallBehaviorExecuteExecutesCommands()
{ {
$client = new Mock\MockClient(); $client = new Mock\MockClient();
$client->enableMagicMethods(true);
$client->setDescription($this->service); $client->setDescription($this->service);
$client->getEventDispatcher()->addSubscriber(new MockPlugin(array(new Response(200)))); $client->getEventDispatcher()->addSubscriber(new MockPlugin(array(new Response(200))));
$cmd = $client->mockCommand(); $result = $client->mockCommand();
$this->assertInstanceOf('Guzzle\Tests\Service\Mock\Command\MockCommand', $cmd); $this->assertInstanceOf('Guzzle\Http\Message\Response', $result);
$this->assertFalse($cmd->isExecuted());
} }
/** /**