Completed
Push — 3.8.x ( 12ed2a...d105af )
by Tim
06:29
created

filesWithProductsToBeUpdatedAreAvailable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
use Behat\Behat\Context\Context;
4
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
5
use TechDivision\Import\Utils\CommandNames;
6
7
/**
8
 * Defines application features from the specific context.
9
 */
10
class ProductFeatureContext implements Context
11
{
12
13
    /**
14
     * @var \ConsoleContext
15
     */
16
    private $consoleContext;
17
18
    /**
19
     * @var \FeatureContext
20
     */
21
    private $featureContext;
22
23
    /** @BeforeScenario */
24
    public function before(BeforeScenarioScope $scope)
25
    {
26
27
        /** @var Behat\Behat\Context\Environment\InitializedContextEnvironment $environment */
28
        $environment = $scope->getEnvironment();
29
30
        $this->consoleContext = $environment->getContext(ConsoleContext::class);
31
        $this->featureContext = $environment->getContext(FeatureContext::class);
32
    }
33
34
    /**
35
     * @Then title and price are :arg1,( )
36
     * @Then title and price are :arg1, :arg2
37
     */
38
    public function assertTitleAndPrice($arg1, $arg2 = null)
39
    {
40
41
        /** @var \Behat\Mink\Element\NodeElement $title */
42
        $title = $this->featureContext->getSession()->getPage()->find('css', 'title');
43
        PHPUnit_Framework_Assert::assertSame($arg1, $title->getText());
44
45
        if ($this->featureContext->getSession()->getStatusCode() === 200 && $arg2 !== null) {
46
            /** @var \Behat\Mink\Element\NodeElement $price */
47
            $price = $this->featureContext->getSession()->getPage()->find('xpath', '//*[@class="price"]');
48
            PHPUnit_Framework_Assert::assertSame($arg2, $price->getText());
49
        }
50
    }
51
52
    /**
53
     * @Given files with products to be updated are available
54
     */
55
    public function filesWithProductsToBeUpdatedAreAvailable()
56
    {
57
        for ($i = 1; $i < 5; $i++) {
58
            $this->consoleContext->aThirdPartySystemHasCopiedTheFileIntoTheImportFolder(
59
                sprintf('vendor/techdivision/import-sample-data/generic/data/products/add-update/product-import_20161021-161909_0%s.csv', $i),
60
                'var/importexport'
61
            );
62
        }
63
    }
64
65
    /**
66
     * @Given the import process has been started
67
     */
68
    public function theImportProcessHasBeenStarted()
69
    {
70
        $this->consoleContext->theCommandHasBeenExecuted('bin/import-simple import:create:ok-file');
71
        $this->consoleContext->theCommandHasBeenExecuted(sprintf('bin/import-simple %s', CommandNames::IMPORT_PRODUCTS));
72
    }
73
74
    /**
75
     * @When the import process has been finished
76
     */
77
    public function assertExitCode()
78
    {
79
80
        PHPUnit_Framework_Assert::assertSame(0, $this->consoleContext->getExitCode());
81
82
        $this->assertSuccessMessage();
83
    }
84
85
    /**
86
     * @Then a success message has to be rendered
87
     */
88
    public function assertSuccessMessage()
89
    {
90
        $this->assertMessage(
91
            sprintf(
92
                '/Successfully executed command %s with serial \w+-\w+-\w+-\w+-\w+ in \d+:\d+:\d+ s/',
93
                CommandNames::IMPORT_PRODUCTS
94
            )
95
        );
96
    }
97
98
    /**
99
     * @Then a message :arg1 has to be rendered
100
     */
101
    public function assertMessage($arg1)
102
    {
103
104
        $output = $this->consoleContext->getOutput();
105
106
        PHPUnit_Framework_Assert::assertRegExp($arg1, array_pop($output));
107
    }
108
}
109