Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InventoryTransferValidatorTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 use PHPUnit\Framework\TestCase;
14 
15 class InventoryTransferValidatorTest extends TestCase
16 {
20  private $bulkInventoryTransferValidator;
21 
25  private $defaultSourceProvider;
26 
27  public function setUp()
28  {
29  parent::setUp();
30  $this->bulkInventoryTransferValidator =
31  Bootstrap::getObjectManager()->get(BulkInventoryTransferValidatorInterface::class);
32  $this->defaultSourceProvider = Bootstrap::getObjectManager()->get(DefaultSourceProviderInterface::class);
33  }
34 
38  public function testNotExistingSources()
39  {
40  $skus = ['SKU-1'];
41 
42  $validationResult = $this->bulkInventoryTransferValidator->validate(
43  $skus,
44  'non-existing-source',
45  'another-non-existing-source',
46  false
47  );
48 
49  self::assertFalse(
50  $validationResult->isValid(),
51  'Validation did not detect invalid source codes'
52  );
53 
54  $errors = $validationResult->getErrors();
55 
56  self::assertEquals(
57  'Origin source %sourceCode does not exist',
58  $errors[0]->getText(),
59  'Unexpected error message from validator'
60  );
61  self::assertEquals(
62  'Destination source %sourceCode does not exist',
63  $errors[1]->getText(),
64  'Unexpected error message from validator'
65  );
66  }
67 
71  public function testExistingSources()
72  {
73  $skus = ['SKU-1'];
74 
75  $validationResult = $this->bulkInventoryTransferValidator->validate(
76  $skus,
77  'eu-1',
78  'eu-2',
79  false
80  );
81 
82  self::assertTrue(
83  $validationResult->isValid(),
84  'Validation wrongly detected an unknown source code'
85  );
86  }
87 
91  public function testNonSenseTransfer()
92  {
93  $skus = ['SKU-1'];
94 
95  $validationResult = $this->bulkInventoryTransferValidator->validate(
96  $skus,
97  'eu-1',
98  'eu-1',
99  false
100  );
101 
102  $errors = $validationResult->getErrors();
103 
104  self::assertFalse(
105  $validationResult->isValid(),
106  'Validation did not detect non sense transfer'
107  );
108 
109  self::assertEquals(
110  'Cannot transfer a source on itself',
111  $errors[0]->getText(),
112  'Unexpected error message from validator'
113  );
114  }
115 }
foreach($websiteCodes as $websiteCode) $skus
$errors
Definition: overview.phtml:9