Skip to content

Commit

Permalink
Fix intergration test error
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmccombs1 committed Dec 28, 2023
1 parent fca7e0b commit 2a0b69c
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 111 deletions.
11 changes: 9 additions & 2 deletions Block/BlockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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();
}

Expand Down Expand Up @@ -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())) {
Expand Down
3 changes: 0 additions & 3 deletions Block/Checkout/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class Success extends Template
{
use BlockTrait;

/** @var Http */
protected $_request;

/**
* Success constructor.
*
Expand Down
7 changes: 2 additions & 5 deletions Block/Customer/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ class CreditCard extends Template

protected $_creditCardCollection;

/** @var Http */
protected $_request;

/**
* CreditCard constructor.
* @param Template\Context $context
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 8 additions & 9 deletions Block/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ class Js extends Template
*/
private $bugsnag;

/** @var Http */
protected $_request;

/**
* @param Context $context
* @param Config $configHelper
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -443,7 +442,7 @@ public function isBoltProductPage()
*/
public function isOnCartPage()
{
$currentPage = $this->_request->getFullActionName();
$currentPage = $this->getRequestObject()->getFullActionName();
return $currentPage == 'checkout_cart_index';
}

Expand All @@ -452,7 +451,7 @@ public function isOnCartPage()
*/
public function isOnCheckoutPage()
{
$currentPage = $this->_request->getFullActionName();
$currentPage = $this->getRequestObject()->getFullActionName();
return $currentPage == 'checkout_index_index';
}

Expand All @@ -461,7 +460,7 @@ public function isOnCheckoutPage()
*/
public function isOnProductPage()
{
$currentPage = $this->_request->getFullActionName();
$currentPage = $this->getRequestObject()->getFullActionName();
return $currentPage == 'catalog_product_view';
}

Expand All @@ -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;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions Model/Api/ExtendWarrantyManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions Model/Api/OrderTransactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 15 additions & 10 deletions Model/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand Down
54 changes: 0 additions & 54 deletions Test/Unit/Block/JsProductPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions Test/Unit/Block/JsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,7 @@ public function shouldDisableBoltCheckout_withVariousConfigurations_determinesIf
'isKeyMissing',
'getPageBlacklist',
'getIPWhitelistArray',
'getRequest',
'getRequestObject',
'getFullActionName'
]
);
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion Test/Unit/Helper/BugsnagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public function __construct_inVariousSandboxStates_setsAppropriateReleaseStage($
$instance = new Bugsnag(
$this->contextMock,
$this->configHelperMock,
$this->directoryListMock,
$this->storeManagerMock,
$this->boltLogger
);
Expand Down
Loading

0 comments on commit 2a0b69c

Please sign in to comment.