1 | <?php |
||
2 | |||
3 | /** |
||
4 | * MIT License |
||
5 | * For full license information, please view the LICENSE file that was distributed with this source code. |
||
6 | */ |
||
7 | |||
8 | namespace SprykerTest\Zed\CompanyUserDataImport\Communication\Plugin\DataImport; |
||
9 | |||
10 | use Codeception\Test\Unit; |
||
11 | use Generated\Shared\Transfer\CompanyTransfer; |
||
12 | use Generated\Shared\Transfer\CustomerTransfer; |
||
13 | use Generated\Shared\Transfer\DataImporterConfigurationTransfer; |
||
14 | use Generated\Shared\Transfer\DataImporterReaderConfigurationTransfer; |
||
15 | use Generated\Shared\Transfer\DataImporterReportTransfer; |
||
16 | use Spryker\Zed\CompanyUserDataImport\Communication\Plugin\DataImport\CompanyUserDataImportPlugin; |
||
17 | use Spryker\Zed\CompanyUserDataImport\CompanyUserDataImportConfig; |
||
18 | use Spryker\Zed\DataImport\Business\Exception\DataImportException; |
||
19 | |||
20 | /** |
||
21 | * Auto-generated group annotations |
||
22 | * |
||
23 | * @group SprykerTest |
||
24 | * @group Zed |
||
25 | * @group CompanyUserDataImport |
||
26 | * @group Communication |
||
27 | * @group Plugin |
||
28 | * @group DataImport |
||
29 | * @group CompanyUserDataImportPluginTest |
||
30 | * Add your own group annotations below this line |
||
31 | */ |
||
32 | class CompanyUserDataImportPluginTest extends Unit |
||
33 | { |
||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected const CUSTOMER_REFERENCE_1 = 'DE--8'; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | protected const CUSTOMER_REFERENCE_2 = 'DE--9'; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | protected const COMPANY_KEY = 'Test_ltd'; |
||
48 | |||
49 | /** |
||
50 | * @var \SprykerTest\Zed\CompanyUserDataImport\CompanyUserDataImportCommunicationTester |
||
51 | */ |
||
52 | protected $tester; |
||
53 | |||
54 | /** |
||
55 | * @return void |
||
56 | */ |
||
57 | public function testImportImportsData(): void |
||
58 | { |
||
59 | // Arrange |
||
60 | $this->tester->truncateCompanyUsers(['ComUser--1', 'ComUser--2']); |
||
61 | $this->tester->assertCompanyUserTableDoesNotContainsRecords(['ComUser--1', 'ComUser--2']); |
||
62 | $this->prepareTestData(); |
||
63 | |||
64 | $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer(); |
||
65 | $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . 'import/company_user.csv'); |
||
66 | |||
67 | $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer()) |
||
68 | ->setReaderConfiguration($dataImporterReaderConfigurationTransfer); |
||
69 | |||
70 | // Act |
||
71 | $dataImportPlugin = new CompanyUserDataImportPlugin(); |
||
72 | $dataImporterReportTransfer = $dataImportPlugin->import($dataImportConfigurationTransfer); |
||
73 | |||
74 | // Assert |
||
75 | $this->assertInstanceOf(DataImporterReportTransfer::class, $dataImporterReportTransfer); |
||
76 | $this->assertTrue($dataImporterReportTransfer->getIsSuccess()); |
||
77 | $this->tester->assertCompanyUserTableContainRecords(['ComUser--1', 'ComUser--2']); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @return void |
||
82 | */ |
||
83 | public function testImportWithInvalidDataThrowsException(): void |
||
84 | { |
||
85 | // Arrange |
||
86 | $this->tester->truncateCompanyUsers(['ComUser--1', 'ComUser--2']); |
||
87 | $this->tester->assertCompanyUserTableDoesNotContainsRecords(['ComUser--1', 'ComUser--2']); |
||
88 | $this->prepareTestData(); |
||
89 | |||
90 | $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer(); |
||
91 | $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . 'import/company_user_with_invalid_company.csv'); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
92 | |||
93 | $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer()) |
||
94 | ->setReaderConfiguration($dataImporterReaderConfigurationTransfer) |
||
95 | ->setThrowException(true); |
||
96 | $dataImportPlugin = new CompanyUserDataImportPlugin(); |
||
97 | |||
98 | // Assert |
||
99 | $this->expectException(DataImportException::class); |
||
100 | |||
101 | // Act |
||
102 | $dataImportPlugin->import($dataImportConfigurationTransfer); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @return void |
||
107 | */ |
||
108 | public function testGetImportTypeReturnsTypeOfImporter(): void |
||
109 | { |
||
110 | $dataImportPlugin = new CompanyUserDataImportPlugin(); |
||
111 | $this->assertSame(CompanyUserDataImportConfig::IMPORT_TYPE_COMPANY_USER, $dataImportPlugin->getImportType()); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @return void |
||
116 | */ |
||
117 | protected function prepareTestData(): void |
||
118 | { |
||
119 | $this->tester->createCustomerPreservingCustomerReference([ |
||
120 | CustomerTransfer::CUSTOMER_REFERENCE => static::CUSTOMER_REFERENCE_1, |
||
121 | ]); |
||
122 | |||
123 | $this->tester->createCustomerPreservingCustomerReference([ |
||
124 | CustomerTransfer::CUSTOMER_REFERENCE => static::CUSTOMER_REFERENCE_2, |
||
125 | ]); |
||
126 | |||
127 | $this->tester->haveCompany([ |
||
128 | CompanyTransfer::KEY => static::COMPANY_KEY, |
||
129 | ]); |
||
130 | } |
||
131 | } |
||
132 |