From e74cf3ce3e7812462c49712adf1d02002bbad190 Mon Sep 17 00:00:00 2001 From: Michael Dowling Date: Wed, 24 Oct 2012 20:23:10 -0700 Subject: [PATCH] Enabling magic methods by default. Magic methods return result not command. --- src/Guzzle/Service/Client.php | 8 ++++---- tests/Guzzle/Tests/Service/ClientTest.php | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Guzzle/Service/Client.php b/src/Guzzle/Service/Client.php index e0e0dc50..0685807f 100644 --- a/src/Guzzle/Service/Client.php +++ b/src/Guzzle/Service/Client.php @@ -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(); } /** diff --git a/tests/Guzzle/Tests/Service/ClientTest.php b/tests/Guzzle/Tests/Service/ClientTest.php index d9b0a60b..b494c6f5 100644 --- a/tests/Guzzle/Tests/Service/ClientTest.php +++ b/tests/Guzzle/Tests/Service/ClientTest.php @@ -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); } /**