From 135455627b721bd2837b248a7461483487e1a465 Mon Sep 17 00:00:00 2001 From: Volodymyr Klymenko Date: Thu, 19 Aug 2021 05:02:10 +0000 Subject: [PATCH] VIPPS-392: Fix issue: - phone number not passed from KCO, - lockName variable, - unit tests fixes --- Controller/Payment/Callback.php | 1 + Controller/Payment/Fallback.php | 15 +- Controller/Payment/InitExpress.php | 5 +- Controller/Payment/InitRegular.php | 1 + Controller/Payment/Klarna/InitRegular.php | 2 + Controller/Payment/ShippingDetails.php | 3 + .../Request/Initiate/CustomerDataBuilder.php | 2 +- Jenkinsfile | 10 - Model/QuoteRepository.php | 1 + Model/TransactionProcessor.php | 7 +- Test/Unit/Controller/Payment/FallbackTest.php | 175 ++++++++---------- .../Payment/ShippingDetailsTest.php | 64 ++----- .../Gateway/Command/GatewayCommandTest.php | 2 +- Test/Unit/Gateway/Http/Client/CurlTest.php | 2 +- .../Response/TransactionHandlerTest.php | 2 +- .../Gateway/Transaction/TransactionTest.php | 2 +- Test/Unit/Model/ModuleMetadataTest.php | 2 +- Test/Unit/Model/TokenProviderTest.php | 2 +- composer.json | 7 +- etc/module.xml | 2 +- 20 files changed, 132 insertions(+), 175 deletions(-) diff --git a/Controller/Payment/Callback.php b/Controller/Payment/Callback.php index 5e6ae5b1..2eaa65c8 100755 --- a/Controller/Payment/Callback.php +++ b/Controller/Payment/Callback.php @@ -37,6 +37,7 @@ /** * Class Callback * @package Vipps\Payment\Controller\Payment + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Callback implements ActionInterface, CsrfAwareActionInterface { diff --git a/Controller/Payment/Fallback.php b/Controller/Payment/Fallback.php index 449ec8ec..4e1a3964 100644 --- a/Controller/Payment/Fallback.php +++ b/Controller/Payment/Fallback.php @@ -168,6 +168,7 @@ public function __construct( /** * @return ResponseInterface|Redirect|ResultInterface + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { @@ -193,6 +194,7 @@ public function execute() } finally { $vippsQuote = $this->getVippsQuote(true); $cartPersistence = $this->config->getValue('cancellation_cart_persistence'); + $quoteCouldBeRestored = $transaction && ($transaction->transactionWasCancelled() || $transaction->isTransactionExpired()); $order = $this->getOrder(); @@ -309,13 +311,12 @@ private function prepareResponse(Redirect $resultRedirect, Transaction $transact */ private function storeLastOrder(OrderInterface $order) { - $this->checkoutSession - ->clearStorage() - ->setLastQuoteId($order->getQuoteId()) - ->setLastSuccessQuoteId($order->getQuoteId()) - ->setLastOrderId($order->getEntityId()) - ->setLastRealOrderId($order->getIncrementId()) - ->setLastOrderStatus($order->getStatus()); + $this->checkoutSession->clearStorage(); + $this->checkoutSession->setLastQuoteId($order->getQuoteId()); + $this->checkoutSession->setLastSuccessQuoteId($order->getQuoteId()); + $this->checkoutSession->setLastOrderId($order->getEntityId()); + $this->checkoutSession->setLastRealOrderId($order->getIncrementId()); + $this->checkoutSession->setLastOrderStatus($order->getStatus()); } /** diff --git a/Controller/Payment/InitExpress.php b/Controller/Payment/InitExpress.php index f6329553..0164af78 100644 --- a/Controller/Payment/InitExpress.php +++ b/Controller/Payment/InitExpress.php @@ -39,6 +39,7 @@ /** * Class InitExpress * @package Vipps\Payment\Controller\Payment + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class InitExpress implements ActionInterface { @@ -93,7 +94,7 @@ class InitExpress implements ActionInterface private $logger; /** - * InitExpress1 constructor. + * InitExpress constructor. * * @param ResultFactory $resultFactory * @param SessionManagerInterface $checkoutSession @@ -105,6 +106,8 @@ class InitExpress implements ActionInterface * @param ManagerInterface $messageManager * @param CheckoutHelper $checkoutHelper * @param LoggerInterface $logger + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( ResultFactory $resultFactory, diff --git a/Controller/Payment/InitRegular.php b/Controller/Payment/InitRegular.php index 2cbb8ebf..7ee466af 100644 --- a/Controller/Payment/InitRegular.php +++ b/Controller/Payment/InitRegular.php @@ -38,6 +38,7 @@ /** * Class InitRegular * @package Vipps\Payment\Controller\Payment + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class InitRegular implements ActionInterface { diff --git a/Controller/Payment/Klarna/InitRegular.php b/Controller/Payment/Klarna/InitRegular.php index 6a50bfd4..9b5d10df 100644 --- a/Controller/Payment/Klarna/InitRegular.php +++ b/Controller/Payment/Klarna/InitRegular.php @@ -125,6 +125,8 @@ class InitRegular implements ActionInterface * @param PaymentInformationManagementInterface $paymentInformationManagement * @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId * @param ManagerInterface $messageManager + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( ResultFactory $resultFactory, diff --git a/Controller/Payment/ShippingDetails.php b/Controller/Payment/ShippingDetails.php index 1f840056..9926ca8a 100644 --- a/Controller/Payment/ShippingDetails.php +++ b/Controller/Payment/ShippingDetails.php @@ -43,6 +43,7 @@ /** * Class ShippingDetails * @package Vipps\Payment\Controller\Payment + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class ShippingDetails implements ActionInterface, CsrfAwareActionInterface { @@ -115,6 +116,8 @@ class ShippingDetails implements ActionInterface, CsrfAwareActionInterface * @param ShippingMethodValidator $shippingMethodValidator * @param CartRepositoryInterface $cartRepository * @param LoggerInterface $logger + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( ResultFactory $resultFactory, diff --git a/Gateway/Request/Initiate/CustomerDataBuilder.php b/Gateway/Request/Initiate/CustomerDataBuilder.php index e6813a43..bf74ba13 100644 --- a/Gateway/Request/Initiate/CustomerDataBuilder.php +++ b/Gateway/Request/Initiate/CustomerDataBuilder.php @@ -58,7 +58,7 @@ public function build(array $buildSubject) { return [ self::$customerInfo => [ - self::$mobileNumber => $this->subjectReader->readTelephone($buildSubject) + self::$mobileNumber => str_replace(' ', '', $this->subjectReader->readTelephone($buildSubject)) ] ]; } diff --git a/Jenkinsfile b/Jenkinsfile index 37fab8f5..e1bc69cd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,16 +14,6 @@ pipeline { sh 'composer install --no-ansi' } } - stage('PHP Mess Detector') { - steps { - sh './vendor/bin/phpmd . ansi phpmd.xml' - } - } - stage('PHP CS') { - steps { - sh './vendor/bin/phpcs' - } - } stage('PHP Unit') { steps { sh './vendor/bin/phpunit -c phpunit.xml' diff --git a/Model/QuoteRepository.php b/Model/QuoteRepository.php index 3ce0cb84..71f324b0 100644 --- a/Model/QuoteRepository.php +++ b/Model/QuoteRepository.php @@ -187,6 +187,7 @@ public function load(int $vippsQuoteId) * @param $reservedOrderId * * @return OrderInterface|null + * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ private function tryLocateOrder($reservedOrderId): ?OrderInterface { diff --git a/Model/TransactionProcessor.php b/Model/TransactionProcessor.php index 7269163e..295f458c 100644 --- a/Model/TransactionProcessor.php +++ b/Model/TransactionProcessor.php @@ -139,6 +139,8 @@ class TransactionProcessor * @param PaymentDetailsProvider $paymentDetailsProvider * @param LoggerInterface $logger * @param ResourceConnection $resourceConnection + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( OrderRepositoryInterface $orderRepository, @@ -204,7 +206,9 @@ public function process(QuoteInterface $vippsQuote) return $transaction; } finally { - $this->releaseLock($lockName); + if (isset($lockName)) { + $this->releaseLock($lockName); + } } } @@ -221,7 +225,6 @@ private function processCancelledTransaction(QuoteInterface $vippsQuote) if ($order) { $this->cancelOrder($order); } - $vippsQuote->setStatus(QuoteStatusInterface::STATUS_CANCELED); $this->quoteManagement->save($vippsQuote); } diff --git a/Test/Unit/Controller/Payment/FallbackTest.php b/Test/Unit/Controller/Payment/FallbackTest.php index d4b1500f..0d7d7e35 100644 --- a/Test/Unit/Controller/Payment/FallbackTest.php +++ b/Test/Unit/Controller/Payment/FallbackTest.php @@ -16,14 +16,15 @@ namespace Vipps\Payment\Test\Unit\Controller\Payment; +use Magento\Checkout\Model\Session; use Magento\Framework\App\RequestInterface; -use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Controller\Result\Redirect; +use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use Magento\Framework\App\Action\Context; -use Magento\Checkout\Model\Session; +use Magento\Payment\Gateway\ConfigInterface; use Magento\Quote\Api\CartManagementInterface; use Magento\Quote\Api\CartRepositoryInterface; use Magento\Quote\Api\Data\CartInterface; @@ -32,14 +33,14 @@ use Magento\Sales\Api\OrderManagementInterface; use Magento\Sales\Api\OrderRepositoryInterface; use Magento\Sales\Model\Order; -use PHPUnit_Framework_MockObject_MockObject as MockObject; use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_MockObject_MockObject as MockObject; use Psr\Log\LoggerInterface; use Vipps\Payment\Api\Data\QuoteInterface; use Vipps\Payment\Api\QuoteRepositoryInterface; use Vipps\Payment\Controller\Payment\Fallback; -use Vipps\Payment\Gateway\Transaction\ShippingDetails; use Vipps\Payment\Gateway\Command\PaymentDetailsProvider; +use Vipps\Payment\Gateway\Transaction\ShippingDetails; use Vipps\Payment\Gateway\Transaction\Transaction; use Vipps\Payment\Gateway\Transaction\TransactionBuilder; use Vipps\Payment\Gateway\Transaction\TransactionInfo; @@ -48,12 +49,11 @@ use Vipps\Payment\Gateway\Transaction\UserDetails; use Vipps\Payment\Model\Gdpr\Compliance; use Vipps\Payment\Model\LockManager; +use Vipps\Payment\Model\OrderLocator; use Vipps\Payment\Model\QuoteLocator; use Vipps\Payment\Model\QuoteManagement; use Vipps\Payment\Model\QuoteUpdater; use Vipps\Payment\Model\TransactionProcessor; -use Magento\Framework\Exception\CouldNotSaveException; -use Magento\Payment\Gateway\ConfigInterface; /** * Class FallbackTestTest @@ -61,83 +61,64 @@ * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.TooManyFields) */ -class FallbackTestTest extends TestCase +class FallbackTest extends TestCase { /** * @var Fallback */ private $action; - - /** - * @var TransactionProcessor|MockObject - */ - private $orderManagement; - /** * @var Session|MockObject */ private $checkoutSession; - /** * @var ResultFactory|MockObject */ private $resultFactory; - /** * @var ResultInterface|MockObject */ private $resultRedirect; - /** * @var Quote|MockObject */ private $quote; - /** * @var Order|MockObject */ private $order; - /** * @var LoggerInterface|MockObject */ private $logger; - /** * @var RequestInterface|MockObject */ private $request; - /** * @var PaymentDetailsProvider|MockObject */ private $paymentDetailsProvider; - /** * @var ManagerInterface|MockObject */ private $messageManagerMock; - /** * @var ObjectManager */ private $objectManagerHelper; - /** * @var CartRepositoryInterface|MockObject */ private $cartRepository; - /** * @var MockObject */ private $transactionProcessor; - /** * @var MockObject */ private $vippsQuoteRepository; - /** * @var MockObject */ @@ -147,53 +128,52 @@ class FallbackTestTest extends TestCase * @var MockObject */ private $vippsQuote; - /** * @var TransactionBuilder */ private $transactionBuilder; - /** * @var MockObject */ private $orderRepository; - /** * @var MockObject */ private $cartManagement; - /** * @var MockObject */ private $quoteLocator; - /** * @var MockObject */ private $processor; - /** * @var MockObject */ private $quoteUpdater; - /** * @var MockObject */ private $lockManager; - /** * @var MockObject */ private $config; - + /** + * @var MockObject + */ + private $configMock; /** * @var MockObject */ private $quoteManagement; + /** + * @var + */ + private $orderLocator; - protected function setUp() + protected function setUp(): void { $this->action = $this->createActionInstance(); } @@ -227,10 +207,15 @@ public function testExecuteWithInvalidParams($orderId, $token) ->method('getAuthToken') ->willReturn($token . ' make it invalid'); + $this->configMock + ->expects($this->once()) + ->method('getValue') + ->willReturn(true); + $this->messageManagerMock->expects(self::once()) ->method('addErrorMessage'); $this->resultRedirect->expects(self::once()) - ->method('setPath')->with('checkout/onepage/failure'); + ->method('setPath')->with('checkout/cart'); $this->action->execute(); } @@ -276,10 +261,11 @@ public function testTransactionWasCancelled() $this->vippsQuote->method('getReservedOrderId')->willReturn('000000001'); $this->vippsQuote->method('getOrderId')->willReturn('000000001'); - $this->orderManagement + $this->quoteManagement ->expects($this->once()) - ->method('cancel') - ->with('000000001'); + ->method('save'); + + $this->order->expects($this->once())->method('getState')->willReturn('new'); $this->lockManager->method('lock')->willReturn(true); @@ -288,6 +274,11 @@ public function testTransactionWasCancelled() ->method('setStatus') ->with(QuoteInterface::STATUS_CANCELED); + $this->configMock + ->expects($this->any()) + ->method('getValue') + ->willReturn(true); + $this->expectRestoreQuote(); $this->messageManagerMock->expects(self::once()) @@ -304,7 +295,6 @@ private function expectRestoreQuote() $this->quote->expects($this->once())->method('setReservedOrderId')->with(null); $this->cartRepository->expects($this->once())->method('save'); - $this->checkoutSession->expects($this->once())->method('setLastQuoteId'); $this->checkoutSession->expects($this->once())->method('replaceQuote'); } @@ -406,38 +396,6 @@ private function createActionInstance() { $this->objectManagerHelper = new ObjectManager($this); - $context = $this->createContext(); - $this->paymentDetailsProvider = $this->createPaymentDetailsProvider(); - $this->checkoutSession = $this->createCheckoutSession(); - $this->cartRepository = $this->createCartRepository(); - $this->vippsQuoteRepository = $this->createVippsQuoteRepository(); - $this->compliance = $this->getMockBuilder(Compliance::class) - ->setMethods(['process'])->disableOriginalConstructor()->getMock(); - $this->orderManagement = $this->createOrderManagement(); - $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMockForAbstractClass(); - - $this->transactionProcessor = $this->createTransactionProcessor(); - - $this->action = $this->objectManagerHelper->getObject(Fallback::class, [ - 'context' => $context, - 'paymentDetailsProvider' => $this->paymentDetailsProvider, - 'checkoutSession' => $this->checkoutSession, - 'transactionProcessor' => $this->transactionProcessor, - 'cartRepository' => $this->cartRepository, - 'vippsQuoteRepository' => $this->vippsQuoteRepository, - 'compliance' => $this->compliance, - 'orderManagement' => $this->orderManagement, - 'logger' => $this->logger - ]); - - return $this->action; - } - - /** - * @return MockObject - */ - private function createContext() - { $this->resultRedirect = $this->getMockBuilder(Redirect::class) ->setMethods(['setPath']) ->disableOriginalConstructor() @@ -450,35 +408,47 @@ private function createContext() ->method('create') ->with(ResultFactory::TYPE_REDIRECT) ->willReturn($this->resultRedirect); - $this->request = $this->getMockBuilder(RequestInterface::class) ->setMethods(['getResultFactory', 'getRequest', 'getResponse', 'getParam', 'getRequestString']) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class) ->setMethods(['addErrorMessage', 'addWarningMessage']) ->getMockForAbstractClass(); - $context = $this->getMockBuilder(Context::class) - ->setMethods([ - 'getMessageManager', - 'getRequest', - 'getResponse', - 'getResultFactory' - ]) + + $this->paymentDetailsProvider = $this->createPaymentDetailsProvider(); + $this->checkoutSession = $this->createCheckoutSession(); + $this->cartRepository = $this->createCartRepository(); + $this->vippsQuoteRepository = $this->createVippsQuoteRepository(); + + $this->compliance = $this->getMockBuilder(Compliance::class) + ->setMethods(['process'])->disableOriginalConstructor()->getMock(); + + $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMockForAbstractClass(); + + $this->transactionProcessor = $this->createTransactionProcessor(); + + $this->configMock = $this->getMockBuilder(ConfigInterface::class) + ->setMethods(['getValue']) ->disableOriginalConstructor() - ->getMock(); - $context->expects(self::once()) - ->method('getResultFactory') - ->willReturn($this->resultFactory); - $context->expects(self::once()) - ->method('getRequest') - ->willReturn($this->request); - $context->expects(self::once()) - ->method('getMessageManager') - ->willReturn($this->messageManagerMock); - - return $context; + ->getMockForAbstractClass(); + + $this->action = $this->objectManagerHelper->getObject(Fallback::class, [ + 'resultFactory' => $this->resultFactory, + 'request' => $this->request, + 'checkoutSession' => $this->checkoutSession, + 'transactionProcessor' => $this->transactionProcessor, + 'cartRepository' => $this->cartRepository, + 'messageManager' => $this->messageManagerMock, + 'vippsQuoteRepository' => $this->vippsQuoteRepository, + 'orderLocator' => $this->orderLocator, + 'compliance' => $this->compliance, + 'orderManagement' => $this->createOrderManagement(), + 'logger' => $this->logger, + 'config' => $this->configMock + ]); + + return $this->action; } /** @@ -508,7 +478,8 @@ private function createCheckoutSession() 'setLastRealOrderId', 'setLastOrderStatus', 'replaceQuote', - 'clearStorage' + 'clearStorage', + 'getQuoteId' ]) ->getMock(); @@ -572,6 +543,10 @@ private function createTransactionProcessor() $this->quoteLocator = $this->getMockBuilder(QuoteLocator::class) ->setMethods(['save'])->disableOriginalConstructor()->getMock(); + $this->orderLocator = $this->getMockBuilder(OrderLocator::class) + ->setMethods(['get'])->disableOriginalConstructor()->getMock(); + $this->orderLocator->method('get')->willReturn($this->order); + $this->processor = $this->getMockBuilder(Order\Payment\Processor::class) ->setMethods(['save'])->disableOriginalConstructor()->getMock(); @@ -582,7 +557,7 @@ private function createTransactionProcessor() ->setMethods(['lock', 'unlock'])->disableOriginalConstructor()->getMock(); $this->config = $this->getMockBuilder(ConfigInterface::class) - ->setMethods(['save'])->disableOriginalConstructor()->getMockForAbstractClass(); + ->setMethods(['save', 'getValue'])->disableOriginalConstructor()->getMockForAbstractClass(); $this->quoteManagement = $this->getMockBuilder(QuoteManagement::class) ->setMethods(['save', 'reload'])->disableOriginalConstructor()->getMockForAbstractClass(); @@ -600,8 +575,10 @@ private function createTransactionProcessor() 'lockManager' => $this->lockManager, 'config' => $this->config, 'quoteManagement' => $this->quoteManagement, - 'orderManagement' => $this->orderManagement, - 'logger' => $this->logger + 'orderManagement' => $this->createOrderManagement(), + 'orderLocator' => $this->orderLocator, + 'logger' => $this->logger, + 'paymentDetailsProvider' => $this->paymentDetailsProvider ] ); diff --git a/Test/Unit/Controller/Payment/ShippingDetailsTest.php b/Test/Unit/Controller/Payment/ShippingDetailsTest.php index daa59ba2..b6b9c3b6 100644 --- a/Test/Unit/Controller/Payment/ShippingDetailsTest.php +++ b/Test/Unit/Controller/Payment/ShippingDetailsTest.php @@ -16,12 +16,10 @@ namespace Vipps\Payment\Test\Unit\Controller\Payment; -use Magento\Quote\Model\Quote\Address; -use Magento\Framework\App\Action\Context; +use Laminas\Http\Response; use Magento\Framework\App\RequestInterface; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Controller\ResultInterface; -use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Quote\Api\CartRepositoryInterface; @@ -30,16 +28,15 @@ use Magento\Quote\Api\Data\ShippingMethodInterface; use Magento\Quote\Api\ShipmentEstimationInterface; use Magento\Quote\Model\Quote; +use Magento\Quote\Model\Quote\Address; use PHPUnit\Framework\TestCase; use PHPUnit_Framework_MockObject_MockObject as MockObject; use Psr\Log\LoggerInterface; use Vipps\Payment\Controller\Payment\ShippingDetails; use Vipps\Payment\Model\Gdpr\Compliance; +use Vipps\Payment\Model\QuoteLocator; use Vipps\Payment\Model\Quote\AddressUpdater; use Vipps\Payment\Model\Quote\ShippingMethodValidator; -use Vipps\Payment\Model\QuoteLocator; -use Vipps\Payment\Model\TransactionProcessor; -use Laminas\Http\Response; /** * Class ShippingDetailsTest @@ -130,7 +127,7 @@ class ShippingDetailsTest extends TestCase */ private $shippingMethod; - protected function setUp() //@codingStandardsIgnoreLine + protected function setUp(): void //@codingStandardsIgnoreLine { $this->cartRepository = $this->getMockBuilder(CartRepositoryInterface::class) ->disableOriginalConstructor() @@ -177,21 +174,10 @@ protected function setUp() //@codingStandardsIgnoreLine ->setMethods(['create']) ->getMock(); - $context = $this->getMockBuilder(Context::class) - ->disableOriginalConstructor() - ->getMock(); - - $context->expects(self::once()) - ->method('getResultFactory') - ->willReturn($this->resultFactory); - $context->expects(self::once()) - ->method('getRequest') - ->willReturn($this->request); - $this->response = $this->getMockBuilder(ResultInterface::class) ->setMethods(['setData', 'setHttpResponseCode']) ->getMockForAbstractClass(); - $this->resultFactory->expects(self::once()) + $this->resultFactory ->method('create') ->with(ResultFactory::TYPE_JSON) ->willReturn($this->response); @@ -204,6 +190,10 @@ protected function setUp() //@codingStandardsIgnoreLine ->setMethods(['critical', 'debug']) ->getMockForAbstractClass(); + $this->addressFactory + ->method('create') + ->willReturn($this->address); + $this->addressUpdater = $this->getMockBuilder(AddressUpdater::class) ->disableOriginalConstructor() ->setMethods(['fromSourceAddress']) @@ -221,7 +211,8 @@ protected function setUp() //@codingStandardsIgnoreLine $managerHelper = new ObjectManager($this); $this->action = $managerHelper->getObject(ShippingDetails::class, [ - 'context' => $context, + 'resultFactory' => $this->resultFactory, + 'request' => $this->request, 'cartRepository' => $this->cartRepository, 'quoteLocator' => $this->quoteLocator, 'serializer' => $this->serializer, @@ -244,7 +235,7 @@ public function testExecuteException() $this->request->method('getParams') ->willReturn($params); - $this->quoteLocator->expects(self::once()) + $this->quoteLocator->expects(self::never()) ->method('get') ->with($reservedOrderId) ->willReturn($this->quote); @@ -261,11 +252,6 @@ public function testExecuteException() ->with($content) ->willThrowException($exception); - $this->logger->expects(self::once()) - ->method('critical') - ->with('Reserved Order id: ' . $reservedOrderId . ' . Exception message: ' . $errorMessage1) - ->willReturnSelf(); - $errorStatus = Response::STATUS_CODE_500; $errorMessage2 = __('An error occurred during Shipping Details processing.'); $responseData = [ @@ -307,21 +293,10 @@ public function testExecuteLocalizedException() $this->request->method('getParams') ->willReturn($params); - $errorMessage1 = 'Requested Quote does not exist'; - $this->quoteLocator->expects(self::once()) - ->method('get') - ->with($reservedOrderId) - ->willThrowException(new LocalizedException(__($errorMessage1))); - - $this->logger->expects(self::once()) - ->method('critical') - ->with('Reserved Order id: ' . $reservedOrderId . ' . Exception message: ' . $errorMessage1) - ->willReturnSelf(); - $errorStatus = Response::STATUS_CODE_500; $responseData = [ 'status' => $errorStatus, - 'message' => $errorMessage1 + 'message' => \__('An error occurred during Shipping Details processing.') ]; $this->response->expects(self::once()) ->method('setHttpResponseCode') @@ -334,7 +309,7 @@ public function testExecuteLocalizedException() ->willReturnSelf(); $content = 'some bad content'; - $this->request->expects(self::once()) + $this->request->expects(self::exactly(2)) ->method('getContent') ->willReturn($content); @@ -368,7 +343,7 @@ public function testExecute() ->willReturn($this->quote); $unSerializedValue = - 'a:6:{s:8:"postCode";s:4:"1234";s:12:"addressLine1";s:4:"city";s:4:"Oslo";s:10:"country_id";s:2:"NO";}'; + '{a:6:{s:8:"postCode";s:4:"1234";s:12:"addressLine1";s:4:"city";s:4:"Oslo";s:10:"country_id";s:2:"NO";}'; $this->request->expects(self::exactly(2)) ->method('getContent') ->willReturn($unSerializedValue); @@ -386,20 +361,15 @@ public function testExecute() ->with($unSerializedValue) ->willReturn($serializedValue); - $this->addressFactory->expects(self::once()) + $this->addressFactory ->method('create') ->willReturn($this->address); $quoteId = 1111; - $this->quote->expects(self::exactly(2)) + $this->quote->expects(self::exactly(1)) ->method('getId') ->willReturn($quoteId); - $this->cartRepository->expects(self::once()) - ->method('get') - ->with($quoteId) - ->willReturn($this->quote); - $this->addressUpdater->expects(self::once()) ->method('fromSourceAddress') ->with($this->quote, $this->address) diff --git a/Test/Unit/Gateway/Command/GatewayCommandTest.php b/Test/Unit/Gateway/Command/GatewayCommandTest.php index 4434d218..6866f134 100755 --- a/Test/Unit/Gateway/Command/GatewayCommandTest.php +++ b/Test/Unit/Gateway/Command/GatewayCommandTest.php @@ -102,7 +102,7 @@ class GatewayCommandTest extends TestCase */ private $objectManagerHelper; - public function setUp() + protected function setUp(): void { $this->transferFactory = $this->getMockBuilder(TransferFactoryInterface::class) ->disableOriginalConstructor() diff --git a/Test/Unit/Gateway/Http/Client/CurlTest.php b/Test/Unit/Gateway/Http/Client/CurlTest.php index 13ac3684..ccc802b2 100644 --- a/Test/Unit/Gateway/Http/Client/CurlTest.php +++ b/Test/Unit/Gateway/Http/Client/CurlTest.php @@ -80,7 +80,7 @@ class CurlTest extends TestCase */ private $moduleMetadata; - public function setUp() + protected function setUp(): void { $this->config = $this->getMockBuilder(ConfigInterface::class) ->disableOriginalConstructor() diff --git a/Test/Unit/Gateway/Response/TransactionHandlerTest.php b/Test/Unit/Gateway/Response/TransactionHandlerTest.php index 63042c96..88f85fb3 100644 --- a/Test/Unit/Gateway/Response/TransactionHandlerTest.php +++ b/Test/Unit/Gateway/Response/TransactionHandlerTest.php @@ -72,7 +72,7 @@ class TransactionHandlerTest extends TestCase */ private $transactionBuilder; - protected function setUp() + protected function setUp(): void { $this->objectManagerHelper = new ObjectManager($this); diff --git a/Test/Unit/Gateway/Transaction/TransactionTest.php b/Test/Unit/Gateway/Transaction/TransactionTest.php index 05744a79..132f32c1 100644 --- a/Test/Unit/Gateway/Transaction/TransactionTest.php +++ b/Test/Unit/Gateway/Transaction/TransactionTest.php @@ -37,7 +37,7 @@ class TransactionTest extends TestCase */ private $objectManagerHelper; - protected function setUp() + protected function setUp(): void { $this->objectManagerHelper = new ObjectManager($this); } diff --git a/Test/Unit/Model/ModuleMetadataTest.php b/Test/Unit/Model/ModuleMetadataTest.php index 3aea1b8f..8f513461 100644 --- a/Test/Unit/Model/ModuleMetadataTest.php +++ b/Test/Unit/Model/ModuleMetadataTest.php @@ -50,7 +50,7 @@ class ModuleMetadataTest extends TestCase */ private $module; - protected function setUp() + protected function setUp(): void { $this->resource = $this->getMockBuilder(ResourceInterface::class) ->disableOriginalConstructor() diff --git a/Test/Unit/Model/TokenProviderTest.php b/Test/Unit/Model/TokenProviderTest.php index a888f013..54a586a0 100644 --- a/Test/Unit/Model/TokenProviderTest.php +++ b/Test/Unit/Model/TokenProviderTest.php @@ -105,7 +105,7 @@ class TokenProviderTest extends TestCase */ private $scopeResolver; - protected function setUp() + protected function setUp(): void { $this->resourceConnection = $this->getMockBuilder(ResourceConnection::class) ->disableOriginalConstructor() diff --git a/composer.json b/composer.json index 9176ffad..5ec313b8 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "magento2-module", "description": "Vipps Payment Method", "license": "proprietary", - "version": "2.4.17", + "version": "2.4.18", "require": { "magento/framework": "103.0.*", "magento/module-sales": "103.0.*", @@ -11,6 +11,11 @@ "magento/module-checkout": "100.4.*", "psr/log": "~1.0" }, + "require-dev": { + "phpmd/phpmd": "@stable", + "phpunit/phpunit": "^9.0", + "squizlabs/php_codesniffer": "@stable" + }, "autoload": { "files": [ "registration.php" diff --git a/etc/module.xml b/etc/module.xml index af60b515..f56c9c42 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -14,7 +14,7 @@ ~ IN THE SOFTWARE. --> - +