Skip to content

Commit ac70e00

Browse files
ENGCOM-6669: Unit test for Magento\Fedex\Plugin\Block\Tracking\PopupDeliveryDate #26487
- Merge Pull Request #26487 from karyna-tsymbal-atwix/magento2:unit-test-fedex-plugin-popupDeliveryDate - Merged commits: 1. bf77523 2. 7d316ec 3. 0671b7f 4. 9f6fcbb 5. cdc0834 6. bcc19dc
2 parents 606c3e8 + bcc19dc commit ac70e00

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Fedex\Test\Unit\Plugin\Block\Tracking;
10+
11+
use Magento\Fedex\Model\Carrier;
12+
use Magento\Fedex\Plugin\Block\Tracking\PopupDeliveryDate;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use Magento\Shipping\Block\Tracking\Popup;
15+
use Magento\Shipping\Model\Tracking\Result\Status;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* Unit Test for \Magento\Fedex\Plugin\Block\Tracking\PopupDeliveryDate
21+
*/
22+
class PopupDeliveryDateTest extends TestCase
23+
{
24+
const STUB_CARRIER_CODE_NOT_FEDEX = 'not-fedex';
25+
const STUB_DELIVERY_DATE = '2020-02-02';
26+
const STUB_DELIVERY_TIME = '12:00';
27+
28+
/**
29+
* @var MockObject|PopupDeliveryDate
30+
*/
31+
private $plugin;
32+
33+
/**
34+
* @var MockObject|Status $trackingStatusMock
35+
*/
36+
private $trackingStatusMock;
37+
38+
/**
39+
* @var MockObject|Popup $subjectMock
40+
*/
41+
private $subjectMock;
42+
43+
/**
44+
* @inheritDoc
45+
*/
46+
protected function setUp()
47+
{
48+
$this->trackingStatusMock = $this->getStatusMock();
49+
$this->subjectMock = $this->getPopupMock();
50+
$this->subjectMock->expects($this->once())
51+
->method('getTrackingInfo')
52+
->willReturn([[$this->trackingStatusMock]]);
53+
54+
$objectManagerHelper = new ObjectManager($this);
55+
$this->plugin = $objectManagerHelper->getObject(PopupDeliveryDate::class);
56+
}
57+
58+
/**
59+
* Test the method with Fedex carrier
60+
*/
61+
public function testAfterFormatDeliveryDateTimeWithFedexCarrier()
62+
{
63+
$this->trackingStatusMock->expects($this::once())
64+
->method('getCarrier')
65+
->willReturn(Carrier::CODE);
66+
$this->subjectMock->expects($this->once())->method('formatDeliveryDate');
67+
68+
$this->executeOriginalMethod();
69+
}
70+
71+
/**
72+
* Test the method with a different carrier
73+
*/
74+
public function testAfterFormatDeliveryDateTimeWithOtherCarrier()
75+
{
76+
$this->trackingStatusMock->expects($this::once())
77+
->method('getCarrier')
78+
->willReturn(self::STUB_CARRIER_CODE_NOT_FEDEX);
79+
$this->subjectMock->expects($this->never())->method('formatDeliveryDate');
80+
81+
$this->executeOriginalMethod();
82+
}
83+
84+
/**
85+
* Returns Mock for \Magento\Shipping\Model\Tracking\Result\Status
86+
*
87+
* @return MockObject
88+
*/
89+
private function getStatusMock(): MockObject
90+
{
91+
return $this->getMockBuilder(Status::class)
92+
->disableOriginalConstructor()
93+
->setMethods(['getCarrier'])
94+
->getMock();
95+
}
96+
97+
/**
98+
* Returns Mock for \Magento\Shipping\Block\Tracking\Popup
99+
*
100+
* @return MockObject
101+
*/
102+
private function getPopupMock(): MockObject
103+
{
104+
return $this->getMockBuilder(Popup::class)
105+
->disableOriginalConstructor()
106+
->setMethods(['formatDeliveryDate', 'getTrackingInfo'])
107+
->getMock();
108+
}
109+
110+
/**
111+
* Run plugin's original method
112+
*/
113+
private function executeOriginalMethod()
114+
{
115+
$this->plugin->afterFormatDeliveryDateTime(
116+
$this->subjectMock,
117+
'Test Result',
118+
self::STUB_DELIVERY_DATE,
119+
self::STUB_DELIVERY_TIME
120+
);
121+
}
122+
}

0 commit comments

Comments
 (0)