10 use Magento\Paypal\Model\Billing\AgreementFactory as BillingAgreementFactory;
27 private $objectManagerHelper;
32 private $billingAgreementFactoryMock;
37 private $specificationMock;
42 private $paymentMethodMock;
52 private $billingAgreementCollectionMock;
57 private $billingAgreementMock;
61 $this->billingAgreementFactoryMock = $this->getMockBuilder(BillingAgreementFactory::class)
62 ->disableOriginalConstructor()
63 ->setMethods([
'create'])
65 $this->specificationMock = $this->getMockBuilder(SpecificationInterface::class)
66 ->getMockForAbstractClass();
67 $this->paymentMethodMock = $this->getMockBuilder(MethodInterface::class)
68 ->getMockForAbstractClass();
69 $this->quoteMock = $this->getMockBuilder(Quote::class)
70 ->disableOriginalConstructor()
71 ->setMethods([
'getCustomerId'])
73 $this->billingAgreementCollectionMock = $this->getMockBuilder(BillingAgreementCollection::class)
74 ->disableOriginalConstructor()
76 $this->billingAgreementMock = $this->getMockBuilder(BillingAgreement::class)
77 ->disableOriginalConstructor()
80 $this->objectManagerHelper =
new ObjectManagerHelper($this);
81 $this->plugin = $this->objectManagerHelper->getObject(
82 SpecificationPlugin::class,
84 'agreementFactory' => $this->billingAgreementFactoryMock
91 $this->setExpectations(
'any',
'any');
94 $this->plugin->afterIsApplicable(
95 $this->specificationMock,
97 $this->paymentMethodMock,
105 $this->setExpectations(
'not_agreement',
'any');
108 $this->plugin->afterIsApplicable(
109 $this->specificationMock,
111 $this->paymentMethodMock,
119 $this->setExpectations(
'paypal_billing_agreement',
null);
122 $this->plugin->afterIsApplicable(
123 $this->specificationMock,
125 $this->paymentMethodMock,
138 $this->setExpectations(
'paypal_billing_agreement', 1);
140 $this->billingAgreementFactoryMock->expects(static::once())
142 ->willReturn($this->billingAgreementMock);
143 $this->billingAgreementMock->expects(static::once())
144 ->method(
'getAvailableCustomerBillingAgreements')
146 ->willReturn($this->billingAgreementCollectionMock);
147 $this->billingAgreementCollectionMock->expects(static::once())
153 $this->plugin->afterIsApplicable($this->specificationMock,
true, $this->paymentMethodMock, $this->quoteMock)
162 return [[0], [1], [2]];
172 private function setExpectations($paymentMethodCode,
$customerId)
174 $this->paymentMethodMock->expects(static::any())
176 ->willReturn($paymentMethodCode);
177 $this->quoteMock->expects(static::any())
178 ->method(
'getCustomerId')
testAfterIsApplicableNoCustomerId()
testAfterIsApplicable($count)
afterIsApplicableDataProvider()
testAfterIsApplicableNotAgreement()
testAfterIsApplicableNotOriginallyApplicable()