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\CompanyUnitAddressLabelDataImport\Communication\Plugin; |
||
9 | |||
10 | use Codeception\Test\Unit; |
||
11 | use Generated\Shared\Transfer\CompanyUnitAddressTransfer; |
||
12 | use Generated\Shared\Transfer\DataImporterConfigurationTransfer; |
||
13 | use Generated\Shared\Transfer\DataImporterReaderConfigurationTransfer; |
||
14 | use Generated\Shared\Transfer\DataImporterReportTransfer; |
||
15 | use Spryker\Zed\CompanyUnitAddressLabelDataImport\Communication\Plugin\CompanyUnitAddressLabelRelationDataImportPlugin; |
||
16 | use Spryker\Zed\CompanyUnitAddressLabelDataImport\CompanyUnitAddressLabelDataImportConfig; |
||
17 | use Spryker\Zed\DataImport\Business\Exception\DataImportException; |
||
18 | |||
19 | /** |
||
20 | * Auto-generated group annotations |
||
21 | * |
||
22 | * @group SprykerTest |
||
23 | * @group Zed |
||
24 | * @group CompanyUnitAddressLabelDataImport |
||
25 | * @group Communication |
||
26 | * @group Plugin |
||
27 | * @group CompanyUnitAddressLabelRelationDataImportPluginTest |
||
28 | * Add your own group annotations below this line |
||
29 | */ |
||
30 | class CompanyUnitAddressLabelRelationDataImportPluginTest extends Unit |
||
31 | { |
||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected const COMPANY_ADDRESS_KEY_1 = 'spryker-address-1'; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected const COMPANY_ADDRESS_KEY_2 = 'spryker-address-2'; |
||
41 | |||
42 | /** |
||
43 | * @var \SprykerTest\Zed\CompanyUnitAddressLabelDataImport\CompanyUnitAddressLabelDataImportCommunicationTester |
||
44 | */ |
||
45 | protected $tester; |
||
46 | |||
47 | /** |
||
48 | * @return void |
||
49 | */ |
||
50 | public function testImportImportsCompanyUnitAddressLabelRelation(): void |
||
51 | { |
||
52 | $this->tester->ensureRelationTableIsEmpty(); |
||
53 | $this->tester->ensureCompanyUnitAddressWithKeyDoesNotExist(static::COMPANY_ADDRESS_KEY_1); |
||
54 | $this->tester->ensureCompanyUnitAddressWithKeyDoesNotExist(static::COMPANY_ADDRESS_KEY_2); |
||
55 | $this->tester->haveCompanyUnitAddress([ |
||
56 | CompanyUnitAddressTransfer::FK_COUNTRY => $this->tester->haveCountry()->getIdCountry(), |
||
57 | CompanyUnitAddressTransfer::KEY => static::COMPANY_ADDRESS_KEY_1, |
||
58 | ]); |
||
59 | $this->tester->haveCompanyUnitAddress([ |
||
60 | CompanyUnitAddressTransfer::FK_COUNTRY => $this->tester->haveCountry()->getIdCountry(), |
||
61 | CompanyUnitAddressTransfer::KEY => static::COMPANY_ADDRESS_KEY_2, |
||
62 | ]); |
||
63 | $this->tester->haveCompanyUnitAddressLabel(['name' => 'label-1']); |
||
64 | $this->tester->haveCompanyUnitAddressLabel(['name' => 'label-2']); |
||
65 | |||
66 | $dataImportConfigurationTransfer = $this->getDataImporterReaderConfigurationTransfer('import/company_unit_address_label_relation.csv'); |
||
67 | |||
68 | $companyUnitAddressLabelDataImportPlugin = new CompanyUnitAddressLabelRelationDataImportPlugin(); |
||
69 | $dataImporterReportTransfer = $companyUnitAddressLabelDataImportPlugin->import($dataImportConfigurationTransfer); |
||
70 | |||
71 | $this->assertInstanceOf(DataImporterReportTransfer::class, $dataImporterReportTransfer); |
||
72 | |||
73 | $this->tester->assertDatabaseTableContainsData(); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @return void |
||
78 | */ |
||
79 | public function testImportThrowsExceptionWhenCompanyUnitAddressNotFound(): void |
||
80 | { |
||
81 | $dataImportConfigurationTransfer = $this->getDataImporterReaderConfigurationTransfer('import/company_unit_address_label_relation_with_invalid_company_unit_address.csv'); |
||
82 | $dataImportConfigurationTransfer->setThrowException(true); |
||
83 | |||
84 | $companyUnitAddressDataImportPlugin = new CompanyUnitAddressLabelRelationDataImportPlugin(); |
||
85 | |||
86 | $this->expectException(DataImportException::class); |
||
87 | $this->expectExceptionMessage('Could not find CompanyUnitAddress with key "invalid-address-key".'); |
||
88 | |||
89 | $companyUnitAddressDataImportPlugin->import($dataImportConfigurationTransfer); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @return void |
||
94 | */ |
||
95 | public function testImportThrowsExceptionWhenCompanyUnitAddressLabelNotFound(): void |
||
96 | { |
||
97 | $dataImportConfigurationTransfer = $this->getDataImporterReaderConfigurationTransfer('import/company_unit_address_label_relation_with_invalid_company_unit_address_label.csv'); |
||
98 | $dataImportConfigurationTransfer->setThrowException(true); |
||
99 | |||
100 | $companyUnitAddressDataImportPlugin = new CompanyUnitAddressLabelRelationDataImportPlugin(); |
||
101 | |||
102 | $this->expectException(DataImportException::class); |
||
103 | $this->expectExceptionMessage('Could not find CompanyUnitAddressLabel with name "invalid-label-name".'); |
||
104 | |||
105 | $companyUnitAddressDataImportPlugin->import($dataImportConfigurationTransfer); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @return void |
||
110 | */ |
||
111 | public function testGetImportTypeReturnsTypeOfImporter(): void |
||
112 | { |
||
113 | $companyUnitAddressLabelRelationDataImportPlugin = new CompanyUnitAddressLabelRelationDataImportPlugin(); |
||
114 | $this->assertSame(CompanyUnitAddressLabelDataImportConfig::IMPORT_TYPE_COMPANY_UNIT_ADDRESS_LABEL_RELATION, $companyUnitAddressLabelRelationDataImportPlugin->getImportType()); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @param string $filePath |
||
119 | * |
||
120 | * @return \Generated\Shared\Transfer\DataImporterConfigurationTransfer |
||
121 | */ |
||
122 | protected function getDataImporterReaderConfigurationTransfer(string $filePath): DataImporterConfigurationTransfer |
||
123 | { |
||
124 | $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer(); |
||
125 | $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . $filePath); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
126 | |||
127 | $dataImportConfigurationTransfer = new DataImporterConfigurationTransfer(); |
||
128 | $dataImportConfigurationTransfer->setReaderConfiguration($dataImporterReaderConfigurationTransfer); |
||
129 | |||
130 | return $dataImportConfigurationTransfer; |
||
131 | } |
||
132 | } |
||
133 |