/** * @test */ public function shouldReturnSameOrderUsedWhileFetchAndUpdateCallsOnExecute() { $model = array('location' => 'theKlarnaOrderLocation', 'cart' => array('items' => array(array('foo'), array('bar')))); $request = new FetchOrder($model); $testCase = $this; $expectedOrder = null; $connector = $this->createConnectorMock(); $connector->expects($this->at(0))->method('apply')->with('GET')->will($this->returnCallback(function ($method, $order, $options) use($testCase, &$expectedOrder) { $expectedOrder = $order; })); $action = new FetchOrderAction($connector); $action->setApi(new Config()); $action->execute($request); $this->assertSame($expectedOrder, $request->getOrder()); }
/** * @test */ public function shouldRecoverAfterTimeout() { $model = array('location' => 'theLocation', 'cart' => array('items' => array(array('foo'), array('bar')))); $expectedOrder = null; $connector = $this->createConnectorMock(); $connector->expects($this->at(0))->method('apply')->with('GET')->will($this->throwException(new \Klarna_Checkout_ConnectionErrorException())); $connector->expects($this->at(1))->method('apply')->with('GET')->will($this->returnCallback(function ($method, $order, $options) use(&$expectedOrder) { $expectedOrder = $order; })); $action = new FetchOrderAction($connector); $action->setApi(new Config()); $action->execute($request = new FetchOrder($model)); $this->assertSame($expectedOrder, $request->getOrder()); }