/**
  * @expectedException Guzzle\Service\Exception\InconsistentClientTransferException
  */
 public function testEnsuresAllCommandsUseTheSameClient()
 {
     $batch = new BatchCommandTransfer(2);
     $client1 = new Client('http://www.example.com');
     $client2 = new Client('http://www.example.com');
     $command1 = new Mc();
     $command1->setClient($client1);
     $command2 = new Mc();
     $command2->setClient($client2);
     $batch->transfer(array($command1, $command2));
 }
Ejemplo n.º 2
0
 public function testCanChangeResponseBody()
 {
     $body = EntityBody::factory();
     $command = new MockCommand();
     $command->setClient(new \Guzzle\Service\Client());
     $command->set(AbstractCommand::RESPONSE_BODY, $body);
     $request = $command->prepare();
     $this->assertSame($body, $this->readAttribute($request, 'responseBody'));
 }
 /**
  * @covers Guzzle\Service\Command\AbstractCommand::__call
  */
 public function testMissingMethodCallsAllowedWhenEnabled()
 {
     $command = new MockCommand(array('command.magic_method_call' => true), $this->getApiCommand());
     $command->setTest('foo');
     $this->assertEquals('foo', $command->get('test'));
 }
Ejemplo n.º 4
0
 /**
  * @covers Guzzle\Service\Command\AbstractCommand::setOnComplete
  * @expectedException Guzzle\Common\Exception\InvalidArgumentException
  */
 public function testOnCompleteMustBeCallable()
 {
     $client = $this->getClient();
     $command = new MockCommand();
     $command->setOnComplete('foo');
 }
 /**
  * @covers Guzzle\Service\Command\CommandSet::execute
  * @covers Guzzle\Service\Command\CommandSet::update
  */
 public function testExecutesCommands()
 {
     $client = $this->getClient();
     $observer = $this->getWildcardObserver($client);
     // Create a Mock response
     $response = new Response(200, array('Content-Type' => 'application/xml'), '<xml><data>123</data></xml>');
     $client->getEventDispatcher()->addSubscriber(new MockPlugin(array($response, $response, $response)));
     $command1 = new MockCommand();
     $command1->setClient($client);
     $command2 = new MockCommand();
     $command2->setClient($client);
     $command3 = new MockCommand();
     $command3->setClient($client);
     $commandSet = new CommandSet(array($command1, $command2, $command3));
     $commandSet->execute();
     $this->assertTrue($command1->isExecuted());
     $this->assertTrue($command1->isPrepared());
     $this->assertTrue($command2->isExecuted());
     $this->assertTrue($command2->isPrepared());
     $this->assertTrue($command3->isExecuted());
     $this->assertTrue($command3->isPrepared());
     $this->assertEquals($response, $command1->getResponse());
     $this->assertEquals($response, $command2->getResponse());
     $grouped = $observer->getGrouped();
     $this->assertEquals(3, count($grouped['command.before_send']));
     $this->assertEquals(3, count($grouped['command.after_send']));
     // make sure the command set was detached as a listener on the request
     $listeners = $command1->getRequest()->getEventDispatcher()->getListeners('request.complete');
     $this->assertFalse(in_array($commandSet, $listeners));
     // make sure that the command reference was removed
     $this->assertFalse($command1->getRequest()->getParams()->hasKey('command'));
     // Make sure that the command.after_send events are staggered, meaning they happened as requests completed
     $lastEvent = '';
     foreach ($observer->events as $e) {
         if ($lastEvent == 'command.after_send' && $e == 'command.after_send') {
             $this->fail('Not completing commands as they complete: ' . var_export($observer->events, true));
         }
         $lastEvent = $e;
     }
 }
Ejemplo n.º 6
0
 /**
  * @covers Guzzle\Service\Command\AbstractCommand::__invoke
  */
 public function testIsInvokable()
 {
     $client = $this->getClient();
     $response = new Response(200);
     $this->setMockResponse($client, array($response));
     $command = new MockCommand();
     $command->setClient($client);
     // Returns the result of the command
     $this->assertSame($response, $command());
 }
Ejemplo n.º 7
0
 /**
  * @covers Guzzle\Service\Command\AbstractCommand::prepare
  */
 public function testAddsCurlOptionsToRequestsWhenPreparing()
 {
     $command = new MockCommand(array('foo' => 'bar', 'curl.CURLOPT_PROXYPORT' => 8080));
     $client = new Client();
     $command->setClient($client);
     $request = $command->prepare();
     $this->assertEquals(8080, $request->getCurlOptions()->get(CURLOPT_PROXYPORT));
 }