diff --git a/modules/payment_form/src/Entity/Payment/PaymentForm.php b/modules/payment_form/src/Entity/Payment/PaymentForm.php index 48c9e48..fc78795 100644 --- a/modules/payment_form/src/Entity/Payment/PaymentForm.php +++ b/modules/payment_form/src/Entity/Payment/PaymentForm.php @@ -12,7 +12,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\payment\Plugin\Payment\MethodSelector\PaymentMethodSelectorManagerInterface; -use Drupal\payment\ResponseInterface; +use Drupal\payment\Response\ResponseInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/modules/payment_form/src/Plugin/Payment/Type/PaymentForm.php b/modules/payment_form/src/Plugin/Payment/Type/PaymentForm.php index 9e3a47b..2daa8a4 100644 --- a/modules/payment_form/src/Plugin/Payment/Type/PaymentForm.php +++ b/modules/payment_form/src/Plugin/Payment/Type/PaymentForm.php @@ -12,7 +12,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Url; use Drupal\payment\Plugin\Payment\Type\PaymentTypeBase; -use Drupal\payment\Response; +use Drupal\payment\Response\Response; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; diff --git a/modules/payment_form/tests/src/Unit/Entity/Payment/PaymentFormUnitTest.php b/modules/payment_form/tests/src/Unit/Entity/Payment/PaymentFormUnitTest.php index 70f142a..5829de2 100644 --- a/modules/payment_form/tests/src/Unit/Entity/Payment/PaymentFormUnitTest.php +++ b/modules/payment_form/tests/src/Unit/Entity/Payment/PaymentFormUnitTest.php @@ -9,7 +9,7 @@ namespace Drupal\Tests\payment_form\Unit\Entity\Payment; use Drupal\Core\Form\FormState; use Drupal\Core\Url; -use Drupal\payment\Response; +use Drupal\payment\Response\Response; use Drupal\payment_form\Entity\Payment\PaymentForm; use Drupal\Tests\UnitTestCase; use Symfony\Component\DependencyInjection\ContainerInterface; diff --git a/modules/payment_form/tests/src/Unit/Plugin/Payment/Type/PaymentFormUnitTest.php b/modules/payment_form/tests/src/Unit/Plugin/Payment/Type/PaymentFormUnitTest.php index 070fe24..c9e2d96 100644 --- a/modules/payment_form/tests/src/Unit/Plugin/Payment/Type/PaymentFormUnitTest.php +++ b/modules/payment_form/tests/src/Unit/Plugin/Payment/Type/PaymentFormUnitTest.php @@ -207,7 +207,7 @@ class PaymentFormUnitTest extends UnitTestCase { $response = $this->paymentType->getResumeContextResponse(); - $this->assertInstanceOf('\Drupal\payment\ResponseInterface', $response); + $this->assertInstanceOf('\Drupal\payment\Response\ResponseInterface', $response); $this->assertSame($url, $response->getRedirectUrl()->getUri()); } diff --git a/modules/payment_reference/src/Plugin/Payment/Type/PaymentReference.php b/modules/payment_reference/src/Plugin/Payment/Type/PaymentReference.php index 6d23d26..c037bae 100644 --- a/modules/payment_reference/src/Plugin/Payment/Type/PaymentReference.php +++ b/modules/payment_reference/src/Plugin/Payment/Type/PaymentReference.php @@ -13,7 +13,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Url; use Drupal\payment\Plugin\Payment\Type\PaymentTypeBase; -use Drupal\payment\Response; +use Drupal\payment\Response\Response; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; diff --git a/modules/payment_reference/tests/src/Unit/Plugin/Payment/Type/PaymentReferenceUnitTest.php b/modules/payment_reference/tests/src/Unit/Plugin/Payment/Type/PaymentReferenceUnitTest.php index 8de72d5..58bf0a1 100644 --- a/modules/payment_reference/tests/src/Unit/Plugin/Payment/Type/PaymentReferenceUnitTest.php +++ b/modules/payment_reference/tests/src/Unit/Plugin/Payment/Type/PaymentReferenceUnitTest.php @@ -235,7 +235,7 @@ class PaymentReferenceUnitTest extends UnitTestCase { public function testDoGetResumeContextResponse() { $response = $this->paymentType->getResumeContextResponse(); - $this->assertInstanceOf('\Drupal\payment\ResponseInterface', $response); + $this->assertInstanceOf('\Drupal\payment\Response\ResponseInterface', $response); } } diff --git a/modules/payment_test/src/Plugin/Payment/Method/PaymentTestResponse.php b/modules/payment_test/src/Plugin/Payment/Method/PaymentTestResponse.php index c8dc25a..1482d28 100644 --- a/modules/payment_test/src/Plugin/Payment/Method/PaymentTestResponse.php +++ b/modules/payment_test/src/Plugin/Payment/Method/PaymentTestResponse.php @@ -8,7 +8,7 @@ namespace Drupal\payment_test\Plugin\Payment\Method; use Drupal\Core\Url; use Drupal\payment\PaymentExecutionResult; -use Drupal\payment\Response; +use Drupal\payment\Response\Response; /** * A testing payment method. diff --git a/src/PaymentExecutionResult.php b/src/PaymentExecutionResult.php index 4a458f0..eb5727e 100644 --- a/src/PaymentExecutionResult.php +++ b/src/PaymentExecutionResult.php @@ -7,6 +7,8 @@ namespace Drupal\payment; +use Drupal\payment\Response\ResponseInterface; + /** * Provides a payment execution result. */ @@ -15,14 +17,14 @@ class PaymentExecutionResult implements PaymentExecutionResultInterface { /** * The response. * - * @var \Drupal\payment\ResponseInterface|null + * @var \Drupal\payment\Response\ResponseInterface|null */ protected $response; /** * Creates a new instance. * - * @param \Drupal\payment\ResponseInterface|null $response + * @param \Drupal\payment\Response\ResponseInterface|null $response * A response or NULL if execution has completed. */ public function __construct(ResponseInterface $response = NULL) { diff --git a/src/PaymentExecutionResultInterface.php b/src/PaymentExecutionResultInterface.php index e91725a..f6e0c5a 100644 --- a/src/PaymentExecutionResultInterface.php +++ b/src/PaymentExecutionResultInterface.php @@ -28,7 +28,7 @@ interface PaymentExecutionResultInterface { /** * Gets the response to complete payment execution. * - * @return \Drupal\payment\ResponseInterface|null + * @return \Drupal\payment\Response\ResponseInterface|null * A response (only if self::isInProgress() returns TRUE) or NULL if payment * execution cannot be completed (anymore). */ diff --git a/src/Plugin/Payment/Type/PaymentTypeBase.php b/src/Plugin/Payment/Type/PaymentTypeBase.php index f7cb9f3..a8725e7 100644 --- a/src/Plugin/Payment/Type/PaymentTypeBase.php +++ b/src/Plugin/Payment/Type/PaymentTypeBase.php @@ -117,7 +117,7 @@ abstract class PaymentTypeBase extends PluginBase implements ContainerFactoryPlu /** * Performs the actual context resumption. * - * @return \Drupal\payment\ResponseInterface + * @return \Drupal\payment\Response\ResponseInterface */ abstract protected function doGetResumeContextResponse(); diff --git a/src/Plugin/Payment/Type/PaymentTypeInterface.php b/src/Plugin/Payment/Type/PaymentTypeInterface.php index bf7b626..98c330e 100644 --- a/src/Plugin/Payment/Type/PaymentTypeInterface.php +++ b/src/Plugin/Payment/Type/PaymentTypeInterface.php @@ -56,7 +56,7 @@ interface PaymentTypeInterface extends PluginInspectionInterface, ConfigurablePl /** * Resumes the payer's original workflow. * - * @return \Drupal\payment\ResponseInterface + * @return \Drupal\payment\Response\ResponseInterface * * @see self::resumeContextAccess */ diff --git a/src/Response/RedirectResponse.php b/src/Response/RedirectResponse.php new file mode 100644 index 0000000..f908260 --- /dev/null +++ b/src/Response/RedirectResponse.php @@ -0,0 +1,28 @@ +response = new SymfonyRedirectResponse($url->toString()); + $this->url = $url; + } + +} diff --git a/src/Response.php b/src/Response/Response.php similarity index 79% rename from src/Response.php rename to src/Response/Response.php index 6d96950..5f2d966 100644 --- a/src/Response.php +++ b/src/Response/Response.php @@ -2,13 +2,12 @@ /** * @file - * Contains \Drupal\payment\Response. + * Contains \Drupal\payment\Response\Response. */ -namespace Drupal\payment; +namespace Drupal\payment\Response; use Drupal\Core\Url; -use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; /** @@ -52,7 +51,7 @@ class Response implements ResponseInterface { * {@inheritdoc} */ public function getResponse() { - return $this->response ? $this->response : new RedirectResponse($this->getRedirectUrl()->toString()); + return $this->response; } } diff --git a/src/ResponseInterface.php b/src/Response/ResponseInterface.php similarity index 52% rename from src/ResponseInterface.php rename to src/Response/ResponseInterface.php index c9e9497..8a2c43e 100644 --- a/src/ResponseInterface.php +++ b/src/Response/ResponseInterface.php @@ -2,17 +2,13 @@ /** * @file - * Contains \Drupal\payment\ResponseInterface. + * Contains \Drupal\payment\Response\ResponseInterface. */ -namespace Drupal\payment; +namespace Drupal\payment\Response; /** * Defines a payment response. - * - * When returning a instance of a class that implements this interface, - * self::getRedirectUrl() MUST return a value and calling code MUST be able to - * perform a redirect using this value. All other functionality is optional. */ interface ResponseInterface { @@ -24,7 +20,7 @@ interface ResponseInterface { public function getRedirectUrl(); /** - * Gets the response + * Gets the response the calling code must return after payment execution. * * @return \Symfony\Component\HttpFoundation\Response */ diff --git a/tests/src/Unit/Controller/PaymentUnitTest.php b/tests/src/Unit/Controller/PaymentUnitTest.php index df1c35d..a90a015 100644 --- a/tests/src/Unit/Controller/PaymentUnitTest.php +++ b/tests/src/Unit/Controller/PaymentUnitTest.php @@ -112,7 +112,7 @@ class PaymentUnitTest extends UnitTestCase { ->disableOriginalConstructor() ->getMock(); - $response = $this->getMock('\Drupal\payment\ResponseInterface'); + $response = $this->getMock('\Drupal\payment\Response\ResponseInterface'); $response->expects($this->atLeastOnce()) ->method('getResponse') ->willReturn($symfony_response); diff --git a/tests/src/Unit/PaymentExecutionResultUnitTest.php b/tests/src/Unit/PaymentExecutionResultUnitTest.php index 61cbf60..f0192d6 100644 --- a/tests/src/Unit/PaymentExecutionResultUnitTest.php +++ b/tests/src/Unit/PaymentExecutionResultUnitTest.php @@ -21,7 +21,7 @@ class PaymentExecutionResultUnitTest extends UnitTestCase { /** * The response. * - * @var \Drupal\payment\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\payment\Response\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $response; @@ -36,7 +36,7 @@ class PaymentExecutionResultUnitTest extends UnitTestCase { * {@inheritdoc} */ public function setUp() { - $this->response = $this->getMock('\Drupal\payment\ResponseInterface'); + $this->response = $this->getMock('\Drupal\payment\Response\ResponseInterface'); } /** diff --git a/tests/src/Unit/Plugin/Payment/Type/PaymentTypeBaseUnitTest.php b/tests/src/Unit/Plugin/Payment/Type/PaymentTypeBaseUnitTest.php index 23482f1..873e7a2 100644 --- a/tests/src/Unit/Plugin/Payment/Type/PaymentTypeBaseUnitTest.php +++ b/tests/src/Unit/Plugin/Payment/Type/PaymentTypeBaseUnitTest.php @@ -111,7 +111,7 @@ class PaymentTypeBaseUnitTest extends UnitTestCase { * @depends testGetPayment */ public function testGetResumeContextResponse() { - $response = $this->getMock('\Drupal\payment\ResponseInterface'); + $response = $this->getMock('\Drupal\payment\Response\ResponseInterface'); $payment = $this->getMockBuilder('\Drupal\payment\Entity\Payment') ->disableOriginalConstructor() diff --git a/tests/src/Unit/Response/RedirectResponseUnitTest.php b/tests/src/Unit/Response/RedirectResponseUnitTest.php new file mode 100644 index 0000000..91a908f --- /dev/null +++ b/tests/src/Unit/Response/RedirectResponseUnitTest.php @@ -0,0 +1,74 @@ +randomMachineName(); + + $url_generator = $this->getMock('\Drupal\Core\Routing\UrlGeneratorInterface'); + $url_generator->expects($this->atLeastOnce()) + ->method('generateFromRoute') + ->with($route_name) + ->willReturn($this->randomMachineName()); + + $container = new ContainerBuilder(); + $container->set('url_generator', $url_generator); + + \Drupal::setContainer($container); + + $this->redirectUrl = new Url($route_name); + + $this->response = new RedirectResponse($this->redirectUrl); + } + + /** + * @covers ::getRedirectUrl + */ + function testGetRedirectUrl() { + $this->assertSame($this->redirectUrl, $this->response->getRedirectUrl()); + } + + /** + * @covers ::getResponse + */ + function testGetResponse() { + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\RedirectResponse', $this->response->getResponse()); + } + +} diff --git a/tests/src/Unit/ResponseUnitTest.php b/tests/src/Unit/Response/ResponseUnitTest.php similarity index 60% rename from tests/src/Unit/ResponseUnitTest.php rename to tests/src/Unit/Response/ResponseUnitTest.php index c6e4aae..6dc9c3b 100644 --- a/tests/src/Unit/ResponseUnitTest.php +++ b/tests/src/Unit/Response/ResponseUnitTest.php @@ -5,15 +5,15 @@ * Contains \Drupal\Tests\payment\Unit\ResponseUnitTest. */ -namespace Drupal\Tests\payment\Unit; +namespace Drupal\Tests\payment\Unit\Response; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Url; -use Drupal\payment\Response; +use Drupal\payment\Response\Response; use Drupal\Tests\UnitTestCase; /** - * @coversDefaultClass \Drupal\payment\Response + * @coversDefaultClass \Drupal\payment\Response\Response * * @group Payment */ @@ -36,7 +36,7 @@ class ResponseUnitTest extends UnitTestCase { /** * The response under test. * - * @var \Drupal\payment\Response + * @var \Drupal\payment\Response\Response */ protected $response; @@ -69,25 +69,4 @@ class ResponseUnitTest extends UnitTestCase { $this->assertSame($this->symfonyResponse, $this->response->getResponse()); } - /** - * @covers ::getResponse - * @covers ::__construct - */ - function testGetResponseWithAutomaticallyCreatedResponse() { - $url_generator = $this->getMock('\Drupal\Core\Routing\UrlGeneratorInterface'); - $url_generator->expects($this->atLeastOnce()) - ->method('generateFromRoute') - ->with($this->redirectUrl->getRouteName()) - ->willReturn($this->randomMachineName()); - - $container = new ContainerBuilder(); - $container->set('url_generator', $url_generator); - - \Drupal::setContainer($container); - - $this->response = new Response($this->redirectUrl); - - $this->assertInstanceOf('\Symfony\Component\HttpFoundation\RedirectResponse', $this->response->getResponse()); - } - }