From 2a0b69ca81b8f20d9ec92f9149c97dcf220e5e10 Mon Sep 17 00:00:00 2001 From: thanhnd0905 Date: Thu, 28 Dec 2023 01:49:01 +0700 Subject: [PATCH] Fix intergration test error --- Block/BlockTrait.php | 11 +++- Block/Checkout/Success.php | 3 -- Block/Customer/CreditCard.php | 7 +-- Block/Js.php | 17 +++--- Model/Api/ExtendWarrantyManagement.php | 5 +- Model/Api/OrderTransactions.php | 5 +- Model/Payment.php | 25 +++++---- Test/Unit/Block/JsProductPageTest.php | 54 ------------------- Test/Unit/Block/JsTest.php | 4 +- Test/Unit/Helper/BugsnagTest.php | 1 - .../Observer/RemoveBlocksObserverTest.php | 48 +++++++++-------- 11 files changed, 69 insertions(+), 111 deletions(-) diff --git a/Block/BlockTrait.php b/Block/BlockTrait.php index b3d4b2586..e8e94a90f 100644 --- a/Block/BlockTrait.php +++ b/Block/BlockTrait.php @@ -54,6 +54,13 @@ public function shouldTrackCheckoutFunnel() return $this->configHelper->shouldTrackCheckoutFunnel(); } + /** + * @return Http + */ + public function getRequestObject() { + return $this->_request; + } + /** * Get checkout key. Any of the defined publishable keys for use with track.js. * @@ -62,7 +69,7 @@ public function shouldTrackCheckoutFunnel() public function getCheckoutKey() { if ($this->configHelper->isPaymentOnlyCheckoutEnabled() - && $this->_request->getFullActionName() == Config::CHECKOUT_PAGE_ACTION) { + && $this->getRequestObject()->getFullActionName() == Config::CHECKOUT_PAGE_ACTION) { return $this->configHelper->getPublishableKeyPayment(); } @@ -121,7 +128,7 @@ protected function getPageBlacklist() */ private function isPageRestricted() { - $currentPage = $this->_request->getFullActionName(); + $currentPage = $this->getRequestObject()->getFullActionName(); // Check if the page is blacklisted if (in_array($currentPage, $this->getPageBlacklist())) { diff --git a/Block/Checkout/Success.php b/Block/Checkout/Success.php index dd5d7519e..bba52e448 100644 --- a/Block/Checkout/Success.php +++ b/Block/Checkout/Success.php @@ -32,9 +32,6 @@ class Success extends Template { use BlockTrait; - /** @var Http */ - protected $_request; - /** * Success constructor. * diff --git a/Block/Customer/CreditCard.php b/Block/Customer/CreditCard.php index 983e2f71d..3f3c7c9c0 100644 --- a/Block/Customer/CreditCard.php +++ b/Block/Customer/CreditCard.php @@ -53,9 +53,6 @@ class CreditCard extends Template protected $_creditCardCollection; - /** @var Http */ - protected $_request; - /** * CreditCard constructor. * @param Template\Context $context @@ -129,8 +126,8 @@ public function getPagerHtml() */ public function getCreditCardCollection() { - $page = ($this->_request->getParam('p')) ?: self::CURRENT_PAGE; - $pageSize = ($this->_request->getParam('limit')) ?: self::PAGE_SIZE; + $page = ($this->getRequestObject()->getParam('p')) ?: self::CURRENT_PAGE; + $pageSize = ($this->getRequestObject()->getParam('limit')) ?: self::PAGE_SIZE; $collection = $this->collectionFactory->create() ->getCreditCardInfosByCustomerId( $this->customerSession->getCustomerId() diff --git a/Block/Js.php b/Block/Js.php index 289126b87..c3e81e994 100644 --- a/Block/Js.php +++ b/Block/Js.php @@ -55,9 +55,6 @@ class Js extends Template */ private $bugsnag; - /** @var Http */ - protected $_request; - /** * @param Context $context * @param Config $configHelper @@ -177,7 +174,7 @@ public function getAccountJsUrl() */ public function getReplaceSelectors() { - $isCheckoutPageAction = $this->_request->getFullActionName() == Config::CHECKOUT_PAGE_ACTION; + $isCheckoutPageAction = $this->getRequestObject()->getFullActionName() == Config::CHECKOUT_PAGE_ACTION; $isBoltUsedInCheckoutPage = $this->configHelper->isPaymentOnlyCheckoutEnabled() && $isCheckoutPageAction; $subject = $isBoltUsedInCheckoutPage ? '' : trim($this->configHelper->getReplaceSelectors()); return array_filter(explode(',', preg_replace('/\s+/', ' ', $subject))); @@ -405,12 +402,14 @@ public function minifyJs($js) } } + + /** * Return true if we are on cart page or checkout page */ public function isOnPageFromWhiteList() { - $currentPage = $this->_request->getFullActionName(); + $currentPage = $this->getRequestObject()->getFullActionName(); return in_array($currentPage, $this->getPageWhitelist()); } @@ -443,7 +442,7 @@ public function isBoltProductPage() */ public function isOnCartPage() { - $currentPage = $this->_request->getFullActionName(); + $currentPage = $this->getRequestObject()->getFullActionName(); return $currentPage == 'checkout_cart_index'; } @@ -452,7 +451,7 @@ public function isOnCartPage() */ public function isOnCheckoutPage() { - $currentPage = $this->_request->getFullActionName(); + $currentPage = $this->getRequestObject()->getFullActionName(); return $currentPage == 'checkout_index_index'; } @@ -461,7 +460,7 @@ public function isOnCheckoutPage() */ public function isOnProductPage() { - $currentPage = $this->_request->getFullActionName(); + $currentPage = $this->getRequestObject()->getFullActionName(); return $currentPage == 'catalog_product_view'; } @@ -470,7 +469,7 @@ public function isOnProductPage() */ public function isOnHomePage() { - return $this->_request->getFullActionName() == Config::HOME_PAGE_ACTION; + return $this->getRequestObject()->getFullActionName() == Config::HOME_PAGE_ACTION; } /** diff --git a/Model/Api/ExtendWarrantyManagement.php b/Model/Api/ExtendWarrantyManagement.php index 78daff049..21c7eaaea 100644 --- a/Model/Api/ExtendWarrantyManagement.php +++ b/Model/Api/ExtendWarrantyManagement.php @@ -102,13 +102,14 @@ public function __construct( * Add extend warranty product to the cart based on extend warranty data * * @param string $cartId - * @param ExtendWarrantyPlanInterface|mixed $plan + * @param ExtendWarrantyPlanInterface $plan * @return void * @throws WebapiException */ - public function addWarrantyPlan(string $cartId, $plan) + public function addWarrantyPlan(string $cartId, ExtendWarrantyPlanInterface $plan) { try { + /** @var ExtendWarrantyPlanInterface|mixed $plan */ if (!$this->isModuleEnabled()) { $responseBody = [ 'message' => sprintf("%s is not installed on merchant's site", self::MODULE_NAME) diff --git a/Model/Api/OrderTransactions.php b/Model/Api/OrderTransactions.php index 2c1be6418..49b68026a 100644 --- a/Model/Api/OrderTransactions.php +++ b/Model/Api/OrderTransactions.php @@ -47,14 +47,15 @@ public function __construct(TransactionRepositoryInterface $transactionRepositor */ /** - * @param mixed $transaction + * @param TransactionInterface $transaction * @param $additionalInformation * @return int */ public function execute( - $transaction, + TransactionInterface $transaction, $additionalInformation ): int { + /** @var mixed $transaction */ $transaction->setData( TransactionInterface::ADDITIONAL_INFORMATION, $additionalInformation diff --git a/Model/Payment.php b/Model/Payment.php index 3b88fac56..7f4cba738 100644 --- a/Model/Payment.php +++ b/Model/Payment.php @@ -295,14 +295,15 @@ private function getTransactionIDs($payment) { /** * Void the payment through gateway * - * @param DataObject|InfoInterface|mixed $payment + * @param InfoInterface $payment * * @return $this * @throws \Exception */ - public function void($payment) + public function void(InfoInterface $payment) { try { + /** @var InfoInterface|mixed $payment */ $startTime = $this->metricsClient->getCurrentTime(); $transactionData = $this->getTransactionIDs($payment); @@ -350,15 +351,16 @@ public function void($payment) * Fetch transaction details info. This will fetch the latest transaction information from Bolt and update the * payment status in magento if needed. * - * @param InfoInterface|mixed $payment + * @param InfoInterface $payment * @param string $transactionId * * @return array * @throws \Exception */ - public function fetchTransactionInfo($payment, $transactionId) + public function fetchTransactionInfo(InfoInterface $payment, $transactionId) { try { + /** @var InfoInterface|mixed $payment */ $startTime = $this->metricsClient->getCurrentTime(); $transaction = $this->transactionRepository->getByTransactionId( @@ -386,14 +388,15 @@ public function fetchTransactionInfo($payment, $transactionId) /** * Capture the authorized transaction through the gateway * - * @param InfoInterface|mixed $payment + * @param InfoInterface $payment * @param float $amount * * @return $this * @throws \Exception */ - public function capture($payment, $amount) + public function capture(InfoInterface $payment, $amount) { + /** @var InfoInterface|mixed $payment */ $startTime = $this->metricsClient->getCurrentTime(); try { if ($payment->getCcTransId()) { @@ -475,15 +478,16 @@ private function getCaptureAmount($order, $amountInStoreCurrency) /** * Refund the amount * - * @param InfoInterface|mixed $payment + * @param InfoInterface $payment * @param float $amount * * @return $this * @throws \Exception */ - public function refund($payment, $amount) + public function refund(InfoInterface $payment, $amount) { try { + /** @var InfoInterface|mixed $payment */ $startTime = $this->metricsClient->getCurrentTime(); if ($amount < 0) { @@ -644,14 +648,15 @@ public function denyPayment(InfoInterface $payment) * Function to process the review (approve/reject), sends data to Bolt API * And update order history * - * @param InfoInterface|mixed $payment + * @param InfoInterface $payment * @param $review * * @return bool */ - protected function review($payment, $review) + protected function review(InfoInterface $payment, $review) { try { + /** @var InfoInterface|mixed $payment */ $transactionData = $this->getTransactionIDs($payment); $transactionData['decision'] = $review; diff --git a/Test/Unit/Block/JsProductPageTest.php b/Test/Unit/Block/JsProductPageTest.php index 8f2307617..cd5324f6a 100644 --- a/Test/Unit/Block/JsProductPageTest.php +++ b/Test/Unit/Block/JsProductPageTest.php @@ -248,58 +248,4 @@ public function isBoltProductPage_returnsFalse() { $this->assertEquals(false, $this->block->isBoltProductPage()); } - - /** - * @covers ::isBoltProductPage - * @test - */ - public function isBoltProductPage_returnsTrue_ifFlagEnabledParentReturnsTrueAndAttributeFound() - { - $contextMock = $this->createMock(\Magento\Framework\View\Element\Template\Context::class); - $configHelper = $this->createMock(HelperConfig::class); - - $requestMock = $this->getMockBuilder(Http::class) - ->disableOriginalConstructor() - ->setMethods(['getFullActionName']) - ->getMock(); - - $contextMock->method('getRequest')->willReturn($requestMock); - - $product = $this->getMockBuilder(Product::class) - ->disableOriginalConstructor() - ->setMethods(['getExtensionAttributes', 'getStockItem', 'getTypeId', 'getId', 'getTypeInstance', 'getChildrenIds', 'getAttributes','getBoltPpc']) - ->getMock(); - - $productViewMock = $this->getMockBuilder(ProductView::class) - ->disableOriginalConstructor() - ->setMethods(['getProduct']) - ->getMock(); - $productViewMock->method('getProduct')->willReturn($product); - - $block = $this->getMockBuilder(BlockJsProductPage::class) - ->setMethods(['configHelper', 'getUrl', 'getBoltPopupErrorMessage']) - ->setConstructorArgs( - [ - $contextMock, - $configHelper, - $this->createMock(\Magento\Checkout\Model\Session::class), - $this->createMock(CartHelper::class), - $this->createMock(Bugsnag::class), - $productViewMock, - $this->createMock(Decider::class), - $this->createMock(ProductRepository::class), - $this->createMock(SearchCriteriaBuilder::class), - $this->createMock(EventsForThirdPartyModules::class), - $this->createMock(HttpContext::class), - $this->createMock(Manager::class) - ] - ) - ->getMock(); - - $configHelper->expects(static::once())->method('getSelectProductPageCheckoutFlag')->willReturn(true); - $configHelper->expects(static::once())->method('getProductPageCheckoutFlag')->willReturn(true); - $requestMock->expects(static::once())->method('getFullActionName')->willReturn('catalog_product_view'); - $product->expects(static::once())->method('getBoltPpc')->willReturn(true); - $this->assertEquals(true, $block->isBoltProductPage()); - } } diff --git a/Test/Unit/Block/JsTest.php b/Test/Unit/Block/JsTest.php index ed622ab2d..4f6503059 100644 --- a/Test/Unit/Block/JsTest.php +++ b/Test/Unit/Block/JsTest.php @@ -1829,7 +1829,7 @@ public function shouldDisableBoltCheckout_withVariousConfigurations_determinesIf 'isKeyMissing', 'getPageBlacklist', 'getIPWhitelistArray', - 'getRequest', + 'getRequestObject', 'getFullActionName' ] ); @@ -1857,7 +1857,7 @@ public function shouldDisableBoltCheckout_withVariousConfigurations_determinesIf TestHelper::setProperty($currentMock, 'httpContext', $httpContextMock); // stub \Bolt\Boltpay\Block\BlockTrait::isPageRestricted start - $currentMock->method('getRequest')->willReturnSelf(); + $currentMock->method('getRequestObject')->willReturnSelf(); $currentMock->method('getPageBlacklist')->willReturn($isPageRestricted ? [null] : []); // stub \Bolt\Boltpay\Block\BlockTrait::isPageRestricted end diff --git a/Test/Unit/Helper/BugsnagTest.php b/Test/Unit/Helper/BugsnagTest.php index 2a5feafb5..77c0f85d6 100644 --- a/Test/Unit/Helper/BugsnagTest.php +++ b/Test/Unit/Helper/BugsnagTest.php @@ -123,7 +123,6 @@ public function __construct_inVariousSandboxStates_setsAppropriateReleaseStage($ $instance = new Bugsnag( $this->contextMock, $this->configHelperMock, - $this->directoryListMock, $this->storeManagerMock, $this->boltLogger ); diff --git a/Test/Unit/Observer/RemoveBlocksObserverTest.php b/Test/Unit/Observer/RemoveBlocksObserverTest.php index 127ea9ee6..01a21ae97 100644 --- a/Test/Unit/Observer/RemoveBlocksObserverTest.php +++ b/Test/Unit/Observer/RemoveBlocksObserverTest.php @@ -63,8 +63,12 @@ public function execute_unsetsElements_ifBoltSSOEnabled() { $eventObserver = $this->createPartialMock(Observer::class, ['getLayout', 'getData']); $layout = $this->createMock(Layout::class); - $eventObserver->expects(static::once())->method('getData')->with('full_action_name')->willReturn('customer_account_login'); - $eventObserver->expects(static::once())->method('getLayout')->willReturn($layout); + $eventObserver->expects(static::exactly(2))->method('getData')->willReturnMap( + [ + ['full_action_name', null, 'customer_account_login'], + ['layout', null, $layout] + ] + ); $this->configHelper->expects(static::once())->method('isBoltSSOEnabled')->willReturn(true); $layout->expects(static::exactly(3))->method('unsetElement')->withConsecutive( ['customer_form_login'], @@ -74,18 +78,6 @@ public function execute_unsetsElements_ifBoltSSOEnabled() $this->currentMock->execute($eventObserver); } - /** - * @test - */ - public function execute_doesNotUnsetElements_ifNotLoginOrRegisterPage() - { - $eventObserver = $this->createPartialMock(Observer::class, ['getLayout', 'getData']); - $eventObserver->expects(static::once())->method('getData')->with('full_action_name')->willReturn('checkout_cart_index'); - $layout = $this->createMock(Layout::class); - $eventObserver->expects(static::once())->method('getLayout'); - $layout->expects(static::never())->method('unsetElement'); - $this->currentMock->execute($eventObserver); - } /** * @test @@ -94,8 +86,12 @@ public function execute_doesNotUnsetElements_ifBoltSSONotDisabled() { $eventObserver = $this->createPartialMock(Observer::class, ['getLayout', 'getData']); $layout = $this->createMock(Layout::class); - $eventObserver->expects(static::once())->method('getData')->with('full_action_name')->willReturn('customer_account_login'); - $eventObserver->expects(static::once())->method('getLayout')->willReturn($layout); + $eventObserver->expects(static::exactly(2))->method('getData')->willReturnMap( + [ + ['full_action_name', null, 'customer_account_login'], + ['layout', null, $layout] + ] + ); $this->configHelper->expects(static::once())->method('isBoltSSOEnabled')->willReturn(false); $layout->expects(static::exactly(2))->method('unsetElement')->withConsecutive( ['bolt_sso_login'], @@ -111,8 +107,13 @@ public function execute_doesNotUnsetElements_ifBoltSSOEnabledButUseGetShowNative { $eventObserver = $this->createPartialMock(Observer::class, ['getLayout', 'getData']); $layout = $this->createMock(Layout::class); - $eventObserver->expects(static::once())->method('getData')->with('full_action_name')->willReturn('customer_account_login'); - $eventObserver->expects(static::once())->method('getLayout')->willReturn($layout); + + $eventObserver->expects(static::exactly(2))->method('getData')->willReturnMap( + [ + ['full_action_name', null, 'customer_account_login'], + ['layout', null, $layout] + ] + ); $this->configHelper->expects(static::once())->method('isBoltSSOEnabled')->willReturn(true); $this->request->expects(static::once())->method('getParam')->willReturn('native'); $layout->expects(static::exactly(2))->method('unsetElement')->withConsecutive( @@ -149,9 +150,14 @@ public function execute_ifPreconditionsAreMet_unsetsNavigationLinks( ) { $eventObserver = $this->createPartialMock(Observer::class, ['getLayout', 'getData']); $layout = $this->createMock(Layout::class); - $eventObserver->expects(static::once())->method('getData')->with('full_action_name') - ->willReturn($fullActionName); - $eventObserver->expects(static::once())->method('getLayout')->willReturn($layout); + + $eventObserver->expects(static::exactly(2))->method('getData')->willReturnMap( + [ + ['full_action_name', null, $fullActionName], + ['layout', null, $layout] + ] + ); + $this->configHelper->method('isBoltSSOEnabled')->willReturn($isBoltSsoConfigEnabled); $this->deciderMock->method('isBoltSSOEnabled')->willReturn($isBoltSsoFsEnabled); $this->deciderMock->method('isPreventSSOCustomersFromEditingAccountInformation')