/** * {@inheritDoc} */ public function execute($request, $catchReply = false) { $action = null; try { $this->extensions->onPreExecute($request); if (false == $action = $this->findActionSupported($request)) { throw RequestNotSupportedException::create($request); } $this->extensions->onExecute($request, $action); $action->execute($request); $this->extensions->onPostExecute($request, $action); } catch (ReplyInterface $reply) { $reply = $this->extensions->onReply($reply, $request, $action) ?: $reply ; if ($catchReply) { return $reply; } throw $reply; } catch (\Exception $e) { $this->extensions->onException($e, $request, $action ?: null); throw $e; } return; }
/** * @test */ public function shouldCallOnReplyWithNewReplyIfFirstExtensionReturnNew() { $expectedReply = $this->getMock('Payum\\Core\\Reply\\ReplyInterface'); $expectedNewReply = $this->getMock('Payum\\Core\\Reply\\ReplyInterface'); $expectedAction = $this->getMock('Payum\\Core\\Action\\ActionInterface'); $expectedRequest = new \stdClass(); $extensionFirst = $this->createExtensionMock(); $extensionFirst->expects($this->once())->method('onReply')->with($this->identicalTo($expectedReply), $this->identicalTo($expectedRequest), $this->identicalTo($expectedAction))->will($this->returnValue($expectedNewReply)); $extensionSecond = $this->createExtensionMock(); $extensionSecond->expects($this->once())->method('onReply')->with($this->identicalTo($expectedNewReply), $this->identicalTo($expectedRequest), $this->identicalTo($expectedAction)); $collection = new ExtensionCollection(); $collection->addExtension($extensionFirst); $collection->addExtension($extensionSecond); $result = $collection->onReply($expectedReply, $expectedRequest, $expectedAction); $this->assertSame($expectedNewReply, $result); }