public function testCanSetCustomerIdInClient()
 {
     $this->client = EwayClient::factory(array('base_url' => 'https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp', 'customer_id' => 100));
     $command = $this->client->getCommand('SendPayment', array('totalAmount' => '10', 'cardHoldersName' => 'Foo Bar', 'cardNumber' => '4444333322221111', 'cardExpiryMonth' => '06', 'cardExpiryYear' => '20', 'CVN' => '123'));
     CommandEvents::prepare($command, $this->client);
     $this->assertEquals(100, $command['customerID']);
 }
예제 #2
0
 public function execute(CommandInterface $command)
 {
     $t = new CommandTransaction($this, $command);
     CommandEvents::prepare($t);
     // Listeners can intercept the event and inject a result. If that
     // happened, then we must not emit further events and just
     // return the result.
     if (null !== ($result = $t->getResult())) {
         return $result;
     }
     $t->setResponse($this->client->send($t->getRequest()));
     CommandEvents::process($t);
     return $t->getResult();
 }
예제 #3
0
 public function testEmitsErrorEventAndCanInterceptWithSuccessfulResult()
 {
     $req = new Request('GET', 'http://httbin.org');
     $res = new Response(200);
     $client = $this->getMockForAbstractClass('GuzzleHttp\\Command\\ServiceClientInterface');
     $cmd = new Command('foo', []);
     $trans = new CommandTransaction($client, $cmd);
     $em = $cmd->getEmitter();
     $exc = new RequestException('foo', $req, $res);
     $em->on('prepare', function (PrepareEvent $e) use($req, $exc) {
         $e->setRequest($req);
         throw $exc;
     });
     $c1 = $c2 = false;
     $em->on('error', function (CommandErrorEvent $e) use(&$c1, $client, $cmd, $req, $res) {
         $e->setResult('foo');
         $this->assertSame($client, $e->getClient());
         $this->assertSame($cmd, $e->getCommand());
         $this->assertSame($req, $e->getRequest());
         $this->assertSame($res, $e->getException()->getResponse());
         $c1 = true;
     });
     $c2 = false;
     $em->on('process', function () use(&$c2) {
         $c2 = true;
     });
     CommandEvents::prepare($trans);
     $this->assertTrue($c1);
     $this->assertFalse($c2);
 }
 /**
  * Set the current request of the iterator and hook the request's event
  * system up to the command's event system.
  */
 private function processCurrentRequest(CommandTransaction $trans)
 {
     $this->currentRequest = $trans->getRequest();
     if ($this->currentRequest) {
         // Emit the command's process event when the request completes
         $this->currentRequest->getEmitter()->on('complete', function (CompleteEvent $event) use($trans) {
             $trans->setResponse($event->getResponse());
             CommandEvents::process($trans);
         });
     }
 }
예제 #5
0
 /**
  * Wrap HTTP level errors with command level errors.
  */
 private static function injectErrorHandler(CommandTransaction $trans)
 {
     $trans->getRequest()->getEmitter()->on('error', function (ErrorEvent $re) use($trans) {
         $re->stopPropagation();
         $trans->setException(CommandEvents::exceptionFromError($trans, $re));
         $cev = new CommandErrorEvent($trans);
         $trans->getCommand()->getEmitter()->emit('error', $cev);
         if ($cev->isPropagationStopped()) {
             $trans->setException(null);
         }
     }, RequestEvents::LATE);
 }
예제 #6
0
 /**
  * Creates and prepares an HTTP request for a command but does not execute
  * the command.
  *
  * When the request is created, it is no longer associated with the command
  * and the event system of the command should no longer be depended upon.
  *
  * @param ServiceClientInterface $client  Client used to create requests
  * @param CommandInterface       $command Command to convert into a request
  *
  * @return \GuzzleHttp\Message\RequestInterface
  */
 public static function createRequest(ServiceClientInterface $client, CommandInterface $command)
 {
     $trans = new CommandTransaction($client, $command);
     CommandEvents::prepare($trans);
     return $trans->getRequest();
 }