Skip to content

Commit a60a22d

Browse files
committed
unit tests coverage
1 parent 06917dd commit a60a22d

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Paypal\Test\Unit\Plugin;
9+
10+
use PHPUnit\Framework\MockObject\Exception;
11+
use PHPUnit\Framework\TestCase;
12+
use Magento\Quote\Model\CustomerManagement;
13+
use Magento\Quote\Model\Quote;
14+
use Magento\Paypal\Plugin\CustomerManagementPlugin;
15+
use Magento\Quote\Model\Quote\Payment;
16+
17+
class CustomerManagementPluginTest extends TestCase
18+
{
19+
/**
20+
* @var CustomerManagementPlugin
21+
*/
22+
private $plugin;
23+
24+
/**
25+
* @var CustomerManagement
26+
*/
27+
private $customerManagement;
28+
29+
/**
30+
* @var Payment
31+
*/
32+
private $paymentMethod;
33+
34+
/**
35+
* @var Quote
36+
*/
37+
private $quote;
38+
39+
/**
40+
* @var callable
41+
*/
42+
private $proceed;
43+
44+
/**
45+
* @throws Exception
46+
*/
47+
protected function setUp(): void
48+
{
49+
$this->quote = $this->createMock(Quote::class);
50+
$this->paymentMethod = $this->createMock(Payment::class);
51+
$this->customerManagement = $this->createMock(CustomerManagement::class);
52+
$this->plugin = new CustomerManagementPlugin();
53+
}
54+
55+
/**
56+
* Test to skip address validation for PayPal payment method to guest customer
57+
*/
58+
public function testAroundValidateAddressesWithPaypal()
59+
{
60+
$this->paymentMethod->method('getMethod')->willReturn('paypal_express');
61+
$this->quote->method('getPayment')->willReturn($this->paymentMethod);
62+
$this->quote->method('getCustomerIsGuest')->willReturn(true);
63+
64+
$this->proceed = function ($quote) {
65+
$this->assertSame($quote, $this->quote);
66+
};
67+
$this->plugin->aroundValidateAddresses($this->customerManagement, $this->proceed, $this->quote);
68+
}
69+
70+
/**
71+
* Test to proceed with address validation for other payment methods
72+
*/
73+
public function testAroundValidateAddressesWithOtherPaymentMethod()
74+
{
75+
$this->paymentMethod->method('getMethod')->willReturn('checkmo');
76+
$this->quote->method('getPayment')->willReturn($this->paymentMethod);
77+
$this->quote->method('getCustomerIsGuest')->willReturn(true);
78+
$this->proceed = function ($quote) {
79+
$this->assertSame($quote, $this->quote);
80+
};
81+
$this->plugin->aroundValidateAddresses($this->customerManagement, $this->proceed, $this->quote);
82+
}
83+
84+
/**
85+
* Test to proceed with address validation when PayPal is selected and customer is not a guest
86+
*/
87+
public function testAroundValidateAddressesWithPaypalAndLoggedInCustomer()
88+
{
89+
$this->paymentMethod->method('getMethod')->willReturn('paypal_express');
90+
$this->quote->method('getPayment')->willReturn($this->paymentMethod);
91+
$this->quote->method('getCustomerIsGuest')->willReturn(false);
92+
$this->proceed = function ($quote) {
93+
$this->assertSame($quote, $this->quote);
94+
};
95+
$this->plugin->aroundValidateAddresses($this->customerManagement, $this->proceed, $this->quote);
96+
}
97+
}

0 commit comments

Comments
 (0)