diff --git a/Block/Adminhtml/System/Config/Fieldset/Base/Payment.php b/Block/Adminhtml/System/Config/Fieldset/Base/Payment.php old mode 100755 new mode 100644 index 9e7e05b..1de8dda --- a/Block/Adminhtml/System/Config/Fieldset/Base/Payment.php +++ b/Block/Adminhtml/System/Config/Fieldset/Base/Payment.php @@ -19,32 +19,38 @@ namespace EMerchantPay\Genesis\Block\Adminhtml\System\Config\Fieldset\Base; +use Magento\Backend\Block\Context; +use Magento\Backend\Model\Auth\Session; +use Magento\Config\Block\System\Config\Form\Fieldset; +use Magento\Config\Model\Config; +use Magento\Framework\Data\Form\Element\AbstractElement; +use Magento\Framework\View\Helper\Js; + /** * Base Renderer for EMerchantPay Checkout & Direct Panel in System Configuration * * Class Payment - * @package EMerchantPay\Genesis\Block\Adminhtml\System\Config\Fieldset\Base */ -abstract class Payment extends \Magento\Config\Block\System\Config\Form\Fieldset +abstract class Payment extends Fieldset { /** - * @var \Magento\Config\Model\Config + * @var Config */ protected $_backendConfig; /** - * @param \Magento\Backend\Block\Context $context - * @param \Magento\Backend\Model\Auth\Session $authSession - * @param \Magento\Framework\View\Helper\Js $jsHelper - * @param \Magento\Config\Model\Config $backendConfig - * @param array $data + * @param Context $context + * @param Session $authSession + * @param Js $jsHelper + * @param Config $backendConfig + * @param array $data */ public function __construct( - \Magento\Backend\Block\Context $context, - \Magento\Backend\Model\Auth\Session $authSession, - \Magento\Framework\View\Helper\Js $jsHelper, - \Magento\Config\Model\Config $backendConfig, - array $data = [] + Context $context, + Session $authSession, + Js $jsHelper, + Config $backendConfig, + array $data = [] ) { $this->_backendConfig = $backendConfig; parent::__construct($context, $authSession, $jsHelper, $data); @@ -52,6 +58,7 @@ public function __construct( /** * Retrieves the Module Panel Css Class + * * @return string */ abstract protected function getBlockHeadCssClass(); @@ -59,7 +66,8 @@ abstract protected function getBlockHeadCssClass(); /** * Add custom css class * - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @param AbstractElement $element + * * @return string */ protected function _getFrontendClass($element) @@ -70,8 +78,10 @@ protected function _getFrontendClass($element) /** * Return header title part of html for payment solution * - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @param AbstractElement $element + * * @return string + * * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _getHeaderTitleHtml($element) @@ -106,8 +116,10 @@ protected function _getHeaderTitleHtml($element) /** * Return header comment part of html for payment solution * - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @param AbstractElement $element + * * @return string + * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function _getHeaderCommentHtml($element) @@ -118,8 +130,10 @@ protected function _getHeaderCommentHtml($element) /** * Get collapsed state on-load * - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @param AbstractElement $element + * * @return bool + * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function _isCollapseState($element) @@ -128,7 +142,10 @@ protected function _isCollapseState($element) } /** - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * Add jQuery to the payment page + * + * @param AbstractElement $element + * * @return string * * @SuppressWarnings(PHPMD.UnusedFormalParameter) diff --git a/Block/Adminhtml/System/Config/Fieldset/CheckoutPayment.php b/Block/Adminhtml/System/Config/Fieldset/CheckoutPayment.php old mode 100755 new mode 100644 index d90deee..ccf6da9 --- a/Block/Adminhtml/System/Config/Fieldset/CheckoutPayment.php +++ b/Block/Adminhtml/System/Config/Fieldset/CheckoutPayment.php @@ -23,12 +23,12 @@ * Renderer for EMerchantPay Checkout Panel in System Configuration * * Class CheckoutPayment - * @package EMerchantPay\Genesis\Block\Adminhtml\System\Config\Fieldset */ class CheckoutPayment extends \EMerchantPay\Genesis\Block\Adminhtml\System\Config\Fieldset\Base\Payment { /** * Retrieves the Module Panel Css Class + * * @return string */ protected function getBlockHeadCssClass() diff --git a/Block/Adminhtml/System/Config/Fieldset/Init.php b/Block/Adminhtml/System/Config/Fieldset/Init.php old mode 100755 new mode 100644 index b7867de..0b4b93d --- a/Block/Adminhtml/System/Config/Fieldset/Init.php +++ b/Block/Adminhtml/System/Config/Fieldset/Init.php @@ -19,11 +19,14 @@ namespace EMerchantPay\Genesis\Block\Adminhtml\System\Config\Fieldset; +use Magento\Backend\Block\Template; +use Magento\Framework\Data\Form\Element\AbstractElement; +use Magento\Framework\Data\Form\Element\Renderer\RendererInterface; + /** * Renderer for EMerchantPay banner in System Configuration */ -class Init extends \Magento\Backend\Block\Template implements - \Magento\Framework\Data\Form\Element\Renderer\RendererInterface +class Init extends Template implements RendererInterface { /** * @var string @@ -33,13 +36,13 @@ class Init extends \Magento\Backend\Block\Template implements /** * Render fieldset html * - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @param AbstractElement $element * @return string * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ // @codingStandardsIgnoreStart - public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) + public function render(AbstractElement $element) { return $this->toHtml(); } diff --git a/Block/Frontend/Config.php b/Block/Frontend/Config.php index 2cd388f..94c5e99 100644 --- a/Block/Frontend/Config.php +++ b/Block/Frontend/Config.php @@ -20,7 +20,7 @@ namespace EMerchantPay\Genesis\Block\Frontend; use EMerchantPay\Genesis\Model\Config as BackendConfig; -use EMerchantPay\Genesis\Model\Method\Checkout; +use EMerchantPay\Genesis\Model\Method\Checkout as MethodCheckout; use Magento\Framework\View\Element\Template; /** @@ -37,8 +37,8 @@ class Config extends Template /** * @param Template\Context $context - * @param BackendConfig $backendConfig - * @param array $data + * @param BackendConfig $backendConfig + * @param array $data */ public function __construct( Template\Context $context, @@ -56,7 +56,7 @@ public function __construct( */ public function isIframeProcessingEnabled(): bool { - $this->_backendConfig->setMethodCode(Checkout::CODE); + $this->_backendConfig->setMethodCode(MethodCheckout::CODE); return $this->_backendConfig->isIframeProcessingEnabled(); } diff --git a/Controller/AbstractAction.php b/Controller/AbstractAction.php old mode 100755 new mode 100644 index 360745e..a6dc0bb --- a/Controller/AbstractAction.php +++ b/Controller/AbstractAction.php @@ -19,39 +19,46 @@ namespace EMerchantPay\Genesis\Controller; +use Magento\Framework\App\Action\Action; +use Magento\Framework\App\Action\Context; +use Magento\Framework\Message\ManagerInterface; +use Magento\Framework\ObjectManagerInterface; +use Psr\Log\LoggerInterface; + /** * Base Controller Class + * * Class AbstractAction - * @package EMerchantPay\Genesis\Controller */ -abstract class AbstractAction extends \Magento\Framework\App\Action\Action +abstract class AbstractAction extends Action { /** - * @var \Magento\Framework\App\Action\Context + * @var Context */ protected $_context; /** - * @var \Psr\Log\LoggerInterface + * @var LoggerInterface */ protected $_logger; /** - * @param \Magento\Framework\App\Action\Context $context - * @param \Psr\Log\LoggerInterface $logger + * @param Context $context + * @param LoggerInterface $logger */ public function __construct( - \Magento\Framework\App\Action\Context $context, - \Psr\Log\LoggerInterface $logger + Context $context, + LoggerInterface $logger ) { parent::__construct($context); $this->_context = $context; - $this->_logger = $logger; + $this->_logger = $logger; } /** * Get Instance of Magento Controller Action - * @return \Magento\Framework\App\Action\Context + * + * @return Context */ protected function getContext() { @@ -60,7 +67,8 @@ protected function getContext() /** * Get Instance of Magento Object Manager - * @return \Magento\Framework\ObjectManagerInterface + * + * @return ObjectManagerInterface */ protected function getObjectManager() { @@ -69,7 +77,8 @@ protected function getObjectManager() /** * Get Instance of Magento global Message Manager - * @return \Magento\Framework\Message\ManagerInterface + * + * @return ManagerInterface */ protected function getMessageManager() { @@ -78,7 +87,8 @@ protected function getMessageManager() /** * Get Instance of Magento global Logger - * @return \Psr\Log\LoggerInterface + * + * @return LoggerInterface */ protected function getLogger() { @@ -87,7 +97,9 @@ protected function getLogger() /** * Check if param exists in the post request + * * @param string $key + * * @return bool */ protected function isPostRequestExists($key) @@ -99,7 +111,9 @@ protected function isPostRequestExists($key) /** * Get an array of the Submitted Post Request + * * @param string|null $key + * * @return null|array */ protected function getPostRequest($key = null) diff --git a/Controller/AbstractCheckoutAction.php b/Controller/AbstractCheckoutAction.php old mode 100755 new mode 100644 index 8dc2e26..3b912df --- a/Controller/AbstractCheckoutAction.php +++ b/Controller/AbstractCheckoutAction.php @@ -22,27 +22,28 @@ use Magento\Checkout\Model\Session; use Magento\Framework\App\Action\Context; use Magento\Framework\App\ResponseInterface; -use Magento\Framework\Controller\Result\Raw; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Controller\Result\Raw; +use Magento\Framework\UrlInterface; +use Magento\Sales\Model\Order; use Magento\Sales\Model\OrderFactory; use Psr\Log\LoggerInterface; -use Magento\Framework\UrlInterface; /** * Base Checkout Controller Class + * * Class AbstractCheckoutAction - * @package EMerchantPay\Genesis\Controller */ -abstract class AbstractCheckoutAction extends \EMerchantPay\Genesis\Controller\AbstractAction +abstract class AbstractCheckoutAction extends AbstractAction { - const ROUTE_PATTERN_CHECKOUT_ONEPAGE_SUCCESS_PATH = 'checkout/onepage/success'; - const ROUTE_PATTERN_CHECKOUT_ONEPAGE_SUCCESS_ARGS = []; + public const ROUTE_PATTERN_CHECKOUT_ONEPAGE_SUCCESS_PATH = 'checkout/onepage/success'; + public const ROUTE_PATTERN_CHECKOUT_ONEPAGE_SUCCESS_ARGS = []; - const ROUTE_PATTERN_CHECKOUT_CART_PATH = 'checkout/cart'; - const ROUTE_PATTERN_CHECKOUT_CART_ARGS = []; + public const ROUTE_PATTERN_CHECKOUT_CART_PATH = 'checkout/cart'; + public const ROUTE_PATTERN_CHECKOUT_CART_ARGS = []; - const ROUTE_PATTERN_CHECKOUT_FRAGMENT_PAYMENT_PATH = 'checkout'; - const ROUTE_PATTERN_CHECKOUT_FRAGMENT_PAYMENT_ARGS = ['_fragment' => 'payment']; + public const ROUTE_PATTERN_CHECKOUT_FRAGMENT_PAYMENT_PATH = 'checkout'; + public const ROUTE_PATTERN_CHECKOUT_FRAGMENT_PAYMENT_ARGS = ['_fragment' => 'payment']; /** * @var Session @@ -112,7 +113,8 @@ protected function getOrderFactory() /** * Get an Instance of the current Checkout Order Object - * @return \Magento\Sales\Model\Order + * + * @return Order */ protected function getOrder() { @@ -135,6 +137,7 @@ protected function getOrder() /** * Does a redirect to the Checkout Payment Page + * * @return void */ protected function redirectToCheckoutFragmentPayment() @@ -185,7 +188,7 @@ protected function redirectToCheckoutCart(bool $iframeRedirect) * Return html code with embedded js in ', - $expectedUrl, - $expectedUrl - ); - - $rawMock->expects($this->once()) - ->method('setContents') - ->with($expectedHtml) - ->willReturnSelf(); - } - - $resultFactoryMock->expects($this->once()) - ->method('create') - ->with(ResultFactory::TYPE_RAW) - ->willReturn($rawMock); - } - - $urlBuilderMock = $this->createMock(UrlInterface::class); - if ($expectedUrl !== '') { - $urlBuilderMock->expects($this->once()) - ->method('getUrl') - ->willReturn($expectedUrl); - } - - $this->controllerInstance = $this->getObjectManagerHelper()->getObject( - $this->getControllerClassName(), - [ - 'context' => $this->getContextMock(), - 'logger' => $this->createMock(LoggerInterface::class), - 'checkoutSession' => $this->checkoutSessionMock, - 'orderFactory' => $this->orderFactoryMock, - 'resultFactory' => $resultFactoryMock, - 'urlBuilder' => $urlBuilderMock - ] - ); - } + protected $urlBuilderMock; /** - * @covers \EMerchantPay\Genesis\Controller\Checkout\Iframe::execute + * @covers IframeController::execute */ public function testExecuteFailWhenLastRealOrderIdIsNull() { @@ -126,7 +78,7 @@ public function testExecuteFailWhenLastRealOrderIdIsNull() } /** - * @covers \EMerchantPay\Genesis\Controller\Checkout\Iframe::execute + * @covers IframeController::execute */ public function testExecuteSuccessReturnAction() { @@ -148,7 +100,7 @@ public function testExecuteSuccessReturnAction() } /** - * @covers \EMerchantPay\Genesis\Controller\Checkout\Iframe::execute + * @covers IframeController::execute */ public function testExecuteCancelReturnAction() { @@ -169,7 +121,7 @@ public function testExecuteCancelReturnAction() } /** - * @covers \EMerchantPay\Genesis\Controller\Checkout\Iframe::execute + * @covers IframeController::execute */ public function testExecuteFailureReturnAction() { @@ -187,7 +139,7 @@ public function testExecuteFailureReturnAction() } /** - * @covers \EMerchantPay\Genesis\Controller\Checkout\Iframe::execute + * @covers IframeController::execute */ public function testExecuteUnsupportedReturnAction() { @@ -202,4 +154,120 @@ public function testExecuteUnsupportedReturnAction() $this->assertNull($result); } + + /** + * Gets controller's fully qualified class name + * + * @return string + */ + protected function getControllerClassName(): string + { + return IframeController::class; + } + + /** + * @return void + */ + protected function setUp(): void + { + parent::setUp(); // Call the parent setUp to initialize common mocks + + $this->setUpCommonMocks(); + + $this->requestMock = $this->createMock(HttpRequest::class); + $this->responseMock = $this->createMock(HttpResponse::class); + $this->redirectFactoryMock = $this->createMock(RedirectFactory::class); + $this->storeManagerMock = $this->createMock(StoreManagerInterface::class); + $this->messageManagerMock = $this->createMock(ManagerInterface::class); + + // Create a mock for the context, which includes all its dependencies + $this->contextMock = $this->getMockBuilder(Context::class) + ->disableOriginalConstructor() + ->onlyMethods( + [ + 'getRequest', + 'getResponse', + 'getResultRedirectFactory', + 'getMessageManager', + ] + ) + ->addMethods(['getStoreManager']) + ->getMock(); + + $this->contextMock->method('getRequest')->willReturn($this->requestMock); + $this->contextMock->method('getResponse')->willReturn($this->responseMock); + $this->contextMock->method('getResultRedirectFactory')->willReturn($this->redirectFactoryMock); + $this->contextMock->method('getStoreManager')->willReturn($this->storeManagerMock); + $this->contextMock->method('getMessageManager')->willReturn($this->messageManagerMock); + + $this->iframeController = $this->getObjectManagerHelper()->getObject( + $this->getControllerClassName(), + [ + 'context' => $this->getContextMock(), + 'logger' => $this->createMock(LoggerInterface::class), + 'checkoutSession' => $this->checkoutSessionMock, + 'orderFactory' => $this->orderFactoryMock, + 'resultFactory' => $this->resultFactoryMock, + 'urlBuilder' => $this->urlBuilderMock + ] + ); + } + + /** + * Sets up common mocks for test methods + */ + private function setUpCommonMocks(bool $expectRaw = false, string $expectedUrl = '') + { + $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class) + ->disableOriginalConstructor() + ->onlyMethods(['create']) + ->addMethods(['getLastRealOrderId']) + ->getMock(); + + if ($expectRaw) { + $rawMock = $this->createMock(Raw::class); + $rawMock->expects($this->once()) + ->method('setHeader') + ->with('Content-Type', 'text/html') + ->willReturnSelf(); + + if ($expectedUrl !== '') { + $expectedHtml = sprintf( + '', + $expectedUrl, + $expectedUrl + ); + + $rawMock->expects($this->once()) + ->method('setContents') + ->with($expectedHtml) + ->willReturnSelf(); + } + + $this->resultFactoryMock->expects($this->once()) + ->method('create') + ->with(ResultFactory::TYPE_RAW) + ->willReturn($rawMock); + } + + $this->urlBuilderMock = $this->createMock(UrlInterface::class); + if ($expectedUrl !== '') { + $this->urlBuilderMock->expects($this->once()) + ->method('getUrl') + ->willReturn($expectedUrl); + } + + $this->controllerInstance = $this->getObjectManagerHelper()->getObject( + $this->getControllerClassName(), + [ + 'context' => $this->getContextMock(), + 'logger' => $this->createMock(LoggerInterface::class), + 'checkoutSession' => $this->checkoutSessionMock, + 'orderFactory' => $this->orderFactoryMock, + 'resultFactory' => $this->resultFactoryMock, + 'urlBuilder' => $this->urlBuilderMock + ] + ); + } } diff --git a/Test/Unit/Controller/Checkout/IndexTest.php b/Test/Unit/Controller/Checkout/IndexTest.php index 4a8a595..da230e1 100755 --- a/Test/Unit/Controller/Checkout/IndexTest.php +++ b/Test/Unit/Controller/Checkout/IndexTest.php @@ -19,17 +19,22 @@ namespace EMerchantPay\Genesis\Test\Unit\Controller\Checkout; +use EMerchantPay\Genesis\Controller\AbstractCheckoutAction; use EMerchantPay\Genesis\Controller\Checkout\Index as IndexController; +use EMerchantPay\Genesis\Test\Unit\Controller\AbstractControllerTest; /** + * Test Checkout + * * Class IndexTest - * @covers \EMerchantPay\Genesis\Controller\Checkout\Index - * @package EMerchantPay\Genesis\Test\Unit\Controller\Checkout + * + * @covers IndexController */ -class IndexTest extends \EMerchantPay\Genesis\Test\Unit\Controller\AbstractControllerTest +class IndexTest extends AbstractControllerTest { /** * Gets controller's fully qualified class name + * * @return string */ protected function getControllerClassName() @@ -38,7 +43,7 @@ protected function getControllerClassName() } /** - * @covers \EMerchantPay\Genesis\Controller\Checkout\Index::execute() + * @covers IndexController::execute() */ public function testExecuteFailWhenLastRealOrderIdIsNull() { @@ -62,7 +67,7 @@ public function testExecuteFailWhenLastRealOrderIdIsNull() } /** - * @covers \EMerchantPay\Genesis\Controller\Checkout\Index::execute() + * @covers IndexController::execute() */ public function testExecuteFailWhenRedirectUrlIsNull() { @@ -85,15 +90,15 @@ public function testExecuteFailWhenRedirectUrlIsNull() ->method('redirect') ->with( $this->getControllerInstance()->getResponse(), - \EMerchantPay\Genesis\Controller\AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_FRAGMENT_PAYMENT_PATH, - \EMerchantPay\Genesis\Controller\AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_FRAGMENT_PAYMENT_ARGS + AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_FRAGMENT_PAYMENT_PATH, + AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_FRAGMENT_PAYMENT_ARGS ); $this->getControllerInstance()->execute(); } /** - * @covers \EMerchantPay\Genesis\Controller\Checkout\Index::execute() + * @covers IndexController::execute() */ public function testExecuteSuccessfulRedirectToTheRedirectUrl() { diff --git a/Test/Unit/Controller/Checkout/RedirectTest.php b/Test/Unit/Controller/Checkout/RedirectTest.php index 3590fee..103b1c3 100755 --- a/Test/Unit/Controller/Checkout/RedirectTest.php +++ b/Test/Unit/Controller/Checkout/RedirectTest.php @@ -19,14 +19,19 @@ namespace EMerchantPay\Genesis\Test\Unit\Controller\Checkout; +use EMerchantPay\Genesis\Controller\AbstractCheckoutAction; use EMerchantPay\Genesis\Controller\Checkout\Redirect as RedirectController; +use EMerchantPay\Genesis\Helper\Data; +use EMerchantPay\Genesis\Test\Unit\Controller\AbstractControllerTest; /** + * Test iframe redirect + * * Class RedirectTest - * @covers \EMerchantPay\Genesis\Controller\Checkout\Redirect - * @package EMerchantPay\Genesis\Test\Unit\Controller\Checkout + * + * @covers RedirectController */ -class RedirectTest extends \EMerchantPay\Genesis\Test\Unit\Controller\AbstractControllerTest +class RedirectTest extends AbstractControllerTest { /** * Gets controller's fully qualified class name @@ -38,14 +43,14 @@ protected function getControllerClassName() } /** - * @covers \EMerchantPay\Genesis\Controller\Checkout\Redirect::execute() + * @covers RedirectController::execute() */ public function testExecuteFailWhenLastRealOrderIdIsNull() { $this->httpRequestMock->expects(self::once()) ->method('getParam') ->with('action') - ->willReturn(\EMerchantPay\Genesis\Helper\Data::ACTION_RETURN_SUCCESS); + ->willReturn(Data::ACTION_RETURN_SUCCESS); $this->checkoutSessionMock->expects(self::atLeastOnce()) ->method('getLastRealOrderId') @@ -61,14 +66,14 @@ public function testExecuteFailWhenLastRealOrderIdIsNull() } /** - * @covers \EMerchantPay\Genesis\Controller\Checkout\Redirect::execute() + * @covers RedirectController::execute() */ public function testExecuteSuccessReturnAction() { $this->httpRequestMock->expects(self::once()) ->method('getParam') ->with('action') - ->willReturn(\EMerchantPay\Genesis\Helper\Data::ACTION_RETURN_SUCCESS); + ->willReturn(Data::ACTION_RETURN_SUCCESS); $this->checkoutSessionMock->expects(self::atLeastOnce()) ->method('getLastRealOrderId') @@ -81,22 +86,22 @@ public function testExecuteSuccessReturnAction() ->method('redirect') ->with( $this->getControllerInstance()->getResponse(), - \EMerchantPay\Genesis\Controller\AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_ONEPAGE_SUCCESS_PATH, - \EMerchantPay\Genesis\Controller\AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_ONEPAGE_SUCCESS_ARGS + AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_ONEPAGE_SUCCESS_PATH, + AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_ONEPAGE_SUCCESS_ARGS ); $this->getControllerInstance()->execute(); } /** - * @covers \EMerchantPay\Genesis\Controller\Checkout\Redirect::execute() + * @covers RedirectController::execute() */ public function testExecuteCancelReturnAction() { $this->httpRequestMock->expects(self::once()) ->method('getParam') ->with('action') - ->willReturn(\EMerchantPay\Genesis\Helper\Data::ACTION_RETURN_CANCEL); + ->willReturn(Data::ACTION_RETURN_CANCEL); $this->checkoutSessionMock->expects(self::never()) ->method('getLastRealOrderId'); @@ -108,22 +113,22 @@ public function testExecuteCancelReturnAction() ->method('redirect') ->with( $this->getControllerInstance()->getResponse(), - \EMerchantPay\Genesis\Controller\AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_CART_PATH, - \EMerchantPay\Genesis\Controller\AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_CART_ARGS + AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_CART_PATH, + AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_CART_ARGS ); $this->getControllerInstance()->execute(); } /** - * @covers \EMerchantPay\Genesis\Controller\Checkout\Redirect::execute() + * @covers RedirectController::execute() */ public function testExecuteFailureReturnAction() { $this->httpRequestMock->expects(self::once()) ->method('getParam') ->with('action') - ->willReturn(\EMerchantPay\Genesis\Helper\Data::ACTION_RETURN_FAILURE); + ->willReturn(Data::ACTION_RETURN_FAILURE); $this->checkoutSessionMock->expects(self::never()) ->method('getLastRealOrderId'); @@ -135,15 +140,15 @@ public function testExecuteFailureReturnAction() ->method('redirect') ->with( $this->getControllerInstance()->getResponse(), - \EMerchantPay\Genesis\Controller\AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_CART_PATH, - \EMerchantPay\Genesis\Controller\AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_CART_ARGS + AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_CART_PATH, + AbstractCheckoutAction::ROUTE_PATTERN_CHECKOUT_CART_ARGS ); $this->getControllerInstance()->execute(); } /** - * @covers \EMerchantPay\Genesis\Controller\Checkout\Redirect::execute() + * @covers RedirectController::execute() */ public function testExecuteUnsupportedReturnAction() { diff --git a/Test/Unit/Controller/Ipn/IndexTest.php b/Test/Unit/Controller/Ipn/IndexTest.php index 06bb08e..07ba474 100755 --- a/Test/Unit/Controller/Ipn/IndexTest.php +++ b/Test/Unit/Controller/Ipn/IndexTest.php @@ -20,23 +20,28 @@ namespace EMerchantPay\Genesis\Test\Unit\Controller\Ipn; use EMerchantPay\Genesis\Controller\Ipn\Index as IndexController; - use EMerchantPay\Genesis\Model\Ipn\CheckoutIpn; +use EMerchantPay\Genesis\Test\Unit\Controller\AbstractControllerTest; +use Magento\Framework\Webapi\Response; +use PHPUnit\Framework\MockObject\MockObject; /** + * Test Notifications + * * Class IndexTest - * @covers \EMerchantPay\Genesis\Controller\Ipn\Index - * @package EMerchantPay\Genesis\Test\Unit\Controller\Ipn + * + * @covers IndexController */ -class IndexTest extends \EMerchantPay\Genesis\Test\Unit\Controller\AbstractControllerTest +class IndexTest extends AbstractControllerTest { /** - * @var \EMerchantPay\Genesis\Model\Ipn\CheckoutIpn|\PHPUnit_Framework_MockObject_MockObject + * @var CheckoutIpn|MockObject */ protected $checkoutIpnMock; /** * Gets controller's fully qualified class name + * * @return string */ protected function getControllerClassName() @@ -46,13 +51,14 @@ protected function getControllerClassName() /** * Get mock for Checkout IPN - * @return \EMerchantPay\Genesis\Model\Ipn\CheckoutIpn|\PHPUnit_Framework_MockObject_MockObject + * + * @return CheckoutIpn|MockObject */ protected function getCheckoutIpnMock() { return $this->checkoutIpnMock = $this->getMockBuilder(CheckoutIpn::class) ->disableOriginalConstructor() - ->setMethods(['handleGenesisNotification']) + ->onlyMethods(['handleGenesisNotification']) ->getMock(); } @@ -67,7 +73,7 @@ protected function setUp(): void } /** - * @covers \EMerchantPay\Genesis\Controller\Ipn\Index::execute() + * @covers IndexController::execute() */ public function testExecuteHttpRequestIsNotPost() { @@ -79,7 +85,7 @@ public function testExecuteHttpRequestIsNotPost() } /** - * @covers \EMerchantPay\Genesis\Controller\Ipn\Index::execute() + * @covers IndexController::execute() */ public function testExecutePostWithoutId() { @@ -102,13 +108,13 @@ public function testExecutePostWithoutId() } /** - * @covers \EMerchantPay\Genesis\Controller\Ipn\Index::execute() + * @covers IndexController::execute() */ public function testExecutePostWithWpfUniqueId() { $postParams = [ 'wpf_unique_id' => '12345678901234567890123456789012', - 'signature' => '1234567890123456789012345678901234567890' + 'signature' => '1234567890123456789012345678901234567890' ]; $responseBody = self::getResponseBody($postParams); @@ -147,7 +153,7 @@ public function testExecutePostWithWpfUniqueId() $this->responseInterfaceMock->expects(self::atLeastOnce()) ->method('setHttpResponseCode') - ->with(\Magento\Framework\Webapi\Response::HTTP_OK) + ->with(Response::HTTP_OK) ->willReturnSelf(); $this->responseInterfaceMock->expects(self::once()) @@ -158,8 +164,10 @@ public function testExecutePostWithWpfUniqueId() /** * Gets array element if exists + * * @param array $array * @param string $key + * * @return string */ protected static function getArrayElement($array, $key) @@ -169,19 +177,20 @@ protected static function getArrayElement($array, $key) /** * Generates the expected XML response from the payment gateway + * * @param array $postParams + * * @return string|null */ protected static function getResponseBody($postParams) { - if ($wpf_unique_id = self::getArrayElement($postParams, 'wpf_unique_id')) { - return ' + $wpf_unique_id = self::getArrayElement($postParams, 'wpf_unique_id'); + + return ($wpf_unique_id) ? ' ' . $wpf_unique_id . ' -'; - } - - return null; +' + : null; } } diff --git a/Test/Unit/Helper/DataTest.php b/Test/Unit/Helper/DataTest.php old mode 100755 new mode 100644 index 3a6ed68..84a0d61 --- a/Test/Unit/Helper/DataTest.php +++ b/Test/Unit/Helper/DataTest.php @@ -1,6 +1,6 @@ getMockBuilder('\Magento\Sales\Model\Order\Payment\Transaction') + return $this->getMockBuilder(Transaction::class) + ->disableOriginalConstructor() + ->onlyMethods(['getAdditionalInformation', 'save', 'setIsClosed', 'load', 'getId']) + ->getMock(); + } + + /** + * @return (PaymentData&MockObject)|MockObject + */ + protected function getPaymentDataMock() + { + return $this->getMockBuilder(PaymentData::class) + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * @return (ConfigFactory&MockObject)|MockObject + */ + protected function getConfigFactoryMock() + { + return $this->getMockBuilder(ConfigFactory::class) + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * @return (Session&MockObject)|MockObject + */ + protected function getCustomerSessionMock() + { + return $this->getMockBuilder(Session::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getAdditionalInformation' - ] - ) ->getMock(); } /** - * @return \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject + * @return (FrontendConfig&MockObject)|MockObject + */ + protected function getConfigMock() + { + return $this->getMockBuilder(FrontendConfig::class) + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * @return (TransactionRepositoryInterface&MockObject)|MockObject + */ + protected function getPaymentTransactionRepositoryMock() + { + return $this->getMockBuilder(TransactionRepositoryInterface::class) + ->disableOriginalConstructor() + ->onlyMethods(['save', 'getList', 'get', 'delete', 'create']) + ->getMock(); + } + + /** + * @return (OrderRepositoryInterface&MockObject)|MockObject + */ + protected function getOrderRepositoryMock() + { + return $this->getMockBuilder(OrderRepositoryInterface::class) + ->disableOriginalConstructor() + ->onlyMethods(['save', 'get', 'getList', 'delete']) + ->getMock(); + } + + /** + * @return Order|MockObject */ protected function getOrderMock() { - $orderConfigMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Config::class) + $orderConfigMock = $this->getMockBuilder(OrderConfig::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getStateDefaultStatus' - ] - ) + ->onlyMethods(['getStateDefaultStatus']) ->getMock(); - $orderMock = $this->getMockBuilder(\Magento\Sales\Model\Order::class) + $orderMock = $this->getMockBuilder(Order::class) ->disableOriginalConstructor() - ->setMethods( + ->onlyMethods( [ 'getConfig', 'setState', @@ -105,7 +223,6 @@ protected function getOrderMock() 'getInvoiceCollection', 'registerCancellation', 'setCustomerNoteNotify', - 'save' ] ) ->getMock(); @@ -135,15 +252,37 @@ protected function setUp(): void $this->setUpBasicMocks(); $this->setUpContextMock(); $this->setUpStoreManagerMock(); + $this->orderRepositoryMock = $this->getOrderRepositoryMock(); + $this->transactionMock = $this->getPaymentTransactionMock(); + $this->transactionRepositoryMock = $this->getPaymentTransactionRepositoryMock(); + $this->paymentDataMock = $this->getPaymentDataMock(); + $this->configFactoryMock = $this->getConfigFactoryMock(); + $this->customerSessionMock = $this->getCustomerSessionMock(); + $this->configMock = $this->getConfigMock(); + + $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) + ->disableOriginalConstructor() + ->getMock(); - $this->moduleHelper = $this->getObjectManagerHelper()->getObject( - EMerchantPayDataHelper::class, - [ - 'context' => $this->contextMock, - 'storeManager' => $this->storeManagerMock, - 'localeResolver' => $this->localeResolverMock - ] - ); + $this->objectManagerMock->method('create') + ->with(Transaction::class) + ->willReturn($this->transactionMock); + + $this->moduleHelper = $this->getMockBuilder(EMerchantPayDataHelper::class) + ->setConstructorArgs([ + 'transactionRepository' => $this->transactionRepositoryMock, + 'objectManager' => $this->objectManagerMock, + 'context' => $this->contextMock, + 'storeManager' => $this->storeManagerMock, + 'localeResolver' => $this->localeResolverMock, + 'orderRepository' => $this->orderRepositoryMock, + 'paymentData' => $this->paymentDataMock, + 'configFactory' => $this->configFactoryMock, + 'customerSession' => $this->customerSessionMock, + 'config' => $this->configMock, + ]) + ->onlyMethods(['getPaymentTransaction', 'setTransactionAdditionalInfo']) + ->getMock(); } /** @@ -151,21 +290,21 @@ protected function setUp(): void */ protected function setUpBasicMocks() { - $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class) + $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) ->getMock(); - $this->storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class) + $this->storeMock = $this->getMockBuilder(Store::class) ->disableOriginalConstructor() ->getMock(); $this->urlBuilderMock = $this->getMockBuilder(\Magento\Framework\Url::class) ->disableOriginalConstructor() - ->setMethods(['getUrl']) + ->onlyMethods(['getUrl']) ->getMock(); - $this->localeResolverMock = $this->getMockBuilder(\Magento\Framework\Locale\Resolver::class) + $this->localeResolverMock = $this->getMockBuilder(Resolver::class) ->disableOriginalConstructor() - ->setMethods(['getLocale']) + ->onlyMethods(['getLocale']) ->getMock(); } @@ -174,22 +313,23 @@ protected function setUpBasicMocks() */ protected function setUpContextMock() { - $this->contextMock = $this->getMockBuilder(\Magento\Framework\App\Helper\Context::class) + $this->contextMock = $this->getMockBuilder(Context::class) ->disableOriginalConstructor() - ->setMethods(['getScopeConfig', 'getUrlBuilder']) + ->onlyMethods( + [ + 'getScopeConfig', + 'getUrlBuilder' + ] + ) ->getMock(); $this->contextMock->expects(static::any()) ->method('getScopeConfig') - ->willReturn( - $this->scopeConfigMock - ); + ->willReturn($this->scopeConfigMock); $this->contextMock->expects(static::any()) ->method('getUrlBuilder') - ->willReturn( - $this->urlBuilderMock - ); + ->willReturn($this->urlBuilderMock); } /** @@ -199,20 +339,17 @@ protected function setUpStoreManagerMock() { $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManager::class) ->disableOriginalConstructor() - ->setMethods(['getStore', 'getUrlBuilder']) + ->addMethods(['getUrlBuilder']) + ->onlyMethods(['getStore']) ->getMock(); $this->storeManagerMock->expects(static::any()) ->method('getStore') - ->willReturn( - $this->storeMock - ); + ->willReturn($this->storeMock); $this->storeManagerMock->expects(static::any()) ->method('getUrlBuilder') - ->willReturn( - $this->urlBuilderMock - ); + ->willReturn($this->urlBuilderMock); } /** @@ -299,9 +436,7 @@ public function testGetTransactionAdditionalInfoValue() $transactionMock->expects(static::exactly(3)) ->method('getAdditionalInformation') - ->with( - \Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS - ) + ->with(Transaction::RAW_DETAILS) ->willReturn( [ EMerchantPayDataHelper::ADDITIONAL_INFO_KEY_REDIRECT_URL => @@ -335,27 +470,23 @@ public function testGetTransactionAdditionalInfoValue() } /** - * @covers EMer + * @covers EMerchantPayDataHelper::getTransactionAdditionalInfoValue() */ public function testGetPaymentAdditionalInfoValue() { /** - * @var $paymentMock \Magento\Payment\Model\InfoInterface|\PHPUnit_Framework_MockObject_MockObject + * @var $paymentMock InfoInterface|MockObject */ - $paymentMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Payment::class) + $paymentMock = $this->getMockBuilder(Payment::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getTransactionAdditionalInfo' - ] - ) + ->onlyMethods(['getTransactionAdditionalInfo']) ->getMock(); $paymentMock->expects(static::exactly(2)) ->method('getTransactionAdditionalInfo') ->willReturn( [ - \Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS => [ + Transaction::RAW_DETAILS => [ EMerchantPayDataHelper::ADDITIONAL_INFO_KEY_STATUS => GenesisTransactionStates::APPROVED, EMerchantPayDataHelper::ADDITIONAL_INFO_KEY_TRANSACTION_TYPE => @@ -380,15 +511,18 @@ public function testGetPaymentAdditionalInfoValue() ); } + /** + * @covers EMerchantPayDataHelper::setTokenByPaymentTransaction() + * + * @return void + */ public function testSetTokenByPaymentTransaction() { $declinedSaleTransactionMock = $this->getPaymentTransactionMock(); $declinedSaleTransactionMock->expects(static::once()) ->method('getAdditionalInformation') - ->with( - \Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS - ) + ->with(Transaction::RAW_DETAILS) ->willReturn( [ EMerchantPayDataHelper::ADDITIONAL_INFO_KEY_STATUS => @@ -400,9 +534,7 @@ public function testSetTokenByPaymentTransaction() $this->moduleHelper->setTokenByPaymentTransaction($declinedSaleTransactionMock); - $this->assertNull( - \Genesis\Config::getToken() - ); + $this->assertNull(GenesisConfig::getToken()); $gatewayTerminalToken = 'gateway_token_098f6bcd4621d373cade4e832627b4f6'; @@ -410,9 +542,7 @@ public function testSetTokenByPaymentTransaction() $approvedSaleTransactionMock->expects(static::once()) ->method('getAdditionalInformation') - ->with( - \Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS - ) + ->with(Transaction::RAW_DETAILS) ->willReturn( [ EMerchantPayDataHelper::ADDITIONAL_INFO_KEY_STATUS => @@ -428,7 +558,7 @@ public function testSetTokenByPaymentTransaction() $this->assertEquals( $gatewayTerminalToken, - \Genesis\Config::getToken() + GenesisConfig::getToken() ); } @@ -439,13 +569,13 @@ public function testMaskException() { $exceptionMessage = 'Exception Message'; - $this->expectException(\Magento\Framework\Webapi\Exception::class); + $this->expectException(WebApiException::class); $this->expectExceptionMessage($exceptionMessage); $this->moduleHelper->maskException( - new \Exception( + new Exception( $exceptionMessage, - \Magento\Framework\Webapi\Exception::HTTP_INTERNAL_ERROR + WebApiException::HTTP_INTERNAL_ERROR ) ); } @@ -455,16 +585,14 @@ public function testMaskException() */ public function testGetArrayFromGatewayResponse() { - $gatewayResponse = new \stdClass(); - $gatewayResponse->status = GenesisTransactionStates::APPROVED; - $gatewayResponse->message = 'Gateway Response Message Text'; + $gatewayResponse = new stdClass(); + $gatewayResponse->status = GenesisTransactionStates::APPROVED; + $gatewayResponse->message = 'Gateway Response Message Text'; $gatewayResponse->transaction_type = GenesisTransactionTypes::PAYSAFECARD; $arrObj = $this->moduleHelper->getArrayFromGatewayResponse($gatewayResponse); - $this->assertTrue( - is_array($arrObj) - ); + $this->assertTrue(is_array($arrObj)); $this->assertArrayHasKeys( [ @@ -484,14 +612,10 @@ public function testSetOrderStateProcessing() $orderMock = $this->getOrderMock(); /** - * @var $orderConfigMock \Magento\Sales\Model\Order\Config|\PHPUnit_Framework_MockObject_MockObject + * @var $orderConfigMock Order\Config|MockObject */ $orderConfigMock = $orderMock->getConfig(); - $orderMock->expects(static::once()) - ->method('save') - ->willReturnSelf(); - $orderMock->expects(static::once()) ->method('setState') ->willReturnSelf(); @@ -503,12 +627,16 @@ public function testSetOrderStateProcessing() $orderConfigMock->expects(static::once()) ->method('getStateDefaultStatus') ->with( - \Magento\Sales\Model\Order::STATE_PROCESSING + Order::STATE_PROCESSING ) ->willReturn( - \Magento\Sales\Model\Order::STATE_PROCESSING + Order::STATE_PROCESSING ); + $this->orderRepositoryMock->expects(static::once()) + ->method('save') + ->with($orderMock); + $this->moduleHelper->setOrderState( $orderMock, GenesisTransactionStates::APPROVED @@ -523,14 +651,10 @@ public function testSetOrderStatePending() $orderMock = $this->getOrderMock(); /** - * @var $orderConfigMock \Magento\Sales\Model\Order\Config|\PHPUnit_Framework_MockObject_MockObject + * @var $orderConfigMock Order\Config|MockObject */ $orderConfigMock = $orderMock->getConfig(); - $orderMock->expects(static::exactly(2)) - ->method('save') - ->willReturnSelf(); - $orderMock->expects(static::exactly(2)) ->method('setState') ->willReturnSelf(); @@ -544,12 +668,12 @@ public function testSetOrderStatePending() $orderConfigMock->expects(static::exactly(2)) ->method('getStateDefaultStatus') - ->with( - \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT - ) - ->willReturn( - \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT - ); + ->with(Order::STATE_PENDING_PAYMENT) + ->willReturn(Order::STATE_PENDING_PAYMENT); + + $this->orderRepositoryMock->expects(static::exactly(2)) + ->method('save') + ->with($orderMock); $this->moduleHelper->setOrderState( $orderMock, @@ -570,7 +694,7 @@ public function testSetOrderStateErrorOrDeclined() $orderMock = $this->getOrderMock(); /** - * @var $orderConfigMock \Magento\Sales\Model\Order\Config|\PHPUnit_Framework_MockObject_MockObject + * @var $orderConfigMock Order\Config|MockObject */ $orderConfigMock = $orderMock->getConfig(); @@ -592,13 +716,13 @@ public function testSetOrderStateErrorOrDeclined() ->method('setCustomerNoteNotify') ->willReturnSelf(); - $orderMock->expects(static::exactly(2)) - ->method('save') - ->willReturnSelf(); - $orderConfigMock->expects(static::exactly(2)) ->method('getStateDefaultStatus'); + $this->orderRepositoryMock->expects(static::exactly(2)) + ->method('save') + ->with($orderMock); + $this->moduleHelper->setOrderState( $orderMock, GenesisTransactionStates::ERROR @@ -618,7 +742,7 @@ public function testSetOrderStateOnPaymentTimeoutOrVoid() $orderMock = $this->getOrderMock(); /** - * @var $orderConfigMock \Magento\Sales\Model\Order\Config|\PHPUnit_Framework_MockObject_MockObject + * @var $orderConfigMock Order\Config|MockObject */ $orderConfigMock = $orderMock->getConfig(); @@ -640,13 +764,13 @@ public function testSetOrderStateOnPaymentTimeoutOrVoid() ->method('setCustomerNoteNotify') ->willReturnSelf(); - $orderMock->expects(static::exactly(2)) - ->method('save') - ->willReturnSelf(); - $orderConfigMock->expects(static::exactly(2)) ->method('getStateDefaultStatus'); + $this->orderRepositoryMock->expects(static::exactly(2)) + ->method('save') + ->with($orderMock); + $this->moduleHelper->setOrderState( $orderMock, GenesisTransactionStates::TIMEOUT @@ -666,15 +790,13 @@ public function testGetGlobalAllowedCurrencyCodes() $this->scopeConfigMock->expects(static::once()) ->method('getValue') ->with( - \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW + Currency::XML_PATH_CURRENCY_ALLOW ) ->willReturn('USD,EUR,GBP'); $globalAllowedCurrencyCodes = $this->moduleHelper->getGlobalAllowedCurrencyCodes(); - $this->assertTrue( - is_array($globalAllowedCurrencyCodes) - ); + $this->assertTrue(is_array($globalAllowedCurrencyCodes)); $this->assertArrayKeysCount( 3, @@ -698,9 +820,7 @@ public function testGetGlobalAllowedCurrenciesOptions() { $this->scopeConfigMock->expects(static::once()) ->method('getValue') - ->with( - \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW - ) + ->with(Currency::XML_PATH_CURRENCY_ALLOW) ->willReturn('USD,EUR,GBP'); $allowedCurrenciesOptions = $this->moduleHelper->getGlobalAllowedCurrenciesOptions( @@ -717,9 +837,7 @@ public function testGetGlobalAllowedCurrenciesOptions() ] ); - $this->assertTrue( - is_array($allowedCurrenciesOptions) - ); + $this->assertTrue(is_array($allowedCurrenciesOptions)); $this->assertArrayKeysCount(2, $allowedCurrenciesOptions); @@ -744,19 +862,19 @@ public function testGetDefaultLocale() $this->localeResolverMock->expects(static::once()) ->method('getLocale') ->willReturn( - \Magento\Framework\Locale\Resolver::DEFAULT_LOCALE + Resolver::DEFAULT_LOCALE ); $gatewayLocale = $this->moduleHelper->getLocale('de'); $this->assertTrue( - \Genesis\Api\Constants\i18n::isValidLanguageCode($gatewayLocale) + i18n::isValidLanguageCode($gatewayLocale) ); $this->assertEquals( $gatewayLocale, substr( - \Magento\Framework\Locale\Resolver::DEFAULT_LOCALE, + Resolver::DEFAULT_LOCALE, 0, 2 ) @@ -779,9 +897,7 @@ public function testGetUnsupportedGatewayLocale() $gatewayLocale = $this->moduleHelper->getLocale($defaultLocale); - $this->assertTrue( - \Genesis\Api\Constants\i18n::isValidLanguageCode($gatewayLocale) - ); + $this->assertTrue(i18n::isValidLanguageCode($gatewayLocale)); $this->assertEquals( $gatewayLocale, @@ -797,13 +913,10 @@ public function testCanRefundCaptureTransaction() $captureTransactionMock = $this->getPaymentTransactionMock(); $captureTransactionMock->expects(static::once()) ->method('getAdditionalInformation') - ->with( - \Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS - ) + ->with(Transaction::RAW_DETAILS) ->willReturn( [ - EMerchantPayDataHelper::ADDITIONAL_INFO_KEY_TRANSACTION_TYPE => - \Genesis\Api\Constants\Transaction\Types::CAPTURE + EMerchantPayDataHelper::ADDITIONAL_INFO_KEY_TRANSACTION_TYPE => GenesisTransactionTypes::CAPTURE ] ); @@ -822,13 +935,11 @@ public function testCanRefundPaySafeCardTransaction() $captureTransactionMock = $this->getPaymentTransactionMock(); $captureTransactionMock->expects(static::once()) ->method('getAdditionalInformation') - ->with( - \Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS - ) + ->with(Transaction::RAW_DETAILS) ->willReturn( [ EMerchantPayDataHelper::ADDITIONAL_INFO_KEY_TRANSACTION_TYPE => - \Genesis\Api\Constants\Transaction\Types::PAYSAFECARD + GenesisTransactionTypes::PAYSAFECARD ] ); @@ -847,13 +958,10 @@ public function testCanRefundSaleTransaction() $captureTransactionMock = $this->getPaymentTransactionMock(); $captureTransactionMock->expects(static::once()) ->method('getAdditionalInformation') - ->with( - \Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS - ) + ->with(Transaction::RAW_DETAILS) ->willReturn( [ - EMerchantPayDataHelper::ADDITIONAL_INFO_KEY_TRANSACTION_TYPE => - \Genesis\Api\Constants\Transaction\Types::SALE + EMerchantPayDataHelper::ADDITIONAL_INFO_KEY_TRANSACTION_TYPE => GenesisTransactionTypes::SALE ] ); @@ -871,25 +979,25 @@ public function testGetIsTransactionThreeDSecure() { $this->assertTrue( $this->moduleHelper->getIsTransactionThreeDSecure( - \Genesis\Api\Constants\Transaction\Types::AUTHORIZE_3D + GenesisTransactionTypes::AUTHORIZE_3D ) ); $this->assertFalse( $this->moduleHelper->getIsTransactionThreeDSecure( - \Genesis\Api\Constants\Transaction\Types::AUTHORIZE + GenesisTransactionTypes::AUTHORIZE ) ); $this->assertTrue( $this->moduleHelper->getIsTransactionThreeDSecure( - \Genesis\Api\Constants\Transaction\Types::SALE_3D + GenesisTransactionTypes::SALE_3D ) ); $this->assertFalse( $this->moduleHelper->getIsTransactionThreeDSecure( - \Genesis\Api\Constants\Transaction\Types::SALE + GenesisTransactionTypes::SALE ) ); } @@ -899,12 +1007,12 @@ public function testGetIsTransactionThreeDSecure() */ public function testGetSuccessErrorMessageFromGatewayResponse() { - $successfulGatewayResponseMessage = 'Transaction successful!'; + $successfulGatewayResponseMessage = 'Transaction successful!'; $successfulGatewayResponseTechMessage = 'Transaction has been processed successfully!'; $validGatewayResponseWithMessage = $this->getSampleGatewayResponse( - \Genesis\Api\Constants\Transaction\States::APPROVED, - \Genesis\Api\Constants\Transaction\Types::AUTHORIZE, + GenesisTransactionStates::APPROVED, + GenesisTransactionTypes::AUTHORIZE, $successfulGatewayResponseMessage, $successfulGatewayResponseTechMessage ); @@ -930,8 +1038,8 @@ public function testGetSuccessErrorMessageFromGatewayResponse() public function testGetFailedErrorMessageFromGatewayResponse() { $validGatewayResponseWithMessage = $this->getSampleGatewayResponse( - \Genesis\Api\Constants\Transaction\States::DECLINED, - \Genesis\Api\Constants\Transaction\Types::SALE + GenesisTransactionStates::DECLINED, + GenesisTransactionTypes::SALE ); $gatewayResponseMessage = $this->moduleHelper->getErrorMessageFromGatewayResponse( @@ -949,14 +1057,14 @@ public function testGetFailedErrorMessageFromGatewayResponse() */ public function testGetPendingAsyncSuccessErrorMessageFromGatewayResponse() { - $successfulGatewayResponseMessage = 'Transaction successful!'; + $successfulGatewayResponseMessage = 'Transaction successful!'; $successfulGatewayResponseTechnicalMessage = 'Transaction has been processed successfully!'; $validGatewayResponseWithMessage = $this->getSampleGatewayResponse( - \Genesis\Api\Constants\Transaction\States::PENDING_ASYNC, - \Genesis\Api\Constants\Transaction\Types::REFUND, + GenesisTransactionStates::PENDING_ASYNC, + GenesisTransactionTypes::REFUND, $successfulGatewayResponseMessage, - $successfulGatewayResponseTechnicalMessage + $successfulGatewayResponseTechnicalMessage ); $gatewayResponseMessage = $this->moduleHelper->getErrorMessageFromGatewayResponse( @@ -969,7 +1077,7 @@ public function testGetPendingAsyncSuccessErrorMessageFromGatewayResponse() ); $this->assertStringEndsWith( - $successfulGatewayResponseTechnicalMessage, + $successfulGatewayResponseTechnicalMessage, $gatewayResponseMessage ); } @@ -979,20 +1087,20 @@ public function testGetPendingAsyncSuccessErrorMessageFromGatewayResponse() */ public function testGetReturnUrl() { - $moduleCode = 'emerchantpay_checkout'; - $returnAction = EMerchantPayDataHelper::ACTION_RETURN_SUCCESS; - $expectedUrlIframe = 'https://example.com/emerchantpay/checkout/iframe/action/success'; + $moduleCode = 'emerchantpay_checkout'; + $returnAction = EMerchantPayDataHelper::ACTION_RETURN_SUCCESS; + $expectedUrlIframe = 'https://example.com/emerchantpay/checkout/iframe/action/success'; $expectedUrlRedirect = 'https://example.com/emerchantpay/checkout/redirect/action/success'; // Mocking the Config class to return true for isIframeProcessingEnabled - $configMock = $this->createMock(\EMerchantPay\Genesis\Block\Frontend\Config::class); + $configMock = $this->createMock(FrontendConfig::class); $configMock->expects($this->exactly(2)) ->method('isIframeProcessingEnabled') ->willReturnOnConsecutiveCalls(true, false); // Use reflection to set the protected property _config - $reflectionClass = new \ReflectionClass(EMerchantPayDataHelper::class); - $configProperty = $reflectionClass->getProperty('_config'); + $reflectionClass = new ReflectionClass(EMerchantPayDataHelper::class); + $configProperty = $reflectionClass->getProperty('_config'); $configProperty->setAccessible(true); $configProperty->setValue($this->moduleHelper, $configMock); @@ -1005,8 +1113,22 @@ public function testGetReturnUrl() $this->urlBuilderMock->expects($this->exactly(2)) ->method('getUrl') ->withConsecutive( - ['emerchantpay/checkout/iframe', ['_store' => $this->storeMock, '_secure' => null, 'action' => $returnAction]], - ['emerchantpay/checkout/redirect', ['_store' => $this->storeMock, '_secure' => null, 'action' => $returnAction]] + [ + 'emerchantpay/checkout/iframe', + [ + '_store' => $this->storeMock, + '_secure' => null, + 'action' => $returnAction + ] + ], + [ + 'emerchantpay/checkout/redirect', + [ + '_store' => $this->storeMock, + '_secure' => null, + 'action' => $returnAction + ] + ] ) ->willReturnOnConsecutiveCalls($expectedUrlIframe, $expectedUrlRedirect); @@ -1018,4 +1140,86 @@ public function testGetReturnUrl() $actualUrlRedirect = $this->moduleHelper->getReturnUrl($moduleCode, $returnAction); $this->assertEquals($expectedUrlRedirect, $actualUrlRedirect); } + + /** + * @covers EMerchantPayDataHelper::updateTransactionAdditionalInfo + * + * @return void + * + * @throws Exception + */ + public function testUpdateTransactionAdditionalInfoTransactionFound() + { + $transactionId = '123'; + $responseObject = new stdClass(); + $shouldCloseTransaction = true; + + $this->transactionMock->method('load') + ->with($transactionId, 'txn_id') + ->willReturnSelf(); + + $this->transactionMock->method('getId') + ->willReturn(1); + + $this->moduleHelper->method('getPaymentTransaction') + ->with($transactionId) + ->willReturn($this->transactionMock); + + $this->moduleHelper->expects($this->once()) + ->method('setTransactionAdditionalInfo') + ->with($this->transactionMock, $responseObject); + + $this->transactionMock->expects($this->once()) + ->method('setIsClosed') + ->with(true); + + $this->transactionRepositoryMock->expects($this->once()) + ->method('save') + ->with($this->transactionMock); + + $result = $this->moduleHelper->updateTransactionAdditionalInfo( + $transactionId, + $responseObject, + $shouldCloseTransaction + ); + + $this->assertTrue($result); + } + + /** + * @covers EMerchantPayDataHelper::updateTransactionAdditionalInfo + * + * @return void + * + * @throws Exception + */ + public function testUpdateTransactionAdditionalInfoTransactionNotFound() + { + $transactionId = '123'; + $responseObject = new stdClass(); + $shouldCloseTransaction = false; + + $this->moduleHelper = $this->getMockBuilder(EMerchantPayDataHelper::class) + ->disableOriginalConstructor() + ->onlyMethods(['getPaymentTransaction', 'setTransactionAdditionalInfo']) + ->getMock(); + + $this->moduleHelper->method('getPaymentTransaction') + ->with($transactionId) + ->willReturn(null); + + $this->moduleHelper->expects($this->never()) + ->method('setTransactionAdditionalInfo'); + + $this->transactionRepositoryMock->expects($this->never()) + ->method('save'); + + $result = $this->moduleHelper->updateTransactionAdditionalInfo( + $transactionId, + $responseObject, + $shouldCloseTransaction + ); + + $this->assertFalse($result); + } } diff --git a/Test/Unit/Helper/ThreedsTest.php b/Test/Unit/Helper/ThreedsTest.php index 9d89f2c..abe6fb8 100644 --- a/Test/Unit/Helper/ThreedsTest.php +++ b/Test/Unit/Helper/ThreedsTest.php @@ -19,16 +19,31 @@ namespace EMerchantPay\Genesis\Test\Unit\Helper; +use ArrayIterator; +use DateTime; +use EMerchantPay\Genesis\Helper\Data; use EMerchantPay\Genesis\Helper\Threeds; +use EMerchantPay\Genesis\Test\Unit\AbstractTestCase; +use Magento\Customer\Model\Address; +use Magento\Customer\Model\Customer; +use Magento\Framework\App\Helper\Context; +use Magento\Framework\DB\Select; +use Magento\Framework\DataObject; +use Magento\Framework\Stdlib\DateTime\Timezone; use Magento\Sales\Model\Order; +use Magento\Sales\Model\Order\Item; +use Magento\Sales\Model\ResourceModel\Order\Collection; +use Magento\Sales\Model\ResourceModel\Order\CollectionFactory; +use PHPUnit\Framework\MockObject\MockObject; /** + * Test 3DS functions + * * Class ThreedsTest - * @package EMerchantPay\Genesis\Test\Unit\Helper * * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ -class ThreedsTest extends \EMerchantPay\Genesis\Test\Unit\AbstractTestCase +class ThreedsTest extends AbstractTestCase { /** * @var Threeds @@ -36,32 +51,32 @@ class ThreedsTest extends \EMerchantPay\Genesis\Test\Unit\AbstractTestCase protected $threedsHelper; /** - * @var \Magento\Framework\App\Helper\Context|\PHPUnit\Framework\MockObject\MockObject + * @var Context|MockObject */ protected $contextMock; /** - * @var \Magento\Framework\Stdlib\DateTime\Timezone|\PHPUnit\Framework\MockObject\MockObject + * @var Timezone|MockObject */ protected $timezoneMock; /** - * @var \EMerchantPay\Genesis\Helper\Data|\PHPUnit\Framework\MockObject\MockObject + * @var Data|MockObject */ protected $moduleHelper; /** - * @var \Magento\Sales\Model\Order|\PHPUnit\Framework\MockObject\MockObject + * @var Order|MockObject */ protected $orderMock; /** - * @var \PHPUnit\Framework\MockObject\MockObject|\Magento\Customer\Model\Customer + * @var Customer|MockObject */ protected $customerMock; /** - * @var \PHPUnit\Framework\MockObject\MockObject|\Magento\Sales\Model\ResourceModel\Order\CollectionFactory + * @var CollectionFactory|MockObject */ protected $orderCollectionFacotryMock; @@ -246,15 +261,15 @@ public function testFetchRegistrationIndicator() /** * Timezone Date Stub * - * @return \DateTime + * @return DateTime */ public function dateCallback($args) { if (!empty($args)) { - return \DateTime::createFromFormat('Y-m-d H:i:s', $args); + return DateTime::createFromFormat('Y-m-d H:i:s', $args); } - return new \DateTime(); + return new DateTime(); } /** @@ -263,14 +278,10 @@ public function dateCallback($args) protected function setUpBasicMocks() { $this->timezoneMock = $this->getMockBuilder( - \Magento\Framework\Stdlib\DateTime\Timezone::class + Timezone::class ) ->disableOriginalConstructor() - ->setMethods( - [ - 'date' - ] - ) + ->onlyMethods(['date']) ->getMock(); $this->timezoneMock->expects(static::any()) @@ -278,14 +289,10 @@ protected function setUpBasicMocks() ->will($this->returnCallback([$this, 'dateCallback'])); $this->orderCollectionFacotryMock = $this->getMockBuilder( - \Magento\Sales\Model\ResourceModel\Order\CollectionFactory::class + CollectionFactory::class ) ->disableOriginalConstructor() - ->setMethods( - [ - 'create' - ] - ) + ->onlyMethods(['create']) ->getMock(); $this->orderCollectionFacotryMock->expects(static::any()) ->method('create') @@ -297,7 +304,7 @@ protected function setUpBasicMocks() */ protected function setUpContextMock() { - $this->contextMock = $this->getMockBuilder(\Magento\Framework\App\Helper\Context::class) + $this->contextMock = $this->getMockBuilder(Context::class) ->disableOriginalConstructor() ->getMock(); } @@ -309,7 +316,7 @@ protected function setUpOrderMock($productId = 1) { $this->orderMock = $this->getMockBuilder(Order::class) ->disableOriginalConstructor() - ->setMethods( + ->onlyMethods( [ 'getCustomerId', 'getBillingAddress', @@ -337,9 +344,9 @@ protected function setUpOrderMock($productId = 1) */ protected function setUpModuleHelperMock() { - $this->moduleHelper = $this->getMockBuilder(\EMerchantPay\Genesis\Helper\Data::class) + $this->moduleHelper = $this->getMockBuilder(Data::class) ->disableOriginalConstructor() - ->setMethods( + ->onlyMethods( [ 'getMethodConfig', 'getCustomerOrders' @@ -357,11 +364,11 @@ protected function setUpModuleHelperMock() */ protected function setUpCustomerMock() { - $this->customerMock = $this->getMockBuilder(\Magento\Customer\Model\Customer::class) + $this->customerMock = $this->getMockBuilder(Customer::class) ->disableOriginalConstructor() - ->setMethods( + ->onlyMethods(['getAddresses']) + ->addMethods( [ - 'getAddresses', 'getCreatedAt', 'getUpdatedAt' ] @@ -390,7 +397,7 @@ protected function setUpCustomerMock() */ protected function getItemMock($productId = 1) { - $itemMock = $this->getMockBuilder('\Magento\Sales\Model\Order\Item') + $itemMock = $this->getMockBuilder(Item::class) ->disableOriginalConstructor() ->getMock(); $itemMock->expects(static::any()) @@ -405,14 +412,10 @@ protected function getItemMock($productId = 1) */ protected function getAddressesMock($createdAt = '2021-01-30 12:12:12', $updatedAt = '2021-01-31 12:12:12') { - $address = $this->getMockBuilder(\Magento\Customer\Model\Address::class) + $address = $this->getMockBuilder(Address::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getData', - 'getCustomerAddressId' - ] - ) + ->onlyMethods(['getData']) + ->addMethods(['getCustomerAddressId']) ->getMock(); $address->expects(static::any()) @@ -437,11 +440,9 @@ protected function getAddressesMock($createdAt = '2021-01-30 12:12:12', $updated */ protected function getOrderCollectionMock() { - $orderCollectionMock = $this->getMockBuilder( - \Magento\Sales\Model\ResourceModel\Order\Collection::class - ) + $orderCollectionMock = $this->getMockBuilder(Collection::class) ->disableOriginalConstructor() - ->setMethods( + ->onlyMethods( [ 'join', 'addFieldToFilter', @@ -450,11 +451,6 @@ protected function getOrderCollectionMock() 'setPageSize', 'getSize', 'getFirstItem', - 'rewind', - 'current', - 'key', - 'next', - 'valid', '_beforeLoad', '_fetchAll', '_afterLoad', @@ -463,6 +459,15 @@ protected function getOrderCollectionMock() 'beforeAddLoadedItem' ] ) + ->addMethods( + [ + 'rewind', + 'current', + 'key', + 'next', + 'valid', + ] + ) ->getMock(); $orderCollectionMock @@ -509,7 +514,7 @@ protected function getOrderCollectionMock() ->method('getFirstItem') ->willReturn($this->getDataObjectMock()); - $iterator = new \ArrayIterator([$this->orderMock]); + $iterator = new ArrayIterator([$this->orderMock]); $orderCollectionMock->expects(static::any()) ->method('rewind') @@ -557,9 +562,9 @@ protected function getOrderCollectionMock() */ protected function getMagentoSelectMock() { - $selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class) + $selectMock = $this->getMockBuilder(Select::class) ->disableOriginalConstructor() - ->setMethods( + ->onlyMethods( [ 'reset', 'columns' @@ -583,13 +588,9 @@ protected function getMagentoSelectMock() */ protected function getDataObjectMock() { - $dataMock = $this->getMockBuilder(\Magento\Framework\DataObject::class) + $dataMock = $this->getMockBuilder(DataObject::class) ->disableOriginalConstructor() - ->setMethods( - [ - 'getCreatedAt' - ] - ) + ->addMethods(['getCreatedAt']) ->getMock(); $dataMock->expects(static::any()) diff --git a/Test/Unit/Model/Config/Source/Method/Checkout/BankCodeTest.php b/Test/Unit/Model/Config/Source/Method/Checkout/BankCodeTest.php index b57d4dd..f05e4c5 100644 --- a/Test/Unit/Model/Config/Source/Method/Checkout/BankCodeTest.php +++ b/Test/Unit/Model/Config/Source/Method/Checkout/BankCodeTest.php @@ -23,29 +23,24 @@ use PHPUnit\Framework\TestCase; /** - * @covers \EMerchantPay\Genesis\Model\Config\Source\Method\Checkout\BankCode - * @package Unit\Model\Config\Source\Method\Checkout + * @covers BankCode */ class BankCodeTest extends TestCase { /** - * @covers \EMerchantPay\Genesis\Model\Config\Source\Method\Checkout\BankCode::toOptionArray + * @covers BankCode::toOptionArray */ public function testToOptionArray() { - $data = []; - $sourceModel = new BankCode(); - - $availableBankCodes = BankCode::$availableBankCodes; + $data = []; + $sourceModel = new BankCode(); + $availableBankCodes = $sourceModel->availableBankCodes; foreach ($availableBankCodes as $value => $label) { - array_push( - $data, - [ - 'value' => $value, - 'label' => __($label) - ] - ); + $data[] = [ + 'value' => $value, + 'label' => __($label) + ]; } $this->assertEquals( diff --git a/Test/Unit/Model/Config/Source/Method/Checkout/ChallengeIndicatorTest.php b/Test/Unit/Model/Config/Source/Method/Checkout/ChallengeIndicatorTest.php index e767b56..baff59a 100644 --- a/Test/Unit/Model/Config/Source/Method/Checkout/ChallengeIndicatorTest.php +++ b/Test/Unit/Model/Config/Source/Method/Checkout/ChallengeIndicatorTest.php @@ -24,34 +24,24 @@ use PHPUnit\Framework\TestCase; /** - * @covers \EMerchantPay\Genesis\Model\Config\Source\Method\Checkout\ChallengeIndicator - * @package Unit\Model\Config\Source\Method\Checkout + * @covers ChallengeIndicator */ class ChallengeIndicatorTest extends TestCase { /** - * @covers \EMerchantPay\Genesis\Model\Config\Source\Method\Checkout\ChallengeIndicator::toOptionArray + * @covers ChallengeIndicator::toOptionArray */ public function testToOptionArray() { - $data = []; - $sourceModel = new ChallengeIndicator(); - - $availableCHallengeIndicators = [ - ChallengeIndicators::NO_PREFERENCE => 'No Preference', - ChallengeIndicators::NO_CHALLENGE_REQUESTED => 'No Challenge Requested', - ChallengeIndicators::PREFERENCE => 'Preference', - ChallengeIndicators::MANDATE => 'Mandate' - ]; + $data = []; + $sourceModel = new ChallengeIndicator(); + $availableCHallengeIndicators = $sourceModel->indicators; foreach ($availableCHallengeIndicators as $value => $label) { - array_push( - $data, - [ - 'value' => $value, - 'label' => __($label) - ] - ); + $data[] = [ + 'value' => $value, + 'label' => __($label) + ]; } $this->assertEquals( diff --git a/Test/Unit/Model/Config/Source/Method/Checkout/ScaExemptionTest.php b/Test/Unit/Model/Config/Source/Method/Checkout/ScaExemptionTest.php index e8b0f04..f458eb1 100644 --- a/Test/Unit/Model/Config/Source/Method/Checkout/ScaExemptionTest.php +++ b/Test/Unit/Model/Config/Source/Method/Checkout/ScaExemptionTest.php @@ -19,37 +19,30 @@ namespace Unit\Model\Config\Source\Method\Checkout; +use EMerchantPay\Genesis\Model\Config\Source\Method\Checkout\ChallengeIndicator; use EMerchantPay\Genesis\Model\Config\Source\Method\Checkout\ScaExemption; use Genesis\Api\Constants\Transaction\Parameters\ScaExemptions; use PHPUnit\Framework\TestCase; /** - * @covers \EMerchantPay\Genesis\Model\Config\Source\Method\Checkout\ScaExemption - * @package Unit\Model\Config\Source\Method\Checkout + * @covers ScaExemption */ class ScaExemptionTest extends TestCase { /** - * @covers \EMerchantPay\Genesis\Model\Config\Source\Method\Checkout\ChallengeIndicator::toOptionArray + * @covers ChallengeIndicator::toOptionArray */ public function testToOptionArray() { - $data = []; - $sourceModel = new ScaExemption(); - - $availableExemptions = [ - ScaExemptions::EXEMPTION_LOW_RISK => 'Low Risk', - ScaExemptions::EXEMPTION_LOW_VALUE => 'Low Value' - ]; + $data = []; + $sourceModel = new ScaExemption(); + $availableExemptions = $sourceModel->exemptions; foreach ($availableExemptions as $value => $label) { - array_push( - $data, - [ - 'value' => $value, - 'label' => __($label) - ] - ); + $data[] = [ + 'value' => $value, + 'label' => __($label) + ]; } $this->assertEquals( diff --git a/Test/Unit/Model/Config/Source/Method/Checkout/TransactionTypeTest.php b/Test/Unit/Model/Config/Source/Method/Checkout/TransactionTypeTest.php index 19d7130..b4c62ec 100755 --- a/Test/Unit/Model/Config/Source/Method/Checkout/TransactionTypeTest.php +++ b/Test/Unit/Model/Config/Source/Method/Checkout/TransactionTypeTest.php @@ -19,54 +19,48 @@ namespace EMerchantPay\Genesis\Test\Unit\Model\Config\Source\Method\Checkout; -use EMerchantPay\Genesis\Helper\Checkout; use EMerchantPay\Genesis\Helper\Data; +use EMerchantPay\Genesis\Model\Config\Source\Method\Checkout\TransactionType; +use EMerchantPay\Genesis\Model\Traits\ExcludedTransactionTypes; +use EMerchantPay\Genesis\Model\Traits\RecurringTransactionTypes; +use Genesis\Api\Constants\Payment\Methods as GenesisPaymentMethods; use Genesis\Api\Constants\Transaction\Names; use Genesis\Api\Constants\Transaction\Parameters\Mobile\ApplePay\PaymentTypes as ApplePaymentTypes; use Genesis\Api\Constants\Transaction\Parameters\Mobile\GooglePay\PaymentTypes as GooglePaymentTypes; use Genesis\Api\Constants\Transaction\Parameters\Wallets\PayPal\PaymentTypes as PayPalPaymentTypes; -use \Genesis\Api\Constants\Transaction\Types as GenesisTransactionTypes; -use \Genesis\Api\Constants\Payment\Methods as GenesisPaymentMethods; +use Genesis\Api\Constants\Transaction\Types as GenesisTransactionTypes; +use PHPUnit\Framework\TestCase; /** + * Test transaction types + * * Class TransactionTypeTest * - * @covers \EMerchantPay\Genesis\Model\Config\Source\Method\Checkout\TransactionType - * @package EMerchantPay\Genesis\Test\Unit\Model\Config\Source\Method\Checkout + * @covers TransactionType */ -class TransactionTypeTest extends \PHPUnit\Framework\TestCase +class TransactionTypeTest extends TestCase { + use ExcludedTransactionTypes; + use RecurringTransactionTypes; /** - * @covers \EMerchantPay\Genesis\Model\Config\Source\Method\Checkout\TransactionType::toOptionArray() + * Test transaction types + * + * @covers TransactionType::toOptionArray() */ public function testToOptionArray() { $data = []; - $sourceModel = new \EMerchantPay\Genesis\Model\Config\Source\Method\Checkout\TransactionType(); + $sourceModel = new TransactionType(); $transactionTypes = GenesisTransactionTypes::getWPFTransactionTypes(); - $excludedTypes = Checkout::getRecurringTransactionTypes(); - - // Exclude PPRO transaction. This is not standalone transaction type - array_push($excludedTypes, GenesisTransactionTypes::PPRO); - // Exclude GooglePay transaction. In this way Google Pay Payment types will be introduced - array_push($excludedTypes, GenesisTransactionTypes::GOOGLE_PAY); - // Exclude PayPal transaction. In this way PayPal Payment types will be introduced - array_push($excludedTypes, GenesisTransactionTypes::PAY_PAL); - // Exclude Apple Pay transaction. - array_push($excludedTypes, GenesisTransactionTypes::APPLE_PAY); + $excludedTypes = array_merge( + $this->getRecurringTransactionTypes(), + $this->getExcludedTransactionTypes() + ); // Exclude Transaction Types $transactionTypes = array_diff($transactionTypes, $excludedTypes); - // Add PPRO types - $pproTypes = array_map( - function ($type) { - return $type . Data::PPRO_TRANSACTION_SUFFIX; - }, - GenesisPaymentMethods::getMethods() - ); - // Add Google Payment types $googlePayTypes = array_map( function ($type) { @@ -103,7 +97,6 @@ function ($type) { $transactionTypes = array_merge( $transactionTypes, - $pproTypes, $googlePayTypes, $payPalTypes, $applePayTypes @@ -116,13 +109,10 @@ function ($type) { $name = strtoupper($type); } - array_push( - $data, - [ - 'value' => $type, - 'label' => __($name) - ] - ); + $data[] = [ + 'value' => $type, + 'label' => __($name) + ]; } $this->assertEquals( @@ -130,4 +120,23 @@ function ($type) { $sourceModel->toOptionArray() ); } + + /** + * Test excluded transaction types are really excluded + */ + public function testExcludedTransactionTypesAreExcluded() + { + $sourceModel = new TransactionType(); + $excludedTypes = $this->getExcludedTransactionTypes(); + + $transactionOptions = $sourceModel->toOptionArray(); + + $transactionTypes = array_map(function ($option) { + return $option['value']; + }, $transactionOptions); + + foreach ($excludedTypes as $excludedType) { + $this->assertNotContains($excludedType, $transactionTypes); + } + } } diff --git a/Test/Unit/Model/Ipn/AbstractIpnTest.php b/Test/Unit/Model/Ipn/AbstractIpnTest.php index f41770f..91dd4a5 100755 --- a/Test/Unit/Model/Ipn/AbstractIpnTest.php +++ b/Test/Unit/Model/Ipn/AbstractIpnTest.php @@ -19,27 +19,35 @@ namespace EMerchantPay\Genesis\Test\Unit\Model\Ipn; +use EMerchantPay\Genesis\Helper\Data as DataHelper; +use EMerchantPay\Genesis\Model\Config; +use EMerchantPay\Genesis\Model\Ipn\AbstractIpn; +use EMerchantPay\Genesis\Model\Ipn\CheckoutIpn; +use EMerchantPay\Genesis\Test\Unit\AbstractTestCase; use Genesis\Api\Constants\Transaction\States; +use Genesis\Api\Constants\Transaction\Types; +use Genesis\Api\Notification as Notification; +use Genesis\Config as GenesisConfig; use Magento\Framework\App\Action\Context; -use Magento\Sales\Model\Order\Status\History; +use Magento\Sales\Api\Data\OrderPaymentInterface; +use Magento\Sales\Model\Order; use Magento\Sales\Model\OrderFactory; -use Magento\Sales\Model\Order\Email\Sender\OrderSender; use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender; +use Magento\Sales\Model\Order\Email\Sender\OrderSender; +use Magento\Sales\Model\Order\Status\History; +use PHPUnit\Framework\MockObject\Rule\InvokedCount; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface as Logger; -use EMerchantPay\Genesis\Helper\Data as DataHelper; -use Magento\Framework\App\Request\Http as HttpRequest; -use Magento\Sales\Model\Order; -use Genesis\Api\Notification as Notification; +use stdClass; /** * Class AbstractIpnTest - * @package EMerchantPay\Genesis\Test\Unit\Model\Ipn */ -abstract class AbstractIpnTest extends \EMerchantPay\Genesis\Test\Unit\AbstractTestCase +abstract class AbstractIpnTest extends AbstractTestCase { /** - * @var \EMerchantPay\Genesis\Model\Ipn\CheckoutIpn + * @var CheckoutIpn */ protected $ipnInstance; @@ -49,7 +57,7 @@ abstract class AbstractIpnTest extends \EMerchantPay\Genesis\Test\Unit\AbstractT protected $postParams; /** - * @var \stdClass $reconciliationObj + * @var stdClass $reconciliationObj */ protected $reconciliationObj; @@ -59,72 +67,77 @@ abstract class AbstractIpnTest extends \EMerchantPay\Genesis\Test\Unit\AbstractT protected $customerPwd; /** - * @var \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject + * @var Context|MockObject */ protected $contextMock; /** - * @var \Magento\Sales\Model\OrderFactory|\PHPUnit_Framework_MockObject_MockObject + * @var OrderFactory|MockObject */ protected $orderFactoryMock; /** - * @var \Magento\Sales\Model\Order\Email\Sender\OrderSender|\PHPUnit_Framework_MockObject_MockObject + * @var OrderSender|MockObject */ protected $orderSenderMock; /** - * @var \Magento\Sales\Model\Order\Email\Sender\CreditmemoSender|\PHPUnit_Framework_MockObject_MockObject + * @var CreditmemoSender|MockObject */ protected $creditmemoSenderMock; /** - * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var Logger|MockObject */ protected $loggerMock; /** - * @var \EMerchantPay\Genesis\Helper\Data|\PHPUnit_Framework_MockObject_MockObject + * @var DataHelper|MockObject */ protected $dataHelperMock; /** - * @var \Genesis\Api\Notification|\PHPUnit_Framework_MockObject_MockObject + * @var Notification|MockObject */ protected $notificationMock; /** - * @var \EMerchantPay\Genesis\Model\Config|\PHPUnit_Framework_MockObject_MockObject + * @var Config|MockObject */ protected $configHelperMock; /** * Gets IPN model class name + * * @return string */ abstract protected function getIpnClassName(); /** * Creates reconciliation object - * @return \stdClass + * + * @return stdClass */ abstract protected function createReconciliationObj(); /** * Get mock for data helper - * @return \EMerchantPay\Genesis\Helper\Data|\PHPUnit_Framework_MockObject_MockObject + * + * @return DataHelper|MockObject */ abstract protected function getDataHelperMock(); /** * Get mock for payment - * @return \Magento\Sales\Api\Data\OrderPaymentInterface|\PHPUnit_Framework_MockObject_MockObject + * + * @return OrderPaymentInterface|MockObject */ abstract protected function getPaymentMock(); /** * Gets IPN model instance - * @return \EMerchantPay\Genesis\Model\Ipn\CheckoutIpn + * + * @return CheckoutIpn */ protected function getIpnInstance() { @@ -133,8 +146,10 @@ protected function getIpnInstance() /** * Creates signature param for the IPN POST request + * * @param string $unique_id * @param string $customerPwd + * * @return string */ protected static function createSignature($unique_id, $customerPwd) @@ -144,7 +159,8 @@ protected static function createSignature($unique_id, $customerPwd) /** * Get mock for context - * @return \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject + * + * @return Context|MockObject */ protected function getContextMock() { @@ -157,13 +173,14 @@ protected function getContextMock() /** * Get mock for order factory - * @return \Magento\Sales\Model\OrderFactory|\PHPUnit_Framework_MockObject_MockObject + * + * @return OrderFactory|MockObject */ protected function getOrderFactoryMock() { $this->orderFactoryMock = $this->getMockBuilder(OrderFactory::class) ->disableOriginalConstructor() - ->setMethods(['create']) + ->onlyMethods(['create']) ->getMock(); $this->orderFactoryMock->expects(self::once()) @@ -175,43 +192,43 @@ protected function getOrderFactoryMock() /** * Get mock for order sender - * @return \Magento\Sales\Model\Order\Email\Sender\OrderSender|\PHPUnit_Framework_MockObject_MockObject + * + * @return OrderSender|MockObject */ protected function getOrderSenderMock() { return $this->orderSenderMock = $this->getMockBuilder(OrderSender::class) ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); } /** - * Get mock for credit memo sedner - * @return \Magento\Sales\Model\Order\Email\Sender\CreditmemoSender|\PHPUnit_Framework_MockObject_MockObject + * Get mock for credit memo sender + * + * @return CreditmemoSender|MockObject */ protected function getCreditmemoSenderMock() { return $this->creditmemoSenderMock = $this->getMockBuilder(CreditmemoSender::class) ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); } /** * Get mock for logger - * @return \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject + * @return Logger|MockObject */ protected function getLoggerMock() { return $this->loggerMock = $this->getMockBuilder(Logger::class) ->disableOriginalConstructor() - ->setMethods([]) ->getMockForAbstractClass(); } /** * Get mock for order - * @return \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject + * + * @return Order|MockObject */ protected function getOrderMock() { @@ -219,7 +236,7 @@ protected function getOrderMock() $orderMock = $this->getMockBuilder(Order::class) ->disableOriginalConstructor() - ->setMethods(['loadByIncrementId','getId','getPayment', 'addStatusHistoryComment']) + ->onlyMethods(['loadByIncrementId','getId','getPayment', 'addCommentToStatusHistory']) ->getMock(); $orderMock->expects(self::atLeastOnce()) @@ -236,7 +253,7 @@ protected function getOrderMock() ->willReturn($orderMock); $orderMock->expects(self::once()) - ->method('addStatusHistoryComment') + ->method('addCommentToStatusHistory') ->willReturn($this->getOrderStatusHistoryMock()); return $orderMock; @@ -245,13 +262,13 @@ protected function getOrderMock() /** * Get Mock for OrderStatusHistory * - * @return \Magento\Sales\Model\Order\Status\History|\PHPUnit\Framework\MockObject\MockObject + * @return History|MockObject */ protected function getOrderStatusHistoryMock() { $statusHistory = $this->getMockBuilder(History::class) ->disableOriginalConstructor() - ->setMethods(['setIsCustomerNotified']) + ->onlyMethods(['setIsCustomerNotified']) ->getMock(); $statusHistory->expects(self::once()) @@ -263,29 +280,32 @@ protected function getOrderStatusHistoryMock() /** * Get notification function name based on transaction type + * * @param string $transaction_type + * * @return string */ protected function getNotificationFunctionName($transaction_type) { $result=null; switch ($transaction_type) { - case \Genesis\Api\Constants\Transaction\Types::AUTHORIZE: - case \Genesis\Api\Constants\Transaction\Types::AUTHORIZE_3D: + case Types::AUTHORIZE: + case Types::AUTHORIZE_3D: $result = 'registerAuthorizationNotification'; break; - case \Genesis\Api\Constants\Transaction\Types::SALE: - case \Genesis\Api\Constants\Transaction\Types::SALE_3D: + case Types::SALE: + case Types::SALE_3D: $result = 'registerCaptureNotification'; break; default: break; } + return $result; } /** - * @param \stdClass $responseObject + * @param stdClass $responseObject * @return bool */ protected function getShouldSetCurrentTranPending($responseObject) @@ -298,7 +318,7 @@ protected function getShouldSetCurrentTranPending($responseObject) * * @param $status * - * @return \PHPUnit\Framework\MockObject\Matcher\InvokedCount + * @return InvokedCount */ protected function getShouldExecuteAuthoirizeCaptureEvent($status) { @@ -310,14 +330,15 @@ protected function getShouldExecuteAuthoirizeCaptureEvent($status) } /** - * @param \stdClass $responseObject + * @param stdClass $responseObject + * * @return bool */ protected function getShouldCloseCurrentTransaction($responseObject) { $voidableTransactions = [ - \Genesis\Api\Constants\Transaction\Types::AUTHORIZE, - \Genesis\Api\Constants\Transaction\Types::AUTHORIZE_3D + Types::AUTHORIZE, + Types::AUTHORIZE_3D ]; return !in_array($responseObject->transaction_type, $voidableTransactions); @@ -328,14 +349,15 @@ protected function getShouldCloseCurrentTransaction($responseObject) */ protected function initGatewayClientMock() { - \Genesis\Config::setPassword( + GenesisConfig::setPassword( $this->customerPwd ); } /** * Get mock for notification - * @return \Genesis\Api\Notification|\PHPUnit_Framework_MockObject_MockObject + * + * @return Notification|MockObject */ protected function getNotificationMock() { @@ -359,7 +381,7 @@ protected function getNotificationMock() $this->notificationMock->expects(self::once()) ->method('initReconciliation') - ->willReturn(new \stdClass()); + ->willReturn(new stdClass()); $this->notificationMock->expects(self::once()) ->method('getReconciliationObject') @@ -370,13 +392,20 @@ protected function getNotificationMock() /** * Get mock for model config - * @return \EMerchantPay\Genesis\Model\Config|\PHPUnit_Framework_MockObject_MockObject + * + * @return Config|MockObject */ protected function getConfigHelperMock() { $this->configHelperMock = $this->getMockBuilder('EMerchantPay\Genesis\Model\Config') ->disableOriginalConstructor() - ->setMethods(['initGatewayClient', 'initReconciliation', 'getCheckoutTitle']) + ->onlyMethods( + [ + 'initGatewayClient', + 'getCheckoutTitle' + ] + ) + ->addMethods(['initReconciliation']) ->getMock(); $this->configHelperMock->expects(self::once()) @@ -413,7 +442,7 @@ protected function setUp(): void } /** - * @covers \EMerchantPay\Genesis\Model\Ipn\AbstractIpn::handleGenesisNotification() + * @covers AbstractIpn::handleGenesisNotification() */ public function testGenesisNotification() { @@ -422,6 +451,7 @@ public function testGenesisNotification() /** * Creates constructor parameters + * * @return array */ public function createParams() diff --git a/Test/Unit/Model/Ipn/CheckoutIpnAuthRefundTest.php b/Test/Unit/Model/Ipn/CheckoutIpnAuthRefundTest.php index c713761..1cf2e7f 100644 --- a/Test/Unit/Model/Ipn/CheckoutIpnAuthRefundTest.php +++ b/Test/Unit/Model/Ipn/CheckoutIpnAuthRefundTest.php @@ -20,29 +20,30 @@ namespace EMerchantPay\Genesis\Test\Unit\Model\Ipn; use EMerchantPay\Genesis\Model\Ipn\CheckoutIpn; -use EMerchantPay\Genesis\Helper\Data as DataHelper; -use Magento\Framework\App\Request\Http as HttpRequest; -use Magento\Sales\Api\Data\OrderPaymentInterface; +use Genesis\Api\Constants\Transaction\States; +use Genesis\Api\Constants\Transaction\Types; +use stdClass; /** * Class CheckoutIpnRefundedTest - * @covers \EMerchantPay\Genesis\Model\Ipn\Checkout - * @package EMerchantPay\Genesis\Test\Unit\Model\Ipn + * + * @covers CheckoutIpn */ -class CheckoutIpnAuthRefundTest extends \EMerchantPay\Genesis\Test\Unit\Model\Ipn\CheckoutIpnTest +class CheckoutIpnAuthRefundTest extends CheckoutIpnTest { - const RECONCILIATION_TRANSACTION_TYPE = \Genesis\Api\Constants\Transaction\Types::AUTHORIZE; + public const RECONCILIATION_TRANSACTION_TYPE = Types::AUTHORIZE; /** * Creates reconciliation object - * @return \stdClass + * + * @return stdClass */ protected function createReconciliationObj() { $this->reconciliationObj = parent::createReconciliationObj(); - $this->reconciliationObj->status = \Genesis\Api\Constants\Transaction\States::REFUNDED; + $this->reconciliationObj->status = States::REFUNDED; $this->reconciliationObj->transaction_type = self::RECONCILIATION_TRANSACTION_TYPE; return $this->reconciliationObj; diff --git a/Test/Unit/Model/Ipn/CheckoutIpnAuthVoidTest.php b/Test/Unit/Model/Ipn/CheckoutIpnAuthVoidTest.php index ed32e6d..aaab1e4 100644 --- a/Test/Unit/Model/Ipn/CheckoutIpnAuthVoidTest.php +++ b/Test/Unit/Model/Ipn/CheckoutIpnAuthVoidTest.php @@ -20,29 +20,30 @@ namespace EMerchantPay\Genesis\Test\Unit\Model\Ipn; use EMerchantPay\Genesis\Model\Ipn\CheckoutIpn; -use EMerchantPay\Genesis\Helper\Data as DataHelper; -use Magento\Framework\App\Request\Http as HttpRequest; -use Magento\Sales\Api\Data\OrderPaymentInterface; +use Genesis\Api\Constants\Transaction\States; +use Genesis\Api\Constants\Transaction\Types; +use stdClass; /** * Class CheckoutIpnRefundedTest - * @covers \EMerchantPay\Genesis\Model\Ipn\Checkout - * @package EMerchantPay\Genesis\Test\Unit\Model\Ipn + * + * @covers CheckoutIpn */ -class CheckoutIpnAuthVoidTest extends \EMerchantPay\Genesis\Test\Unit\Model\Ipn\CheckoutIpnTest +class CheckoutIpnAuthVoidTest extends CheckoutIpnTest { - const RECONCILIATION_TRANSACTION_TYPE = \Genesis\Api\Constants\Transaction\Types::AUTHORIZE; + public const RECONCILIATION_TRANSACTION_TYPE = Types::AUTHORIZE; /** * Creates reconciliation object - * @return \stdClass + * + * @return stdClass */ protected function createReconciliationObj() { $this->reconciliationObj = parent::createReconciliationObj(); - $this->reconciliationObj->status = \Genesis\Api\Constants\Transaction\States::VOIDED; + $this->reconciliationObj->status = States::VOIDED; $this->reconciliationObj->transaction_type = self::RECONCILIATION_TRANSACTION_TYPE; return $this->reconciliationObj; diff --git a/Test/Unit/Model/Ipn/CheckoutIpnSaleRefundTest.php b/Test/Unit/Model/Ipn/CheckoutIpnSaleRefundTest.php index 7d4c365..c9b1940 100644 --- a/Test/Unit/Model/Ipn/CheckoutIpnSaleRefundTest.php +++ b/Test/Unit/Model/Ipn/CheckoutIpnSaleRefundTest.php @@ -20,29 +20,30 @@ namespace EMerchantPay\Genesis\Test\Unit\Model\Ipn; use EMerchantPay\Genesis\Model\Ipn\CheckoutIpn; -use EMerchantPay\Genesis\Helper\Data as DataHelper; -use Magento\Framework\App\Request\Http as HttpRequest; -use Magento\Sales\Api\Data\OrderPaymentInterface; +use Genesis\Api\Constants\Transaction\States; +use Genesis\Api\Constants\Transaction\Types; +use stdClass; /** * Class CheckoutIpnRefundedTest - * @covers \EMerchantPay\Genesis\Model\Ipn\Checkout - * @package EMerchantPay\Genesis\Test\Unit\Model\Ipn + * + * @covers CheckoutIpn */ -class CheckoutIpnSaleRefundTest extends \EMerchantPay\Genesis\Test\Unit\Model\Ipn\CheckoutIpnTest +class CheckoutIpnSaleRefundTest extends CheckoutIpnTest { - const RECONCILIATION_TRANSACTION_TYPE = \Genesis\Api\Constants\Transaction\Types::SALE; + public const RECONCILIATION_TRANSACTION_TYPE = Types::SALE; /** * Creates reconciliation object - * @return \stdClass + * + * @return stdClass */ protected function createReconciliationObj() { $this->reconciliationObj = parent::createReconciliationObj(); - $this->reconciliationObj->status = \Genesis\Api\Constants\Transaction\States::REFUNDED; + $this->reconciliationObj->status = States::REFUNDED; $this->reconciliationObj->transaction_type = self::RECONCILIATION_TRANSACTION_TYPE; return $this->reconciliationObj; diff --git a/Test/Unit/Model/Ipn/CheckoutIpnSaleVoidTest.php b/Test/Unit/Model/Ipn/CheckoutIpnSaleVoidTest.php index 5ec71b6..edbf1f3 100644 --- a/Test/Unit/Model/Ipn/CheckoutIpnSaleVoidTest.php +++ b/Test/Unit/Model/Ipn/CheckoutIpnSaleVoidTest.php @@ -20,29 +20,29 @@ namespace EMerchantPay\Genesis\Test\Unit\Model\Ipn; use EMerchantPay\Genesis\Model\Ipn\CheckoutIpn; -use EMerchantPay\Genesis\Helper\Data as DataHelper; -use Magento\Framework\App\Request\Http as HttpRequest; -use Magento\Sales\Api\Data\OrderPaymentInterface; +use Genesis\Api\Constants\Transaction\States; +use Genesis\Api\Constants\Transaction\Types; +use stdClass; /** * Class CheckoutIpnRefundedTest - * @covers \EMerchantPay\Genesis\Model\Ipn\Checkout - * @package EMerchantPay\Genesis\Test\Unit\Model\Ipn + * @covers CheckoutIpn */ -class CheckoutIpnSaleVoidTest extends \EMerchantPay\Genesis\Test\Unit\Model\Ipn\CheckoutIpnTest +class CheckoutIpnSaleVoidTest extends CheckoutIpnTest { - const RECONCILIATION_TRANSACTION_TYPE = \Genesis\Api\Constants\Transaction\Types::SALE; + public const RECONCILIATION_TRANSACTION_TYPE = Types::SALE; /** * Creates reconciliation object - * @return \stdClass + * + * @return stdClass */ protected function createReconciliationObj() { $this->reconciliationObj = parent::createReconciliationObj(); - $this->reconciliationObj->status = \Genesis\Api\Constants\Transaction\States::VOIDED; + $this->reconciliationObj->status = States::VOIDED; $this->reconciliationObj->transaction_type = self::RECONCILIATION_TRANSACTION_TYPE; return $this->reconciliationObj; diff --git a/Test/Unit/Model/Ipn/CheckoutIpnTest.php b/Test/Unit/Model/Ipn/CheckoutIpnTest.php index ed2bd0b..e0863e3 100755 --- a/Test/Unit/Model/Ipn/CheckoutIpnTest.php +++ b/Test/Unit/Model/Ipn/CheckoutIpnTest.php @@ -19,28 +19,36 @@ namespace EMerchantPay\Genesis\Test\Unit\Model\Ipn; -use EMerchantPay\Genesis\Model\Ipn\CheckoutIpn; use EMerchantPay\Genesis\Helper\Data as DataHelper; -use Magento\Framework\App\Request\Http as HttpRequest; +use EMerchantPay\Genesis\Model\Ipn\CheckoutIpn; +use EMerchantPay\Genesis\Model\Method\Checkout; +use Genesis\Api\Constants\Transaction\States; +use Genesis\Api\Constants\Transaction\Types; +use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Api\Data\OrderPaymentInterface; +use PHPUnit\Framework\MockObject\MockObject; +use stdClass; +use Magento\Sales\Api\OrderRepositoryInterface; /** + * Test Checkout notification + * * Class CheckoutIpnTest - * @covers \EMerchantPay\Genesis\Model\Ipn\Checkout - * @package EMerchantPay\Genesis\Test\Unit\Model\Ipn + * + * @covers CheckoutIpn */ -class CheckoutIpnTest extends \EMerchantPay\Genesis\Test\Unit\Model\Ipn\AbstractIpnTest +class CheckoutIpnTest extends AbstractIpnTest { - const UNIQUE_ID_NAME = 'wpf_unique_id'; + private const UNIQUE_ID_NAME = 'wpf_unique_id'; - const TRANSACTION_ID = '12345678901234567890123456789012'; - const CUSTOMER_PWD = '1234567890123456789012345678901234567890'; + private const TRANSACTION_ID = '12345678901234567890123456789012'; + private const CUSTOMER_PWD = '1234567890123456789012345678901234567890'; - const RECONCILIATION_TRANSACTION_ID = '123-456'; - const RECONCILIATION_TRANSACTION_TYPE = \Genesis\Api\Constants\Transaction\Types::AUTHORIZE; - const RECONCILIATION_MESSAGE = 'sample reconciliation message'; - const RECONCILIATION_AMOUNT = 271.97; + private const RECONCILIATION_TRANSACTION_ID = '123-456'; + private const RECONCILIATION_TRANSACTION_TYPE = Types::AUTHORIZE; + private const RECONCILIATION_MESSAGE = 'sample reconciliation message'; + private const RECONCILIATION_AMOUNT = 271.97; /** * @var customerPwd @@ -49,6 +57,7 @@ class CheckoutIpnTest extends \EMerchantPay\Genesis\Test\Unit\Model\Ipn\Abstract /** * Gets IPN model class name + * * @return string */ protected function getIpnClassName() @@ -72,9 +81,9 @@ protected function setUp(): void protected function setPostParams() { $transactionId = self::TRANSACTION_ID; - $customerPwd = self::CUSTOMER_PWD; + $customerPwd = self::CUSTOMER_PWD; - $signature = self::createSignature($transactionId, $customerPwd); + $signature = self::createSignature($transactionId, $customerPwd); $this->postParams = [ self::UNIQUE_ID_NAME => $transactionId, @@ -85,14 +94,15 @@ protected function setPostParams() /** * Creates reconciliation object - * @return \stdClass + * + * @return stdClass */ protected function createReconciliationObj() { - $this->reconciliationObj = new \stdClass(); + $this->reconciliationObj = new stdClass(); $this->reconciliationObj->unique_id = $this->postParams[self::UNIQUE_ID_NAME]; $this->reconciliationObj->transaction_id = self::RECONCILIATION_TRANSACTION_ID; - $this->reconciliationObj->status = \Genesis\Api\Constants\Transaction\States::APPROVED; + $this->reconciliationObj->status = States::APPROVED; $this->reconciliationObj->message = __('Module') . ' ' . self::RECONCILIATION_MESSAGE; $this->reconciliationObj->transaction_type = self::RECONCILIATION_TRANSACTION_TYPE; $this->reconciliationObj->amount = self::RECONCILIATION_AMOUNT; @@ -103,13 +113,14 @@ protected function createReconciliationObj() /** * Get mock for data helper - * @return \EMerchantPay\Genesis\Helper\Data|\PHPUnit_Framework_MockObject_MockObject + * + * @return DataHelper|MockObject */ protected function getDataHelperMock() { $this->dataHelperMock = $this->getMockBuilder(DataHelper::class) ->disableOriginalConstructor() - ->setMethods( + ->onlyMethods( [ 'getMethodConfig', 'createNotificationObject', @@ -121,7 +132,7 @@ protected function getDataHelperMock() $this->dataHelperMock->expects(self::once()) ->method('getMethodConfig') - ->with(\EMerchantPay\Genesis\Model\Method\Checkout::CODE) + ->with(Checkout::CODE) ->willReturn( $this->configHelperMock ); @@ -136,28 +147,34 @@ protected function getDataHelperMock() /** * Get mock for payment - * @return \Magento\Sales\Api\Data\OrderPaymentInterface|\PHPUnit_Framework_MockObject_MockObject + * + * @return OrderPaymentInterface|MockObject */ protected function getPaymentMock() { $paymentMock = $this->getMockBuilder(OrderPaymentInterface::class) ->disableOriginalConstructor() - ->setMethods([ - 'setLastTransId', - 'setTransactionId', - 'setParentTransactionId', - 'setShouldCloseParentTransaction', - 'setIsTransactionPending', - 'setIsTransactionClosed', - 'setPreparedMessage', - 'resetTransactionAdditionalInfo', - 'setTransactionAdditionalInfo', - 'registerAuthorizationNotification', - 'registerCaptureNotification', - 'save' - ]) + ->onlyMethods(['setLastTransId']) + ->addMethods( + [ + 'getOrder', + 'setTransactionId', + 'setParentTransactionId', + 'setShouldCloseParentTransaction', + 'setIsTransactionPending', + 'setIsTransactionClosed', + 'setPreparedMessage', + 'resetTransactionAdditionalInfo', + 'setTransactionAdditionalInfo', + 'registerAuthorizationNotification', + 'registerCaptureNotification', + ] + ) ->getMockForAbstractClass(); + $orderMock = $this->createMock(OrderInterface::class); + $paymentMock->method('getOrder')->willReturn($orderMock); + $paymentMock->expects(self::once()) ->method('setLastTransId') ->with($this->reconciliationObj->unique_id) diff --git a/Test/Unit/Model/Method/AbstractMethodTest.php b/Test/Unit/Model/Method/AbstractMethodTest.php index a5b92d1..03314fa 100644 --- a/Test/Unit/Model/Method/AbstractMethodTest.php +++ b/Test/Unit/Model/Method/AbstractMethodTest.php @@ -19,28 +19,45 @@ namespace EMerchantPay\Genesis\Test\Unit\Model\Method; +use EMerchantPay\Genesis\Helper\Data; +use EMerchantPay\Genesis\Logger\Logger; +use EMerchantPay\Genesis\Model\Config; +use EMerchantPay\Genesis\Model\Method\Checkout; +use EMerchantPay\Genesis\Test\Unit\AbstractTestCase; +use Faker\Factory; +use Faker\Generator; +use Faker\Provider\Internet; +use Faker\Provider\Payment; +use Faker\Provider\en_US\Address; +use Faker\Provider\en_US\Person; +use Faker\Provider\en_US\PhoneNumber; +use Magento\Checkout\Model\Session; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Payment\Model\InfoInterface; +use Magento\Sales\Api\OrderPaymentRepositoryInterface; use Magento\Sales\Model\Order; -use EMerchantPay\Genesis\Helper\Data as EMerchantPayDataHelper; -use Genesis\Api\Constants\Transaction\Types as GenesisTransactionTypes; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; +use ReflectionClass; +use ReflectionException; /** * Base Test Method Class for Payment Method Models * * Class AbstractMethodTest - * @package EMerchantPay\Genesis\Test\Unit\Model\Method */ -abstract class AbstractMethodTest extends \EMerchantPay\Genesis\Test\Unit\AbstractTestCase +abstract class AbstractMethodTest extends AbstractTestCase { - const ORDER_AMOUNT = 1.05; + public const ORDER_AMOUNT = 1.05; - const CREDIT_CARD_VISA = '4200000000000000'; + public const CREDIT_CARD_VISA = '4200000000000000'; - const API_LOGIN = 'api_login-23e9b38424f6b1688aed91495fa4601a'; - const API_PASSWORD = 'api_password-0631a4be134a6d344bec9a99ac6954d4'; - const API_TOKEN = 'api_token-c7dd1174bab427d2333b66b12a8ed703'; + public const API_LOGIN = 'api_login-23e9b38424f6b1688aed91495fa4601a'; + public const API_PASSWORD = 'api_password-0631a4be134a6d344bec9a99ac6954d4'; + public const API_TOKEN = 'api_token-c7dd1174bab427d2333b66b12a8ed703'; /** - * @var \EMerchantPay\Genesis\Model\Method\Checkout + * @var Checkout */ protected $paymentMethodInstance; @@ -49,47 +66,52 @@ abstract class AbstractMethodTest extends \EMerchantPay\Genesis\Test\Unit\Abstra */ protected $paymentMethodCode = null; /** - * @var \ReflectionClass + * @var ReflectionClass */ protected $paymentMethodReflection; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject + * @var ScopeConfigInterface|MockObject */ protected $scopeConfigMock; /** - * @var \Magento\Payment\Model\InfoInterface|\PHPUnit_Framework_MockObject_MockObject + * @var InfoInterface|MockObject */ protected $paymentMock; /** - * @var \EMerchantPay\Genesis\Helper\Data|\PHPUnit_Framework_MockObject_MockObject + * @var Data|MockObject */ protected $dataHelperMock; /** - * @var \EMerchantPay\Genesis\Model\Config|\PHPUnit_Framework_MockObject_MockObject + * @var Config|MockObject */ protected $configHelperMock; /** - * @var \Magento\Checkout\Model\Session|\PHPUnit_Framework_MockObject_MockObject + * @var Session|MockObject */ protected $checkoutSessionMock; /** - * @var \EMerchantPay\Genesis\Logger\Logger|\PHPUnit_Framework_MockObject_MockObject + * @var Logger|MockObject */ protected $loggerHelperMock; /** - * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var LoggerInterface|MockObject */ protected $psrLoggerMock; /** - * @return \EMerchantPay\Genesis\Model\Method\Checkout + * @var (OrderPaymentRepositoryInterface&MockObject)|MockObject + */ + protected $paymentRepositoryMock; + + /** + * @return Checkout */ protected function getPaymentMethodInstance() { @@ -97,7 +119,7 @@ protected function getPaymentMethodInstance() } /** - * @return \ReflectionClass + * @return ReflectionClass */ protected function getPaymentMethodReflection() { @@ -116,17 +138,28 @@ protected function getPaymentMethodCode() return $this->paymentMethodCode; } + /** + * @return mixed + */ abstract protected function getPaymentMethodClassName(); + /** + * @return void + * + * @throws ReflectionException + */ protected function init() { parent::init(); - $this->paymentMethodReflection = new \ReflectionClass( + $this->paymentMethodReflection = new ReflectionClass( $this->getPaymentMethodClassName() ); } + /** + * @return int + */ protected function getGeneratedOrderId() { return $this->getFakerObject()->randomNumber(8); @@ -139,55 +172,45 @@ protected function setUp(): void { parent::setUp(); - $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class) + $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) ->getMock(); - $this->paymentMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Payment::class) + $this->paymentMock = $this->getMockBuilder(Order\Payment::class) ->disableOriginalConstructor() - ->setMethods([ - 'getOrder', 'getId', 'setAdditionalInformation', 'getAdditionalInformation', - 'setIsTransactionDenied', 'setIsTransactionClosed', 'decrypt', 'getCcLast4', - 'getParentTransactionId', 'getPoNumber', 'setIsTransactionPending', 'setTransactionAdditionalInfo', - 'getCcNumber', 'getCcExpYear', 'getCcExpMonth', 'getCcCid', 'getCcOwner', - 'setTransactionId', 'addData' + ->onlyMethods([ + 'addData', 'decrypt', 'getAdditionalInformation', 'getCcExpMonth', 'getCcExpYear', 'getCcLast4', + 'getCcOwner', 'getId', 'getOrder', 'getParentTransactionId', 'getPoNumber', 'setAdditionalInformation', + 'setIsTransactionClosed', 'setIsTransactionPending', 'setTransactionAdditionalInfo', 'setTransactionId', ]) + ->addMethods(['setIsTransactionDenied', 'getCcNumber', 'getCcCid']) ->getMock(); - $this->dataHelperMock = $this->getMockBuilder(\EMerchantPay\Genesis\Helper\Data::class) + $this->dataHelperMock = $this->getMockBuilder(Data::class) ->disableOriginalConstructor() - ->setMethods( + ->onlyMethods( [ - 'getMethodConfig', - 'getNotificationUrl', - 'getReturnUrl', - 'genTransactionId', - 'buildOrderUsage', - 'buildOrderDescriptionText', - 'getLocale', - 'executeGatewayRequest', - 'getGatewayResponseObject', + 'buildOrderDescriptionText', 'buildOrderUsage', 'executeGatewayRequest', 'genTransactionId', + 'getGatewayResponseObject', 'getLocale', 'getMethodConfig', 'getNotificationUrl', 'getReturnUrl', + 'lookUpAuthorizationTransaction', 'lookUpCaptureTransaction', 'lookUpVoidReferenceTransaction', 'maskException', - 'lookUpAuthorizationTransaction', - 'lookUpCaptureTransaction', - 'lookUpVoidReferenceTransaction' ] ) ->getMock(); $this->configHelperMock = $this->getMockBuilder('EMerchantPay\Genesis\Model\Config') ->disableOriginalConstructor() - ->setMethods(['getMethodCode', 'initGatewayClient', 'getScopeConfig']) + ->onlyMethods(['getMethodCode', 'initGatewayClient', 'getScopeConfig']) ->getMock(); $this->configHelperMock->expects(self::any()) ->method('initGatewayClient') ->willReturn(null); - $this->checkoutSessionMock = $this->getMockBuilder(\Magento\Checkout\Model\Session::class) + $this->checkoutSessionMock = $this->getMockBuilder(Session::class) ->disableOriginalConstructor() - ->setMethods( + ->onlyMethods(['getQuote']) + ->addMethods( [ - 'getQuote', 'setEmerchantPayLastCheckoutError', 'setEmerchantPayCheckoutRedirectUrl', 'getEmerchantPayLastCheckoutError', @@ -210,13 +233,17 @@ protected function setUp(): void $this->setupLoggerMocks(); + $this->paymentRepositoryMock = $this->getMockBuilder(OrderPaymentRepositoryInterface::class) + ->getMock(); + $this->paymentMethodInstance = $this->getObjectManagerHelper()->getObject( $this->getPaymentMethodClassName(), [ - 'scopeConfig' => $this->scopeConfigMock, - 'moduleHelper' => $this->dataHelperMock, - 'checkoutSession' => $this->checkoutSessionMock, - 'loggerHelper' => $this->loggerHelperMock + 'scopeConfig' => $this->scopeConfigMock, + 'moduleHelper' => $this->dataHelperMock, + 'checkoutSession' => $this->checkoutSessionMock, + 'loggerHelper' => $this->loggerHelperMock, + 'paymentRepository' => $this->paymentRepositoryMock ] ); @@ -255,14 +282,17 @@ protected function setUp(): void ); } + /** + * @return void + */ protected function setupLoggerMocks() { $this->loggerHelperMock = $this->getMockBuilder( - \EMerchantPay\Genesis\Logger\Logger::class + Logger::class )->getMock(); $this->psrLoggerMock = $this->getMockBuilder( - \Psr\Log\LoggerInterface::class + LoggerInterface::class )->getMock(); $this->loggerHelperMock @@ -274,13 +304,14 @@ protected function setupLoggerMocks() /** * Get mock for order - * @return \PHPUnit_Framework_MockObject_MockObject + * + * @return MockObject */ protected function getOrderMock() { $orderMock = $this->getMockBuilder(Order::class) ->disableOriginalConstructor() - ->setMethods( + ->onlyMethods( [ 'getId', 'getIncrementId', @@ -301,7 +332,7 @@ protected function getOrderMock() /** * Get Mock for Order Address * - * @return \PHPUnit_Framework_MockObject_MockObject + * @return MockObject */ protected function getOrderAddressMock() { @@ -346,16 +377,16 @@ protected function getOrderAddressMock() /** * Builds a Faker Object * - * @return \Faker\Generator + * @return Generator */ protected function getFakerObject() { - $faker = \Faker\Factory::create(); - $faker->addProvider(new \Faker\Provider\en_US\Person($faker)); - $faker->addProvider(new \Faker\Provider\Payment($faker)); - $faker->addProvider(new \Faker\Provider\en_US\Address($faker)); - $faker->addProvider(new \Faker\Provider\en_US\PhoneNumber($faker)); - $faker->addProvider(new \Faker\Provider\Internet($faker)); + $faker = Factory::create(); + $faker->addProvider(new Person($faker)); + $faker->addProvider(new Payment($faker)); + $faker->addProvider(new Address($faker)); + $faker->addProvider(new PhoneNumber($faker)); + $faker->addProvider(new Internet($faker)); return $faker; } diff --git a/Test/Unit/Model/Method/CheckoutTest.php b/Test/Unit/Model/Method/CheckoutTest.php index d43b6db..4d5cb64 100644 --- a/Test/Unit/Model/Method/CheckoutTest.php +++ b/Test/Unit/Model/Method/CheckoutTest.php @@ -21,16 +21,22 @@ use EMerchantPay\Genesis\Helper\Data; use EMerchantPay\Genesis\Model\Method\Checkout as CheckoutPaymentMethod; -use Genesis\Api\Constants\Payment\Methods; -use Genesis\Api\Constants\Payment\Methods as GenesisPaymentMethods; +use Genesis\Api\Constants\Transaction\States; use Genesis\Api\Constants\Transaction\Types as GenesisTransactionTypes; +use Genesis\Genesis; +use Magento\Payment\Model\MethodInterface; +use Magento\Quote\Model\Quote; +use Magento\Sales\Model\Order\Payment\Transaction; +use PHPUnit\Framework\MockObject\MockObject; /** + * Test Checkout functionality + * * Class CheckoutTest - * @covers \EMerchantPay\Genesis\Model\Method\Checkout - * @package EMerchantPay\Genesis\Test\Unit\Model\Method + * + * @covers CheckoutPaymentMethod */ -class CheckoutTest extends \EMerchantPay\Genesis\Test\Unit\Model\Method\AbstractMethodTest +class CheckoutTest extends AbstractMethodTest { protected function getPaymentMethodClassName() { @@ -43,7 +49,7 @@ protected function getPaymentMethodClassName() public function testGetConfigPaymentAction() { $this->assertEquals( - \Magento\Payment\Model\Method\AbstractMethod::ACTION_ORDER, + MethodInterface::ACTION_ORDER, $this->getPaymentMethodInstance()->getConfigPaymentAction() ); } @@ -79,12 +85,6 @@ public function testGetCheckoutTransactionTypes() GenesisTransactionTypes::WEBMONEY, GenesisTransactionTypes::PAYSAFECARD, GenesisTransactionTypes::SOFORT, - Methods::EPS . Data::PPRO_TRANSACTION_SUFFIX, - Methods::PRZELEWY24 . Data::PPRO_TRANSACTION_SUFFIX, - Methods::SAFETY_PAY . Data::PPRO_TRANSACTION_SUFFIX, - Methods::BCMC . Data::PPRO_TRANSACTION_SUFFIX, - Methods::MYBANK . Data::PPRO_TRANSACTION_SUFFIX, - Methods::IDEAL . Data::PPRO_TRANSACTION_SUFFIX ] ) ); @@ -108,29 +108,6 @@ public function testGetCheckoutTransactionTypes() GenesisTransactionTypes::PAYSAFECARD, GenesisTransactionTypes::POLI, GenesisTransactionTypes::SDD_SALE, - GenesisTransactionTypes::PPRO => [ - 'name' => GenesisTransactionTypes::PPRO, - 'parameters' => [ - [ - 'payment_method' => GenesisPaymentMethods::BCMC, - ], - [ - 'payment_method' => GenesisPaymentMethods::EPS - ], - [ - 'payment_method' => GenesisPaymentMethods::IDEAL, - ], - [ - 'payment_method' => GenesisPaymentMethods::MYBANK, - ], - [ - 'payment_method' => GenesisPaymentMethods::PRZELEWY24, - ], - [ - 'payment_method' => GenesisPaymentMethods::SAFETY_PAY, - ] - ] - ], GenesisTransactionTypes::SOFORT, GenesisTransactionTypes::TRUSTLY_SALE, GenesisTransactionTypes::WEBMONEY, @@ -191,11 +168,11 @@ public function testSuccessfulOrder() ->willReturn('en'); /** - * @var $quote \Magento\Quote\Model\Quote|\PHPUnit_Framework_MockObject_MockObject + * @var $quote Quote|MockObject */ - $quote = $this->getMockBuilder(\Magento\Quote\Model\Quote::class) + $quote = $this->getMockBuilder(Quote::class) ->disableOriginalConstructor() - ->setMethods(['getCustomerEmail']) + ->addMethods(['getCustomerEmail']) ->getMock(); $quote->expects(self::once()) @@ -238,15 +215,15 @@ public function testSuccessfulOrder() ->withConsecutive( [ $this->getPaymentMethodInstance()->getCode(), - \EMerchantPay\Genesis\Helper\Data::ACTION_RETURN_SUCCESS + Data::ACTION_RETURN_SUCCESS ], [ $this->getPaymentMethodInstance()->getCode(), - \EMerchantPay\Genesis\Helper\Data::ACTION_RETURN_CANCEL + Data::ACTION_RETURN_CANCEL ], [ $this->getPaymentMethodInstance()->getCode(), - \EMerchantPay\Genesis\Helper\Data::ACTION_RETURN_FAILURE + Data::ACTION_RETURN_FAILURE ] ) ->willReturnOnConsecutiveCalls( @@ -256,7 +233,7 @@ public function testSuccessfulOrder() ); $gatewayResponse = $this->getSampleGatewayResponse( - \Genesis\Api\Constants\Transaction\States::NEW_STATUS, + States::NEW_STATUS, null, null, null, @@ -274,7 +251,7 @@ public function testSuccessfulOrder() $this->dataHelperMock->expects(self::once()) ->method('executeGatewayRequest') ->with( - $this->isInstanceOf(\Genesis\Genesis::class) + $this->isInstanceOf(Genesis::class) ) ->willReturnArgument(0); @@ -298,7 +275,7 @@ public function testSuccessfulOrder() $this->paymentMock->expects(self::once()) ->method('setTransactionAdditionalInfo') ->with( - \Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS, + Transaction::RAW_DETAILS, $this->dataHelperMock->getArrayFromGatewayResponse( $gatewayResponse ) @@ -322,6 +299,7 @@ public function testSuccessfulOrder() * Scope Config Method Settings values * * @param ...$args + * * @return string */ public function configCallback(...$args) diff --git a/Test/Unit/Model/Observer/AbstractObserverTest.php b/Test/Unit/Model/Observer/AbstractObserverTest.php index 274b9bc..2e77fb8 100755 --- a/Test/Unit/Model/Observer/AbstractObserverTest.php +++ b/Test/Unit/Model/Observer/AbstractObserverTest.php @@ -21,7 +21,9 @@ use EMerchantPay\Genesis\Helper\Data as DataHelper; use EMerchantPay\Genesis\Model\Config; +use EMerchantPay\Genesis\Model\Observer\ControllerFrontSendResponseBefore; use EMerchantPay\Genesis\Model\Observer\SalesOrderBeforeSaveObserver; +use EMerchantPay\Genesis\Test\Unit\AbstractTestCase; use Magento\Checkout\Model\Session; use Magento\Framework\Event; use Magento\Framework\Event\Observer; @@ -31,67 +33,70 @@ use Magento\Payment\Model\Method\InstanceFactory; use Magento\Sales\Api\Data\OrderPaymentInterface; use Magento\Sales\Model\Order; -use Magento\Sales\Model\Order\Email\Sender\OrderSender; use Magento\Sales\Model\OrderFactory; +use Magento\Sales\Model\Order\Email\Sender\OrderSender; +use PHPUnit\Framework\MockObject\MockObject; +use stdClass; /** * Class AbstractObserverTest - * @package EMerchantPay\Genesis\Test\Unit\Model\Observer + * + * @SuppressWarnings(PHPMD.TooManyFields) */ -abstract class AbstractObserverTest extends \EMerchantPay\Genesis\Test\Unit\AbstractTestCase +abstract class AbstractObserverTest extends AbstractTestCase { /** - * @var \EMerchantPay\Genesis\Model\Observer\ControllerFrontSendResponseBefore|\PHPUnit_Framework_MockObject_MockObject + * @var ControllerFrontSendResponseBefore|MockObject */ protected $observerInstance; /** - * @var \EMerchantPay\Genesis\Helper\Data|\PHPUnit_Framework_MockObject_MockObject + * @var DataHelper|MockObject */ protected $dataHelperMock; /** - * @var \Magento\Framework\Webapi\ErrorProcessor|\PHPUnit_Framework_MockObject_MockObject + * @var ErrorProcessor|MockObject */ protected $errorProcessorMock; /** - * @var \Magento\Checkout\Model\Session|\PHPUnit_Framework_MockObject_MockObject + * @var Session|MockObject */ protected $checkoutSessionMock; /** - * @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject + * @var Observer|MockObject */ protected $observerMock; /** - * @var \Magento\Framework\Event|\PHPUnit_Framework_MockObject_MockObject + * @var Event|MockObject */ protected $eventMock; /** - * @var \Magento\Framework\Webapi\Rest\Response|\PHPUnit_Framework_MockObject_MockObject + * @var RestResponse|MockObject */ protected $restResponseMock; /** - * @var \Magento\Framework\Webapi\Exception|\PHPUnit_Framework_MockObject_MockObject + * @var WebapiException|MockObject */ protected $webapiException; /** - * @var (Config&\PHPUnit\Framework\MockObject\MockObject)|\PHPUnit\Framework\MockObject\MockObject + * @var (Config&MockObject)|MockObject */ protected $configHelper; /** - * @var (InstanceFactory&\PHPUnit\Framework\MockObject\MockObject)|\PHPUnit\Framework\MockObject\MockObject + * @var (InstanceFactory&MockObject)|MockObject */ protected $methodInstance; /** - * @var (Order&\PHPUnit\Framework\MockObject\MockObject)|\PHPUnit\Framework\MockObject\MockObject + * @var (Order&MockObject)|MockObject */ protected $orderMock; @@ -101,27 +106,27 @@ abstract class AbstractObserverTest extends \EMerchantPay\Genesis\Test\Unit\Abst protected $sendMailOnOrderPaymentSuccess; /** - * @var (OrderFactory&\PHPUnit\Framework\MockObject\MockObject)|\PHPUnit\Framework\MockObject\MockObject + * @var (OrderFactory&MockObject)|MockObject */ protected $orderModel; /** - * @var (OrderSender&\PHPUnit\Framework\MockObject\MockObject)|\PHPUnit\Framework\MockObject\MockObject + * @var (OrderSender&MockObject)|MockObject */ protected $orderSender; /** - * @var (Session&\PHPUnit\Framework\MockObject\MockObject)|\PHPUnit\Framework\MockObject\MockObject + * @var (Session&MockObject)|MockObject */ protected $checkoutSession; /** - * @var \stdClass + * @var stdClass */ protected $createMock; /** - * @var (OrderPaymentInterface&\PHPUnit\Framework\MockObject\MockObject)|\PHPUnit\Framework\MockObject\MockObject + * @var (OrderPaymentInterface&MockObject)|MockObject */ protected $paymentInterfaceMock; @@ -129,8 +134,10 @@ abstract protected function getObserverClassName(); /** * Gets observer's instance - * @return \EMerchantPay\Genesis\Model\Observer\ControllerFrontSendResponseBefore| - * \EMerchantPay\Genesis\Model\Observer\SalesOrderPaymentPlaceEnd + * + * @return ControllerFrontSendResponseBefore| + * + * @covers SalesOrderBeforeSaveObserver */ protected function getObserverInstance() { @@ -139,79 +146,92 @@ protected function getObserverInstance() /** * Get mock for data helper - * @return \EMerchantPay\Genesis\Helper\Data|\PHPUnit_Framework_MockObject_MockObject + * @return DataHelper|MockObject */ protected function getDataHelperMock() { return $this->dataHelperMock = $this->getMockBuilder(DataHelper::class) ->disableOriginalConstructor() - ->setMethods(['createWebApiException']) + ->onlyMethods(['createWebApiException']) ->getMock(); } /** * Get mock for error processor - * @return \Magento\Framework\Webapi\ErrorProcessor|\PHPUnit_Framework_MockObject_MockObject + * @return ErrorProcessor|MockObject */ protected function getErrorProcessorMock() { return $this->errorProcessorMock = $this->getMockBuilder(ErrorProcessor::class) ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); } /** * Get mock for checkout session - * @return \Magento\Checkout\Model\Session|\PHPUnit_Framework_MockObject_MockObject + * @return Session|MockObject */ protected function getCheckoutSessionMock() { return $this->checkoutSessionMock = $this->getMockBuilder(Session::class) ->disableOriginalConstructor() - ->setMethods(['getEmerchantPayLastCheckoutError','setEmerchantPayLastCheckoutError']) + ->addMethods( + [ + 'getEmerchantPayLastCheckoutError', + 'setEmerchantPayLastCheckoutError' + ] + ) ->getMock(); } /** * Get mock for event observer - * @return \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject + * + * @return Observer|MockObject */ protected function getObserverMock() { return $this->observerMock = $this->getMockBuilder(Observer::class) ->disableOriginalConstructor() - ->setMethods(['getEvent']) + ->onlyMethods(['getEvent']) ->getMock(); } /** * Get mock for event - * @return \Magento\Framework\Event|\PHPUnit_Framework_MockObject_MockObject + * + * @return Event|MockObject */ protected function getEventMock() { return $this->eventMock = $this->getMockBuilder(Event::class) ->disableOriginalConstructor() - ->setMethods(['getData']) + ->onlyMethods(['getData']) ->getMock(); } /** * Get mock for Webapi REST response - * @return \Magento\Framework\Webapi\Rest\Response|\PHPUnit_Framework_MockObject_MockObject + * + * @return RestResponse|MockObject */ protected function getRestResponseMock() { return $this->restResponseMock = $this->getMockBuilder(RestResponse::class) ->disableOriginalConstructor() - ->setMethods(['setException','isException']) + ->onlyMethods( + [ + 'setException', + 'isException' + ] + ) ->getMock(); } /** * Get mock for Webapi exception - * @return \Magento\Framework\Webapi\Exception|\PHPUnit_Framework_MockObject_MockObject + * + * @return WebapiException|MockObject */ protected function getWebapiException() { @@ -229,16 +249,22 @@ protected function getSendMailOnOrderPaymentSuccessMocks(): void { $this->methodInstance = $this->getMockBuilder(InstanceFactory::class) ->disableOriginalConstructor() - ->setMethods(['getCode']) + ->addMethods(['getCode']) ->getMock(); $this->paymentInterfaceMock = $this->getMockBuilder(OrderPaymentInterface::class) - ->setMethods(['getMethodInstance']) + ->addMethods(['getMethodInstance']) ->disableOriginalConstructor() ->getMockForAbstractClass(); $this->orderMock = $this->getMockBuilder(Order::class) - ->setMethods(['getPayment', 'setCanSendNewEmailFlag', 'setSendEmail']) + ->onlyMethods( + [ + 'getPayment', + 'setCanSendNewEmailFlag', + ] + ) + ->addMethods(['setSendEmail']) ->disableOriginalConstructor() ->getMock(); @@ -248,7 +274,14 @@ protected function getSendMailOnOrderPaymentSuccessMocks(): void $this->eventMock = $this->getMockBuilder(Event::class) ->disableOriginalConstructor() - ->setMethods(['getData', 'getEvent', 'getOrder', 'getOrderIds']) + ->onlyMethods(['getData']) + ->addMethods( + [ + 'getEvent', + 'getOrder', + 'getOrderIds' + ] + ) ->getMock(); } @@ -270,8 +303,8 @@ protected function setUp(): void $this->observerInstance = $this->getObjectManagerHelper()->getObject( $this->getObserverClassName(), [ - 'moduleHelper' => $this->dataHelperMock, - 'errorProcessor' => $this->errorProcessorMock, + 'moduleHelper' => $this->dataHelperMock, + 'errorProcessor' => $this->errorProcessorMock, 'checkoutSession' => $this->checkoutSessionMock ] ); diff --git a/Test/Unit/Model/Observer/ControllerFrontSendResponseBeforeTest.php b/Test/Unit/Model/Observer/ControllerFrontSendResponseBeforeTest.php index a8f2c02..cf345a9 100755 --- a/Test/Unit/Model/Observer/ControllerFrontSendResponseBeforeTest.php +++ b/Test/Unit/Model/Observer/ControllerFrontSendResponseBeforeTest.php @@ -20,29 +20,24 @@ namespace EMerchantPay\Genesis\Test\Unit\Model\Observer; use EMerchantPay\Genesis\Model\Observer\ControllerFrontSendResponseBefore; +use PHPUnit\Framework\MockObject\MockObject; /** + * Test front controller response + * * Class ControllerFrontSendResponseBeforeTest - * @covers \EMerchantPay\Genesis\Model\Observer\ControllerFrontSendResponseBefore - * @package EMerchantPay\Genesis\Test\Unit\Model\Observer + * + * @covers ControllerFrontSendResponseBefore */ -class ControllerFrontSendResponseBeforeTest extends \EMerchantPay\Genesis\Test\Unit\Model\Observer\AbstractObserverTest +class ControllerFrontSendResponseBeforeTest extends AbstractObserverTest { /** - * @var \EMerchantPay\Genesis\Model\Observer\ControllerFrontSendResponseBefore|\PHPUnit_Framework_MockObject_MockObject + * @var ControllerFrontSendResponseBefore|MockObject */ protected $observerInstance; /** - * @return string - */ - protected function getObserverClassName() - { - return ControllerFrontSendResponseBefore::class; - } - - /** - * @covers \EMerchantPay\Genesis\Model\Observer\ControllerFrontSendResponseBefore::execute() + * @covers ControllerFrontSendResponseBefore::execute */ public function testExecuteNullResponse() { @@ -65,7 +60,7 @@ public function testExecuteNullResponse() } /** - * @covers \EMerchantPay\Genesis\Model\Observer\ControllerFrontSendResponseBefore::execute() + * @covers ControllerFrontSendResponseBefore::execute */ public function testExecuteDoNotOverrideCheckoutException() { @@ -96,7 +91,7 @@ public function testExecuteDoNotOverrideCheckoutException() } /** - * @covers \EMerchantPay\Genesis\Model\Observer\ControllerFrontSendResponseBefore::execute() + * @covers ControllerFrontSendResponseBefore::execute */ public function testExecuteOverrideCheckoutException() { @@ -133,4 +128,12 @@ public function testExecuteOverrideCheckoutException() $this->getObserverInstance()->execute($this->observerMock); } + + /** + * @return string + */ + protected function getObserverClassName() + { + return ControllerFrontSendResponseBefore::class; + } } diff --git a/Test/Unit/Model/Observer/SalesOrderBeforeSaveObserverTest.php b/Test/Unit/Model/Observer/SalesOrderBeforeSaveObserverTest.php index bceaec1..5f63260 100644 --- a/Test/Unit/Model/Observer/SalesOrderBeforeSaveObserverTest.php +++ b/Test/Unit/Model/Observer/SalesOrderBeforeSaveObserverTest.php @@ -20,8 +20,9 @@ namespace EMerchantPay\Genesis\Test\Unit\Model\Observer; use EMerchantPay\Genesis\Model\Method\Checkout; -use Magento\Framework\Event\Observer; use EMerchantPay\Genesis\Model\Observer\SalesOrderBeforeSaveObserver; +use Magento\Framework\Event\Observer; +use Magento\Framework\Exception\LocalizedException; class SalesOrderBeforeSaveObserverTest extends AbstractObserverTest { @@ -34,6 +35,8 @@ class SalesOrderBeforeSaveObserverTest extends AbstractObserverTest * @covers SalesOrderBeforeSaveObserver::execute() * * @return void + * + * @throws LocalizedException */ public function testExecute(): void { @@ -48,6 +51,8 @@ public function testExecute(): void * @covers SalesOrderBeforeSaveObserver::execute() * * @return void + * + * @throws LocalizedException */ public function testExecuteWithOurPaymentMethod(): void { @@ -76,6 +81,8 @@ public function testExecuteWithOurPaymentMethod(): void * @covers SalesOrderBeforeSaveObserver::execute() * * @return void + * + * @throws LocalizedException */ public function testExecuteWithOtherPaymentMethod(): void { @@ -101,6 +108,8 @@ public function testExecuteWithOtherPaymentMethod(): void * @covers SalesOrderBeforeSaveObserver::execute() * * @return void + * + * @throws LocalizedException */ public function testWithPaymentConfirmationEmailEnabledFalse() { @@ -150,7 +159,7 @@ protected function setUp(): void $this->observerMock = $this->getMockBuilder(Observer::class) ->disableOriginalConstructor() - ->setMethods(['getEvent']) + ->onlyMethods(['getEvent']) ->getMock(); $this->observerMock->expects($this->once()) ->method('getEvent') diff --git a/Test/Unit/Model/Observer/SendMailOnOrderPaymentSuccessTest.php b/Test/Unit/Model/Observer/SendMailOnOrderPaymentSuccessTest.php index 34bfa80..9ff66c7 100644 --- a/Test/Unit/Model/Observer/SendMailOnOrderPaymentSuccessTest.php +++ b/Test/Unit/Model/Observer/SendMailOnOrderPaymentSuccessTest.php @@ -23,15 +23,17 @@ use EMerchantPay\Genesis\Model\Observer\SalesOrderBeforeSaveObserver; use EMerchantPay\Genesis\Model\Observer\SendMailOnOrderPaymentSuccess; use Magento\Checkout\Model\Session; +use Magento\Framework\Exception\LocalizedException; use Magento\Sales\Model\Order; use Magento\Sales\Model\OrderFactory; use Magento\Sales\Model\Order\Email\Sender\OrderSender; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\Rule\InvokedCount as InvokedCountMatcher; class SendMailOnOrderPaymentSuccessTest extends AbstractObserverTest { /** - * @var array|(Order&\PHPUnit\Framework\MockObject\MockObject)|\PHPUnit\Framework\MockObject\MockObject + * @var array|(Order&MockObject)|MockObject */ protected $orderIds = []; @@ -39,6 +41,8 @@ class SendMailOnOrderPaymentSuccessTest extends AbstractObserverTest * @covers SalesOrderBeforeSaveObserver::execute() * * @return void + * + * @throws LocalizedException */ public function testExecuteWithSend(): void { @@ -56,6 +60,8 @@ public function testExecuteWithSend(): void * @covers SalesOrderBeforeSaveObserver::execute() * * @return void + * + * @throws LocalizedException */ public function testWithPaymentConfirmationEmailEnabledFalse(): void { @@ -73,6 +79,8 @@ public function testWithPaymentConfirmationEmailEnabledFalse(): void * @covers SalesOrderBeforeSaveObserver::execute() * * @return void + * + * @throws LocalizedException */ public function testExecuteWithoutOrder(): void { diff --git a/Test/Unit/Plugin/CookieManagerTest.php b/Test/Unit/Plugin/CookieManagerTest.php index b306669..f555535 100644 --- a/Test/Unit/Plugin/CookieManagerTest.php +++ b/Test/Unit/Plugin/CookieManagerTest.php @@ -24,12 +24,15 @@ use Magento\Framework\Stdlib\Cookie\CookieMetadata; use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; use Magento\Framework\Stdlib\Cookie\PhpCookieManager; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** + * Test Cookie samesite handler + * * Class CookieManagerTest * - * @covers \EMerchantPay\Genesis\Plugin\CookieManager + * @covers CookieManager */ class CookieManagerTest extends TestCase { @@ -39,42 +42,28 @@ class CookieManagerTest extends TestCase private $cookieManager; /** - * @var CookieMetadataFactory|\PHPUnit\Framework\MockObject\MockObject + * @var CookieMetadataFactory|MockObject */ private $cookieMetadataFactoryMock; /** - * @var PhpCookieManager|\PHPUnit\Framework\MockObject\MockObject + * @var PhpCookieManager|MockObject */ private $phpCookieManagerMock; /** - * @var CookieMetadata|\PHPUnit\Framework\MockObject\MockObject + * @var CookieMetadata|MockObject */ private $cookieMetadataMock; - protected function setUp(): void - { - $this->cookieMetadataFactoryMock = $this->getMockBuilder(CookieMetadataFactory::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->phpCookieManagerMock = $this->getMockBuilder(PhpCookieManager::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->cookieMetadataMock = $this->getMockBuilder(CookieMetadata::class) - ->disableOriginalConstructor() - ->onlyMethods(['setSameSite']) - ->addMethods(['setSecure']) - ->getMock(); - - $this->cookieManager = new CookieManager($this->cookieMetadataFactoryMock); - } - + /** + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * + * @return void + */ public function testAroundSetPublicCookieWithNullMetadata() { - $cookieName = 'test_cookie'; + $cookieName = 'test_cookie'; $cookieValue = 'test_value'; $this->cookieMetadataFactoryMock->expects($this->once()) @@ -106,6 +95,11 @@ public function testAroundSetPublicCookieWithNullMetadata() $this->assertTrue($result); } + /** + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * + * @return void + */ public function testAroundSetPublicCookieWithMetadata() { $cookieName = 'test_cookie'; @@ -135,4 +129,26 @@ public function testAroundSetPublicCookieWithMetadata() $this->assertTrue($result); } + + /** + * @return void + */ + protected function setUp(): void + { + $this->cookieMetadataFactoryMock = $this->getMockBuilder(CookieMetadataFactory::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->phpCookieManagerMock = $this->getMockBuilder(PhpCookieManager::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->cookieMetadataMock = $this->getMockBuilder(CookieMetadata::class) + ->disableOriginalConstructor() + ->onlyMethods(['setSameSite']) + ->addMethods(['setSecure']) + ->getMock(); + + $this->cookieManager = new CookieManager($this->cookieMetadataFactoryMock); + } } diff --git a/VERSION b/VERSION index e05cb33..d4c4950 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3.8 +1.3.9 diff --git a/composer.json b/composer.json old mode 100755 new mode 100644 index fb26a44..8757023 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "emerchantpay/magento2-emp-plugin", "description": "emerchantpay Payment Gateway for Magento 2", "type": "magento2-module", - "version": "1.3.8", + "version": "1.3.9", "license": [ "GPL-2.0" ], @@ -15,7 +15,7 @@ ], "require": { "php": "7.0.2|7.0.4|~7.0.6|7.1.*|7.2.*|7.3.*|7.4.*|8.0.*|8.1.*|8.2.*|8.3.*", - "genesisgateway/genesis_php": "2.0.1" + "genesisgateway/genesis_php": "2.0.2" }, "keywords": [ "emerchantpay", @@ -52,6 +52,7 @@ "bancontact", "bitpay", "blacklist", + "blik", "cabal", "cashu", "cencosud", @@ -83,6 +84,7 @@ "insta_debit_payout", "interac", "intersolve", + "latipay", "multibanco", "mybank", "neosurf", @@ -97,7 +99,6 @@ "payu", "pix", "poli", - "ppro", "preauthorization", "preauthorization_incremental", "preauthorization_partial", @@ -113,6 +114,7 @@ "sdd_recurring", "sdd_refund", "sofort", + "spei", "tc40", "transfer_to", "trustly", diff --git a/composer.lock b/composer.lock index e4c2024..646cc27 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "77edc7bf8ce9e22ccc3dffdc24ff9b4b", + "content-hash": "0e3215d0f67e7234300e01e33aec5d47", "packages": [ { "name": "genesisgateway/genesis_php", - "version": "2.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/GenesisGateway/genesis_php.git", - "reference": "6b03c8bfa2ab3154b79de11c86e5aaf62e124b1b" + "reference": "b0dcf2f18de2d2f090b68146a5719827460ad5c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/GenesisGateway/genesis_php/zipball/6b03c8bfa2ab3154b79de11c86e5aaf62e124b1b", - "reference": "6b03c8bfa2ab3154b79de11c86e5aaf62e124b1b", + "url": "https://api.github.com/repos/GenesisGateway/genesis_php/zipball/b0dcf2f18de2d2f090b68146a5719827460ad5c5", + "reference": "b0dcf2f18de2d2f090b68146a5719827460ad5c5", "shasum": "" }, "require": { @@ -156,38 +156,46 @@ ], "support": { "issues": "https://github.com/GenesisGateway/genesis_php/issues", - "source": "https://github.com/GenesisGateway/genesis_php/tree/2.0.1" + "source": "https://github.com/GenesisGateway/genesis_php/tree/2.0.2" }, - "time": "2024-07-09T13:50:18+00:00" + "time": "2024-08-05T09:37:19+00:00" } ], "packages-dev": [ { "name": "composer/pcre", - "version": "3.1.1", + "version": "3.2.0", "source": { "type": "git", "url": "https://github.com/composer/pcre.git", - "reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9" + "reference": "ea4ab6f9580a4fd221e0418f2c357cdd39102a90" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/00104306927c7a0919b4ced2aaa6782c1e61a3c9", - "reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9", + "url": "https://api.github.com/repos/composer/pcre/zipball/ea4ab6f9580a4fd221e0418f2c357cdd39102a90", + "reference": "ea4ab6f9580a4fd221e0418f2c357cdd39102a90", "shasum": "" }, "require": { "php": "^7.4 || ^8.0" }, + "conflict": { + "phpstan/phpstan": "<1.11.8" + }, "require-dev": { - "phpstan/phpstan": "^1.3", + "phpstan/phpstan": "^1.11.8", "phpstan/phpstan-strict-rules": "^1.1", - "symfony/phpunit-bridge": "^5" + "phpunit/phpunit": "^8 || ^9" }, "type": "library", "extra": { "branch-alias": { "dev-main": "3.x-dev" + }, + "phpstan": { + "includes": [ + "extension.neon" + ] } }, "autoload": { @@ -215,7 +223,7 @@ ], "support": { "issues": "https://github.com/composer/pcre/issues", - "source": "https://github.com/composer/pcre/tree/3.1.1" + "source": "https://github.com/composer/pcre/tree/3.2.0" }, "funding": [ { @@ -231,20 +239,20 @@ "type": "tidelift" } ], - "time": "2023-10-11T07:11:09+00:00" + "time": "2024-07-25T09:36:02+00:00" }, { "name": "composer/xdebug-handler", - "version": "3.0.3", + "version": "3.0.5", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "ced299686f41dce890debac69273b47ffe98a40c" + "reference": "6c1925561632e83d60a44492e0b344cf48ab85ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/ced299686f41dce890debac69273b47ffe98a40c", - "reference": "ced299686f41dce890debac69273b47ffe98a40c", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/6c1925561632e83d60a44492e0b344cf48ab85ef", + "reference": "6c1925561632e83d60a44492e0b344cf48ab85ef", "shasum": "" }, "require": { @@ -255,7 +263,7 @@ "require-dev": { "phpstan/phpstan": "^1.0", "phpstan/phpstan-strict-rules": "^1.1", - "symfony/phpunit-bridge": "^6.0" + "phpunit/phpunit": "^8.5 || ^9.6 || ^10.5" }, "type": "library", "autoload": { @@ -279,9 +287,9 @@ "performance" ], "support": { - "irc": "irc://irc.freenode.org/composer", + "irc": "ircs://irc.libera.chat:6697/composer", "issues": "https://github.com/composer/xdebug-handler/issues", - "source": "https://github.com/composer/xdebug-handler/tree/3.0.3" + "source": "https://github.com/composer/xdebug-handler/tree/3.0.5" }, "funding": [ { @@ -297,7 +305,7 @@ "type": "tidelift" } ], - "time": "2022-02-25T21:32:43+00:00" + "time": "2024-05-06T16:37:16+00:00" }, { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -695,16 +703,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.59", + "version": "1.11.8", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e607609388d3a6d418a50a49f7940e8086798281" + "reference": "6adbd118e6c0515dd2f36b06cde1d6da40f1b8ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e607609388d3a6d418a50a49f7940e8086798281", - "reference": "e607609388d3a6d418a50a49f7940e8086798281", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/6adbd118e6c0515dd2f36b06cde1d6da40f1b8ec", + "reference": "6adbd118e6c0515dd2f36b06cde1d6da40f1b8ec", "shasum": "" }, "require": { @@ -747,13 +755,9 @@ { "url": "https://github.com/phpstan", "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", - "type": "tidelift" } ], - "time": "2024-02-20T13:59:13+00:00" + "time": "2024-07-24T07:01:22+00:00" }, { "name": "psr/container", @@ -991,16 +995,16 @@ }, { "name": "symfony/config", - "version": "v6.4.3", + "version": "v6.4.8", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "206482ff3ed450495b1d5b7bad1bc3a852def96f" + "reference": "12e7e52515ce37191b193cf3365903c4f3951e35" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/206482ff3ed450495b1d5b7bad1bc3a852def96f", - "reference": "206482ff3ed450495b1d5b7bad1bc3a852def96f", + "url": "https://api.github.com/repos/symfony/config/zipball/12e7e52515ce37191b193cf3365903c4f3951e35", + "reference": "12e7e52515ce37191b193cf3365903c4f3951e35", "shasum": "" }, "require": { @@ -1046,7 +1050,7 @@ "description": "Helps you find, load, combine, autofill and validate configuration values of any kind", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/config/tree/v6.4.3" + "source": "https://github.com/symfony/config/tree/v6.4.8" }, "funding": [ { @@ -1062,20 +1066,20 @@ "type": "tidelift" } ], - "time": "2024-01-29T13:26:27+00:00" + "time": "2024-05-31T14:49:08+00:00" }, { "name": "symfony/dependency-injection", - "version": "v6.4.3", + "version": "v6.4.10", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", - "reference": "6871811c5a5c5e180244ddb689746446db02c05b" + "reference": "5caf9c5f6085f13b27d70a236b776c07e4a1c3eb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/6871811c5a5c5e180244ddb689746446db02c05b", - "reference": "6871811c5a5c5e180244ddb689746446db02c05b", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/5caf9c5f6085f13b27d70a236b776c07e4a1c3eb", + "reference": "5caf9c5f6085f13b27d70a236b776c07e4a1c3eb", "shasum": "" }, "require": { @@ -1127,7 +1131,7 @@ "description": "Allows you to standardize and centralize the way objects are constructed in your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/dependency-injection/tree/v6.4.3" + "source": "https://github.com/symfony/dependency-injection/tree/v6.4.10" }, "funding": [ { @@ -1143,20 +1147,20 @@ "type": "tidelift" } ], - "time": "2024-01-30T08:32:12+00:00" + "time": "2024-07-26T07:32:07+00:00" }, { "name": "symfony/deprecation-contracts", - "version": "v3.4.0", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", "shasum": "" }, "require": { @@ -1165,7 +1169,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.4-dev" + "dev-main": "3.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -1194,7 +1198,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0" }, "funding": [ { @@ -1210,20 +1214,20 @@ "type": "tidelift" } ], - "time": "2023-05-23T14:45:45+00:00" + "time": "2024-04-18T09:32:20+00:00" }, { "name": "symfony/filesystem", - "version": "v6.4.3", + "version": "v6.4.9", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "7f3b1755eb49297a0827a7575d5d2b2fd11cc9fb" + "reference": "b51ef8059159330b74a4d52f68e671033c0fe463" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/7f3b1755eb49297a0827a7575d5d2b2fd11cc9fb", - "reference": "7f3b1755eb49297a0827a7575d5d2b2fd11cc9fb", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/b51ef8059159330b74a4d52f68e671033c0fe463", + "reference": "b51ef8059159330b74a4d52f68e671033c0fe463", "shasum": "" }, "require": { @@ -1231,6 +1235,9 @@ "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-mbstring": "~1.8" }, + "require-dev": { + "symfony/process": "^5.4|^6.4|^7.0" + }, "type": "library", "autoload": { "psr-4": { @@ -1257,7 +1264,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v6.4.3" + "source": "https://github.com/symfony/filesystem/tree/v6.4.9" }, "funding": [ { @@ -1273,20 +1280,20 @@ "type": "tidelift" } ], - "time": "2024-01-23T14:51:35+00:00" + "time": "2024-06-28T09:49:33+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.29.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4" + "reference": "0424dff1c58f028c451efff2045f5d92410bd540" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4", - "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/0424dff1c58f028c451efff2045f5d92410bd540", + "reference": "0424dff1c58f028c451efff2045f5d92410bd540", "shasum": "" }, "require": { @@ -1336,7 +1343,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.30.0" }, "funding": [ { @@ -1352,20 +1359,20 @@ "type": "tidelift" } ], - "time": "2024-01-29T20:11:03+00:00" + "time": "2024-05-31T15:07:36+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.29.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec" + "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec", - "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd22ab50000ef01661e2a31d850ebaa297f8e03c", + "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c", "shasum": "" }, "require": { @@ -1416,7 +1423,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.30.0" }, "funding": [ { @@ -1432,25 +1439,26 @@ "type": "tidelift" } ], - "time": "2024-01-29T20:11:03+00:00" + "time": "2024-06-19T12:30:46+00:00" }, { "name": "symfony/service-contracts", - "version": "v3.4.1", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "fe07cbc8d837f60caf7018068e350cc5163681a0" + "reference": "bd1d9e59a81d8fa4acdcea3f617c581f7475a80f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/fe07cbc8d837f60caf7018068e350cc5163681a0", - "reference": "fe07cbc8d837f60caf7018068e350cc5163681a0", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/bd1d9e59a81d8fa4acdcea3f617c581f7475a80f", + "reference": "bd1d9e59a81d8fa4acdcea3f617c581f7475a80f", "shasum": "" }, "require": { "php": ">=8.1", - "psr/container": "^1.1|^2.0" + "psr/container": "^1.1|^2.0", + "symfony/deprecation-contracts": "^2.5|^3" }, "conflict": { "ext-psr": "<1.1|>=2" @@ -1458,7 +1466,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.4-dev" + "dev-main": "3.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -1498,7 +1506,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.4.1" + "source": "https://github.com/symfony/service-contracts/tree/v3.5.0" }, "funding": [ { @@ -1514,20 +1522,20 @@ "type": "tidelift" } ], - "time": "2023-12-26T14:02:43+00:00" + "time": "2024-04-18T09:32:20+00:00" }, { "name": "symfony/var-exporter", - "version": "v6.4.3", + "version": "v6.4.9", "source": { "type": "git", "url": "https://github.com/symfony/var-exporter.git", - "reference": "a8c12b5448a5ac685347f5eeb2abf6a571ec16b8" + "reference": "f9a060622e0d93777b7f8687ec4860191e16802e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-exporter/zipball/a8c12b5448a5ac685347f5eeb2abf6a571ec16b8", - "reference": "a8c12b5448a5ac685347f5eeb2abf6a571ec16b8", + "url": "https://api.github.com/repos/symfony/var-exporter/zipball/f9a060622e0d93777b7f8687ec4860191e16802e", + "reference": "f9a060622e0d93777b7f8687ec4860191e16802e", "shasum": "" }, "require": { @@ -1535,6 +1543,8 @@ "symfony/deprecation-contracts": "^2.5|^3" }, "require-dev": { + "symfony/property-access": "^6.4|^7.0", + "symfony/serializer": "^6.4|^7.0", "symfony/var-dumper": "^5.4|^6.0|^7.0" }, "type": "library", @@ -1573,7 +1583,7 @@ "serialize" ], "support": { - "source": "https://github.com/symfony/var-exporter/tree/v6.4.3" + "source": "https://github.com/symfony/var-exporter/tree/v6.4.9" }, "funding": [ { @@ -1589,20 +1599,20 @@ "type": "tidelift" } ], - "time": "2024-01-23T14:51:35+00:00" + "time": "2024-06-24T15:53:56+00:00" }, { "name": "webonyx/graphql-php", - "version": "v15.9.1", + "version": "v15.12.5", "source": { "type": "git", "url": "https://github.com/webonyx/graphql-php.git", - "reference": "d6c965ecbd78cd5260ebc083978562f8c9409d63" + "reference": "7bcd31d1dcf67781ed5cb493b22c519c539c05e6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/d6c965ecbd78cd5260ebc083978562f8c9409d63", - "reference": "d6c965ecbd78cd5260ebc083978562f8c9409d63", + "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/7bcd31d1dcf67781ed5cb493b22c519c539c05e6", + "reference": "7bcd31d1dcf67781ed5cb493b22c519c539c05e6", "shasum": "" }, "require": { @@ -1615,19 +1625,19 @@ "amphp/http-server": "^2.1", "dms/phpunit-arraysubset-asserts": "dev-master", "ergebnis/composer-normalize": "^2.28", - "friendsofphp/php-cs-fixer": "3.48.0", + "friendsofphp/php-cs-fixer": "3.59.3", "mll-lab/php-cs-fixer-config": "^5", "nyholm/psr7": "^1.5", "phpbench/phpbench": "^1.2", "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "1.10.57", - "phpstan/phpstan-phpunit": "1.3.15", - "phpstan/phpstan-strict-rules": "1.5.2", - "phpunit/phpunit": "^9.5 || ^10", + "phpstan/phpstan": "1.11.5", + "phpstan/phpstan-phpunit": "1.4.0", + "phpstan/phpstan-strict-rules": "1.6.0", + "phpunit/phpunit": "^9.5 || ^10.5.21", "psr/http-message": "^1 || ^2", "react/http": "^1.6", "react/promise": "^2.0 || ^3.0", - "rector/rector": "^0.19", + "rector/rector": "^1.0", "symfony/polyfill-php81": "^1.23", "symfony/var-exporter": "^5 || ^6 || ^7", "thecodingmachine/safe": "^1.3 || ^2" @@ -1655,7 +1665,7 @@ ], "support": { "issues": "https://github.com/webonyx/graphql-php/issues", - "source": "https://github.com/webonyx/graphql-php/tree/v15.9.1" + "source": "https://github.com/webonyx/graphql-php/tree/v15.12.5" }, "funding": [ { @@ -1663,7 +1673,7 @@ "type": "open_collective" } ], - "time": "2024-01-25T09:10:40+00:00" + "time": "2024-06-23T11:30:58+00:00" } ], "aliases": [], @@ -1672,7 +1682,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "7.0.2|7.0.4|~7.0.6|7.1.*|7.2.*|7.3.*|7.4.*|8.0.*|8.1.*|8.2.*" + "php": "7.0.2|7.0.4|~7.0.6|7.1.*|7.2.*|7.3.*|7.4.*|8.0.*|8.1.*|8.2.*|8.3.*" }, "platform-dev": [], "plugin-api-version": "2.6.0" diff --git a/etc/module.xml b/etc/module.xml index c70e3ae..a8d880f 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -17,7 +17,7 @@ GNU General Public License for more details. @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0) --> - + diff --git a/registration.php b/registration.php old mode 100755 new mode 100644 index a1341fe..2c40e14 --- a/registration.php +++ b/registration.php @@ -17,9 +17,11 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPL-2.0) */ +// phpcs:disable if (is_array($_SERVER) && array_key_exists('PLUGIN_ENV', $_SERVER) && $_SERVER['PLUGIN_ENV'] == 'linter') { return; } +// phpcs:enable \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE,