Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TrackValidatorTest.php
Go to the documentation of this file.
1 <?php
7 
12 
16 class TrackValidatorTest extends \PHPUnit\Framework\TestCase
17 {
21  private $validator;
22 
26  private $shipmentMock;
27 
31  private $shipmentTrackMock;
32 
33  protected function setUp()
34  {
35  $objectManagerHelper = new ObjectManager($this);
36  $this->shipmentMock = $this->getMockBuilder(ShipmentInterface::class)
37  ->getMockForAbstractClass();
38  $this->shipmentTrackMock = $this->getMockBuilder(ShipmentTrackInterface::class)
39  ->getMockForAbstractClass();
40  $this->validator = $objectManagerHelper->getObject(TrackValidator::class);
41  }
42 
43  public function testValidateTrackWithNumber()
44  {
45  $this->shipmentTrackMock->expects($this->once())
46  ->method('getTrackNumber')
47  ->willReturn('12345');
48  $this->shipmentMock->expects($this->exactly(2))
49  ->method('getTracks')
50  ->willReturn([$this->shipmentTrackMock]);
51  $this->assertEquals([], $this->validator->validate($this->shipmentMock));
52  }
53 
55  {
56  $this->shipmentTrackMock->expects($this->once())
57  ->method('getTrackNumber')
58  ->willReturn(null);
59  $this->shipmentMock->expects($this->exactly(2))
60  ->method('getTracks')
61  ->willReturn([$this->shipmentTrackMock]);
62  $this->assertEquals([__('Please enter a tracking number.')], $this->validator->validate($this->shipmentMock));
63  }
64 
66  {
67  $this->shipmentTrackMock->expects($this->never())
68  ->method('getTrackNumber');
69  $this->shipmentMock->expects($this->once())
70  ->method('getTracks')
71  ->willReturn([]);
72  $this->assertEquals([], $this->validator->validate($this->shipmentMock));
73  }
74 }
__()
Definition: __.php:13