Issues (3641)

Console/TriggerEventFromFileConsoleTest.php (1 issue)

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Spryker Marketplace License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerTest\Zed\MerchantOms\Communication\Console;
9
10
use Codeception\Test\Unit;
11
use Generated\Shared\Transfer\MerchantOmsTriggerResponseTransfer;
12
use Spryker\Zed\MerchantOms\Business\MerchantOmsFacade;
13
use Spryker\Zed\MerchantOms\Communication\Console\TriggerEventFromCsvFileConsole;
14
use Symfony\Component\Console\Input\ArrayInput;
15
use Symfony\Component\Console\Output\BufferedOutput;
16
17
/**
18
 * Auto-generated group annotations
19
 *
20
 * @group SprykerTest
21
 * @group Zed
22
 * @group MerchantOms
23
 * @group Communication
24
 * @group Console
25
 * @group TriggerEventFromFileConsoleTest
26
 * Add your own group annotations below this line
27
 */
28
class TriggerEventFromFileConsoleTest extends Unit
29
{
30
    /**
31
     * @var string
32
     */
33
    protected const TEST_STATE_MACHINE = 'Test01';
34
35
    /**
36
     * @var string
37
     */
38
    protected const TEST_MERCHANT_ORDER_ITEM_REFERENCE = 'TestMerchantOrderItemReference';
39
40
    /**
41
     * @var int
42
     */
43
    protected const CODE_SUCCESS = 0;
44
45
    /**
46
     * @var int
47
     */
48
    protected const CODE_ERROR = 1;
49
50
    /**
51
     * @var string
52
     */
53
    protected const ARGUMENT_FILE_PATH = 'file-path';
54
55
    /**
56
     * @var \SprykerTest\Zed\MerchantOms\MerchantOmsCommunicationTester
57
     */
58
    protected $tester;
59
60
    /**
61
     * @dataProvider filenameDataProvider
62
     *
63
     * @param string $importFileName
64
     * @param int $resultCode
65
     *
66
     * @return void
67
     */
68
    public function testTriggerEventFromFileConsoleReturnsSuccessWithValidImport(string $importFileName, int $resultCode): void
69
    {
70
        // Arrange
71
        $triggerEventFromFileConsole = (new TriggerEventFromCsvFileConsole())->setFacade($this->getMerchantOmsFacadeMock());
72
        $input = new ArrayInput([static::ARGUMENT_FILE_PATH => codecept_data_dir() . 'import/' . $importFileName]);
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

72
        $input = new ArrayInput([static::ARGUMENT_FILE_PATH => /** @scrutinizer ignore-call */ codecept_data_dir() . 'import/' . $importFileName]);
Loading history...
73
        $output = new BufferedOutput();
74
75
        // Act
76
        $outputCode = $triggerEventFromFileConsole->run($input, $output);
77
78
        // Assert
79
        $this->assertSame($outputCode, $resultCode);
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    public function filenameDataProvider(): array
86
    {
87
        return [
88
            'Valid import file' => ['valid_import.csv', static::CODE_SUCCESS],
89
            'Valid empty import file' => ['valid_empty_import.csv', static::CODE_SUCCESS],
90
            'Invalid non existing file' => ['invalid_not_existing_import.csv', static::CODE_ERROR],
91
            'Invalid without headers' => ['invalid_without_headers_import.csv', static::CODE_ERROR],
92
            'Invalid missing column' => ['invalid_missing_column_import.csv', static::CODE_ERROR],
93
        ];
94
    }
95
96
    /**
97
     * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\MerchantOms\Business\MerchantOmsFacade
98
     */
99
    protected function getMerchantOmsFacadeMock(): MerchantOmsFacade
100
    {
101
        $merchantOmsFacade = $this->createMock(MerchantOmsFacade::class);
102
        $merchantOmsFacade->method('triggerEventForMerchantOrderItem')->willReturn(
103
            (new MerchantOmsTriggerResponseTransfer())->setIsSuccessful(true),
104
        );
105
106
        return $merchantOmsFacade;
107
    }
108
}
109