Issues (3641)

...rableBundleTemplateSlotDataImportPluginTest.php (3 issues)

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\ConfigurableBundleDataImport\Communication\Plugin;
9
10
use Codeception\Test\Unit;
11
use Generated\Shared\Transfer\DataImporterConfigurationTransfer;
12
use Generated\Shared\Transfer\DataImporterReaderConfigurationTransfer;
13
use Generated\Shared\Transfer\DataImporterReportTransfer;
14
use Spryker\Zed\ConfigurableBundleDataImport\Communication\Plugin\ConfigurableBundleTemplateSlotDataImportPlugin;
15
use Spryker\Zed\ConfigurableBundleDataImport\ConfigurableBundleDataImportConfig;
16
use Spryker\Zed\DataImport\Business\Exception\DataImportException;
17
18
/**
19
 * Auto-generated group annotations
20
 *
21
 * @group SprykerTest
22
 * @group Zed
23
 * @group ConfigurableBundleDataImport
24
 * @group Communication
25
 * @group Plugin
26
 * @group ConfigurableBundleTemplateSlotDataImportPluginTest
27
 * Add your own group annotations below this line
28
 * @group ConfigurableBundle
29
 */
30
class ConfigurableBundleTemplateSlotDataImportPluginTest extends Unit
31
{
32
    /**
33
     * @var string
34
     */
35
    protected const TEST_CONFIGURABLE_BUNDLE_TEMPLATE_KEY = 'test-configurable-bundle-template-key-1';
36
37
    /**
38
     * @var string
39
     */
40
    protected const TEST_PRODUCT_LIST_KEY = 'test-product-list-key';
41
42
    /**
43
     * @var string
44
     */
45
    protected const INCORRECT_CONFIGURABLE_BUNDLE_TEMPLATE_KEY = 'incorrect-configurable-bundle-template-key';
46
47
    /**
48
     * @var string
49
     */
50
    protected const INCORRECT_PRODUCT_LIST_KEY = 'incorrect-product-list-key';
51
52
    /**
53
     * @var \SprykerTest\Zed\ConfigurableBundleDataImport\ConfigurableBundleDataImportCommunicationTester
54
     */
55
    protected $tester;
56
57
    /**
58
     * @return void
59
     */
60
    protected function setUp(): void
61
    {
62
        parent::setUp();
63
64
        $this->tester->ensureConfigurableBundleTablesIsEmpty();
65
    }
66
67
    /**
68
     * @return void
69
     */
70
    public function testImportImportsData(): void
71
    {
72
        // Arrange
73
        $this->tester->createConfigurableBundleTemplate(static::TEST_CONFIGURABLE_BUNDLE_TEMPLATE_KEY);
74
        $this->tester->createProductList(static::TEST_PRODUCT_LIST_KEY);
75
76
        $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer();
77
        $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . 'import/configurable_bundle_template_slot.csv');
0 ignored issues
show
The function codecept_data_dir was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
        $dataImporterReaderConfigurationTransfer->setFileName(/** @scrutinizer ignore-call */ codecept_data_dir() . 'import/configurable_bundle_template_slot.csv');
Loading history...
78
79
        $dataImportConfigurationTransfer = new DataImporterConfigurationTransfer();
80
        $dataImportConfigurationTransfer->setReaderConfiguration($dataImporterReaderConfigurationTransfer);
81
82
        $configurableBundleSlotDataImportPlugin = new ConfigurableBundleTemplateSlotDataImportPlugin();
83
84
        // Act
85
        $dataImporterReportTransfer = $configurableBundleSlotDataImportPlugin->import($dataImportConfigurationTransfer);
86
87
        // Assert
88
        $this->assertInstanceOf(DataImporterReportTransfer::class, $dataImporterReportTransfer);
89
        $this->tester->assertConfigurableBundleTemplateSlotDatabaseTablesContainsData();
90
    }
91
92
    /**
93
     * @return void
94
     */
95
    public function testImportThrowsExceptionWhenConfigurableBundleTemplateNotFoundByKey(): void
96
    {
97
        // Arrange
98
        $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer();
99
        $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . 'import/configurable_bundle_template_slot_configurable_bundle_template_not_found.csv');
0 ignored issues
show
The function codecept_data_dir was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
        $dataImporterReaderConfigurationTransfer->setFileName(/** @scrutinizer ignore-call */ codecept_data_dir() . 'import/configurable_bundle_template_slot_configurable_bundle_template_not_found.csv');
Loading history...
100
101
        $dataImportConfigurationTransfer = new DataImporterConfigurationTransfer();
102
        $dataImportConfigurationTransfer->setReaderConfiguration($dataImporterReaderConfigurationTransfer)
103
            ->setThrowException(true);
104
105
        $configurableBundleSlotDataImportPlugin = new ConfigurableBundleTemplateSlotDataImportPlugin();
106
107
        // Assert
108
        $this->expectException(DataImportException::class);
109
        $this->expectExceptionMessage(sprintf('Could not find configurable bundle template by key "%s"', static::INCORRECT_CONFIGURABLE_BUNDLE_TEMPLATE_KEY));
110
111
        // Act
112
        $configurableBundleSlotDataImportPlugin->import($dataImportConfigurationTransfer);
113
    }
114
115
    /**
116
     * @return void
117
     */
118
    public function testImportThrowsExceptionWhenProductListNotFoundByKey(): void
119
    {
120
        // Arrange
121
        $this->tester->createConfigurableBundleTemplate(static::TEST_CONFIGURABLE_BUNDLE_TEMPLATE_KEY);
122
123
        $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer();
124
        $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . 'import/configurable_bundle_template_slot_product_list_not_found.csv');
0 ignored issues
show
The function codecept_data_dir was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

124
        $dataImporterReaderConfigurationTransfer->setFileName(/** @scrutinizer ignore-call */ codecept_data_dir() . 'import/configurable_bundle_template_slot_product_list_not_found.csv');
Loading history...
125
126
        $dataImportConfigurationTransfer = new DataImporterConfigurationTransfer();
127
        $dataImportConfigurationTransfer->setReaderConfiguration($dataImporterReaderConfigurationTransfer)
128
            ->setThrowException(true);
129
130
        $configurableBundleSlotDataImportPlugin = new ConfigurableBundleTemplateSlotDataImportPlugin();
131
132
        // Assert
133
        $this->expectException(DataImportException::class);
134
        $this->expectExceptionMessage(sprintf('Could not find product list by key "%s"', static::INCORRECT_PRODUCT_LIST_KEY));
135
136
        // Act
137
        $configurableBundleSlotDataImportPlugin->import($dataImportConfigurationTransfer);
138
    }
139
140
    /**
141
     * @return void
142
     */
143
    public function testGetImportTypeReturnsTypeOfImporter(): void
144
    {
145
        // Act
146
        $configurableBundleSlotDataImportPlugin = new ConfigurableBundleTemplateSlotDataImportPlugin();
147
148
        // Assert
149
        $this->assertSame(ConfigurableBundleDataImportConfig::IMPORT_TYPE_CONFIGURABLE_BUNDLE_TEMPLATE_SLOT, $configurableBundleSlotDataImportPlugin->getImportType());
150
    }
151
}
152