Completed
Push — 3.8.x ( 2cd6fd...b176ac )
by Tim
07:26
created

ProductFeatureContext::assertExitCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
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
        // load the environment
28
        /** @var Behat\Behat\Context\Environment\InitializedContextEnvironment $environment */
29
        $environment = $scope->getEnvironment();
30
31
        // make the console and the feature context available
32
        $this->consoleContext = $environment->getContext(ConsoleContext::class);
33
        $this->featureContext = $environment->getContext(FeatureContext::class);
34
    }
35
36
    /**
37
     * @Then title and price are :arg1,( )
38
     * @Then title and price are :arg1, :arg2
39
     */
40
    public function assertTitleAndPrice($arg1, $arg2 = null)
41
    {
42
43
        /** @var \Behat\Mink\Element\NodeElement $title */
44
        $title = $this->featureContext->getSession()->getPage()->find('css', 'title');
45
        PHPUnit_Framework_Assert::assertSame($arg1, $title->getText());
46
47
        if ($this->featureContext->getSession()->getStatusCode() === 200 && $arg2 !== null) {
48
            /** @var \Behat\Mink\Element\NodeElement $price */
49
            $price = $this->featureContext->getSession()->getPage()->find('xpath', '//*[@class="price"]');
50
            PHPUnit_Framework_Assert::assertSame($arg2, $price->getText());
51
        }
52
    }
53
54
    /**
55
     * @Given files with products to be updated are available
56
     * @Given files with products to be deleted are available
57
     */
58 View Code Duplication
    public function filesWithProductsToBeUpdatedAreAvailable()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        for ($i = 1; $i < 5; $i++) {
61
            $this->consoleContext->aThirdPartySystemHasCopiedTheFileIntoTheImportFolder(
62
                sprintf('vendor/techdivision/import-sample-data/generic/data/products/add-update/product-import_20161021-161909_0%s.csv', $i),
63
                'var/importexport'
64
            );
65
        }
66
    }
67
68
    /**
69
     * @Given files with products to be replaced are available
70
     */
71 View Code Duplication
    public function filesWithProductsToBeReplacedAreAvailable()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
    {
73
        for ($i = 1; $i < 5; $i++) {
74
            $this->consoleContext->aThirdPartySystemHasCopiedTheFileIntoTheImportFolder(
75
                sprintf('vendor/techdivision/import-sample-data/generic/data/products/replace/product-import_20161021-161909_0%s.csv', $i),
76
                'var/importexport'
77
            );
78
        }
79
    }
80
81
    /**
82
     * @Given the product import process has been started
83
     */
84
    public function theProductImportProcessHasBeenStarted()
85
    {
86
        $this->consoleContext->theCommandHasBeenExecuted(sprintf('bin/import-simple %s', CommandNames::IMPORT_CREATE_OK_FILE));
87
        $this->consoleContext->theCommandHasBeenExecuted(sprintf('bin/import-simple %s add-update', CommandNames::IMPORT_PRODUCTS));
88
    }
89
90
    /**
91
     * @Given the product deletion process has been started
92
     */
93
    public function theProductDeletionProcessHasBeenStarted()
94
    {
95
        $this->consoleContext->theCommandHasBeenExecuted(sprintf('bin/import-simple %s', CommandNames::IMPORT_CREATE_OK_FILE));
96
        $this->consoleContext->theCommandHasBeenExecuted(sprintf('bin/import-simple %s delete', CommandNames::IMPORT_PRODUCTS));
97
    }
98
99
    /**
100
     * @Given the product replacement process has been started
101
     */
102
    public function theProductReplacementProcessHasBeenStarted()
103
    {
104
        $this->consoleContext->theCommandHasBeenExecuted(sprintf('bin/import-simple %s', CommandNames::IMPORT_CREATE_OK_FILE));
105
        $this->consoleContext->theCommandHasBeenExecuted(sprintf('bin/import-simple %s replace', CommandNames::IMPORT_PRODUCTS));
106
    }
107
}
108