diff --git a/payment_form/tests/src/Unit/Plugin/Payment/Type/PaymentFormUnitTest.php b/payment_form/tests/src/Unit/Plugin/Payment/Type/PaymentFormUnitTest.php index 5e772c7..70bb3f5 100644 --- a/payment_form/tests/src/Unit/Plugin/Payment/Type/PaymentFormUnitTest.php +++ b/payment_form/tests/src/Unit/Plugin/Payment/Type/PaymentFormUnitTest.php @@ -207,22 +207,8 @@ class PaymentFormUnitTest extends UnitTestCase { $this->paymentType->setDestinationUrl($url); - $kernel = $this->getMock('\Symfony\Component\HttpKernel\HttpKernelInterface'); - $request = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Request') - ->disableOriginalConstructor() - ->getMock(); - $request_type = $this->randomMachineName(); - $response = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Response') - ->disableOriginalConstructor() - ->getMock(); - $event = new FilterResponseEvent($kernel, $request, $request_type, $response); - - $this->eventDispatcher->expects($this->once()) - ->method('addListener') - ->with(KernelEvents::RESPONSE, new PaymentFormUnitTestDoResumeContextCallableConstraint($event, $url), 999); - - - $this->paymentType->resumeContext(); + $response = $this->paymentType->resumeContext(); + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\RedirectResponse', $response); } /** @@ -236,56 +222,3 @@ class PaymentFormUnitTest extends UnitTestCase { } } - -/** - * Provides a constraint for the doResumeContext() callable. - */ -class PaymentFormUnitTestDoResumeContextCallableConstraint extends \PHPUnit_Framework_Constraint { - - /** - * The event to listen to. - * - * @var \Symfony\Component\HttpKernel\Event\FilterResponseEvent - */ - protected $event; - - /** - * The redirect URL. - * - * @var string - */ - protected $url; - - /** - * Constructs a new class instance. - * - * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event - * @param string $url - */ - public function __construct(FilterResponseEvent $event, $url) { - $this->event = $event; - $this->url = $url; - } - - /** - * {@inheritdoc} - */ - public function matches($other) { - if (is_callable($other)) { - $other($this->event); - $response = $this->event->getResponse(); - if ($response instanceof RedirectResponse) { - return $response->getTargetUrl() == $this->url; - } - } - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function toString() { - return 'returns a RedirectResponse through a KernelEvents::RESPONSE event listener'; - } - -} \ No newline at end of file diff --git a/payment_reference/src/Plugin/Payment/Type/PaymentReference.php b/payment_reference/src/Plugin/Payment/Type/PaymentReference.php index 0c96e5a..54918ff 100644 --- a/payment_reference/src/Plugin/Payment/Type/PaymentReference.php +++ b/payment_reference/src/Plugin/Payment/Type/PaymentReference.php @@ -108,11 +108,7 @@ class PaymentReference extends PaymentTypeBase implements ContainerFactoryPlugin ), array( 'absolute' => TRUE, )); - $response = new RedirectResponse($url); - $listener = function(FilterResponseEvent $event) use ($response) { - $event->setResponse($response); - }; - $this->eventDispatcher->addListener(KernelEvents::RESPONSE, $listener, 999); + return new RedirectResponse($url); } } diff --git a/payment_reference/tests/src/Unit/Plugin/Payment/Type/PaymentReferenceUnitTest.php b/payment_reference/tests/src/Unit/Plugin/Payment/Type/PaymentReferenceUnitTest.php index 4a59a6d..c29bb9a 100644 --- a/payment_reference/tests/src/Unit/Plugin/Payment/Type/PaymentReferenceUnitTest.php +++ b/payment_reference/tests/src/Unit/Plugin/Payment/Type/PaymentReferenceUnitTest.php @@ -250,8 +250,6 @@ class PaymentReferenceUnitTest extends UnitTestCase { * @covers ::doResumeContext */ public function testDoResumeContextWithExecutionReturnsResponse() { - $url = 'http://example.com'; - $payment_method = $this->getMock('\Drupal\payment\Plugin\Payment\Method\PaymentMethodInterface'); $payment_method->expects($this->atLeastOnce()) ->method('executePaymentReturnsResponse') @@ -261,75 +259,8 @@ class PaymentReferenceUnitTest extends UnitTestCase { ->method('getPaymentMethod') ->will($this->returnValue($payment_method)); - $kernel = $this->getMock('\Symfony\Component\HttpKernel\HttpKernelInterface'); - $request = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Request') - ->disableOriginalConstructor() - ->getMock(); - $request_type = $this->randomMachineName(); - $response = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Response') - ->disableOriginalConstructor() - ->getMock(); - $event = new FilterResponseEvent($kernel, $request, $request_type, $response); - - $this->eventDispatcher->expects($this->once()) - ->method('addListener') - ->with(KernelEvents::RESPONSE, new PaymentReferenceUnitTestDoResumeContextCallableConstraint($event, $url), 999); - - - $this->paymentType->resumeContext(); - } - -} - -/** - * Provides a constraint for the doResumeContext() callable. - */ -class PaymentReferenceUnitTestDoResumeContextCallableConstraint extends \PHPUnit_Framework_Constraint { - - /** - * The event to listen to. - * - * @var \Symfony\Component\HttpKernel\Event\FilterResponseEvent - */ - protected $event; - - /** - * The redirect URL. - * - * @var string - */ - protected $url; - - /** - * Constructs a new class instance. - * - * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event - * @param string $url - */ - public function __construct(FilterResponseEvent $event, $url) { - $this->event = $event; - $this->url = $url; - } - - /** - * {@inheritdoc} - */ - public function matches($other) { - if (is_callable($other)) { - $other($this->event); - $response = $this->event->getResponse(); - if ($response instanceof RedirectResponse) { - return $response->getTargetUrl() == $this->url; - } - } - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function toString() { - return 'returns a RedirectResponse through a KernelEvents::RESPONSE event listener'; + $response = $this->paymentType->resumeContext(); + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\RedirectResponse', $response); } }