Issues (3641)

DataImport/CountryStoreDataImportPluginTest.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\CountryDataImport\Communication\Plugin\DataImport;
9
10
use Codeception\Test\Unit;
11
use Generated\Shared\Transfer\CountryTransfer;
12
use Generated\Shared\Transfer\DataImporterConfigurationTransfer;
13
use Generated\Shared\Transfer\DataImporterReaderConfigurationTransfer;
14
use Generated\Shared\Transfer\DataImporterReportTransfer;
15
use Generated\Shared\Transfer\StoreTransfer;
16
use Spryker\Zed\CountryDataImport\Communication\Plugin\DataImport\CountryStoreDataImportPlugin;
17
use Spryker\Zed\CountryDataImport\CountryDataImportConfig;
18
use Spryker\Zed\DataImport\Business\Exception\DataImportException;
19
20
/**
21
 * Auto-generated group annotations
22
 *
23
 * @group SprykerTest
24
 * @group Zed
25
 * @group CountryDataImport
26
 * @group Communication
27
 * @group Plugin
28
 * @group DataImport
29
 * @group CountryStoreDataImportPluginTest
30
 * Add your own group annotations below this line
31
 */
32
class CountryStoreDataImportPluginTest extends Unit
33
{
34
    /**
35
     * @var string
36
     */
37
    protected const STORE_NAME_DE = 'DE';
38
39
    /**
40
     * @var string
41
     */
42
    protected const COUNTRY_CODE_DE = 'DE';
43
44
    /**
45
     * @var \SprykerTest\Zed\CountryDataImport\CountryDataImportCommunicationTester
46
     */
47
    protected $tester;
48
49
    /**
50
     * @return void
51
     */
52
    public function testCountryStoreImportImportsData(): void
53
    {
54
        // Arrange
55
        $this->tester->ensureCountryStoreDatabaseTableIsEmpty();
56
57
        $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer();
58
        $dataImporterReaderConfigurationTransfer->setFileName(codecept_data_dir() . 'import/country_store.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

58
        $dataImporterReaderConfigurationTransfer->setFileName(/** @scrutinizer ignore-call */ codecept_data_dir() . 'import/country_store.csv');
Loading history...
59
60
        $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer())
61
            ->setReaderConfiguration($dataImporterReaderConfigurationTransfer)
62
            ->setThrowException(true);
63
64
        $countryStoreDataImportPlugin = new CountryStoreDataImportPlugin();
65
66
        // Act
67
        $dataImporterReportTransfer = $countryStoreDataImportPlugin->import($dataImportConfigurationTransfer);
68
69
        // Assert
70
        $this->assertInstanceOf(DataImporterReportTransfer::class, $dataImporterReportTransfer);
71
        $this->assertGreaterThan(0, $this->tester->getCountryStoreRelationsCount());
72
    }
73
74
    /**
75
     * @return void
76
     */
77
    public function testImportWithUnknownCountryCode(): void
78
    {
79
        $this->expectException(DataImportException::class);
80
        $this->expectExceptionMessage('Country not found: YY');
81
82
        // Arrange
83
        $this->tester->haveStore([StoreTransfer::NAME => static::STORE_NAME_DE]);
84
85
        $dataImporterReaderConfigurationTransfer = (new DataImporterReaderConfigurationTransfer())
86
            ->setFileName(codecept_data_dir() . 'import/country_store_with_unknown_country_code.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

86
            ->setFileName(/** @scrutinizer ignore-call */ codecept_data_dir() . 'import/country_store_with_unknown_country_code.csv');
Loading history...
87
88
        $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer())
89
            ->setReaderConfiguration($dataImporterReaderConfigurationTransfer)
90
            ->setThrowException(true);
91
92
        $countryStoreDataImportPlugin = new CountryStoreDataImportPlugin();
93
94
        // Act
95
        $countryStoreDataImportPlugin->import($dataImportConfigurationTransfer);
96
    }
97
98
    /**
99
     * @return void
100
     */
101
    public function testImportWithUnknownStore(): void
102
    {
103
        $this->expectException(DataImportException::class);
104
        $this->expectExceptionMessage('Store not found: YY');
105
106
        // Arrange
107
        $this->tester->haveCountry([CountryTransfer::ISO2_CODE => static::COUNTRY_CODE_DE]);
108
109
        $dataImporterReaderConfigurationTransfer = (new DataImporterReaderConfigurationTransfer())
110
            ->setFileName(codecept_data_dir() . 'import/country_store_with_unknown_store.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

110
            ->setFileName(/** @scrutinizer ignore-call */ codecept_data_dir() . 'import/country_store_with_unknown_store.csv');
Loading history...
111
112
        $dataImportConfigurationTransfer = (new DataImporterConfigurationTransfer())
113
            ->setReaderConfiguration($dataImporterReaderConfigurationTransfer)
114
            ->setThrowException(true);
115
116
        $countryStoreDataImportPlugin = new CountryStoreDataImportPlugin();
117
118
        // Act
119
        $countryStoreDataImportPlugin->import($dataImportConfigurationTransfer);
120
    }
121
122
    /**
123
     * @return void
124
     */
125
    public function testCountryStoreGetImportTypeReturnsTypeOfImporter(): void
126
    {
127
        // Arrange
128
        $countryDataImportPlugin = new CountryStoreDataImportPlugin();
129
130
        // Act
131
        $importType = $countryDataImportPlugin->getImportType();
132
133
        // Assert
134
        $this->assertSame(CountryDataImportConfig::IMPORT_TYPE_COUNTRY_STORE, $importType);
135
    }
136
}
137