Completed
Push — sf-44 ( 026126...08883d )
by Kamil
79:34 queued 56:57
created

HomepageContext   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 3
dl 0
loc 60
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A iCheckLatestProducts() 0 4 1
A iShouldBeRedirectedToTheHomepage() 0 4 1
A iShouldSeeProductsInTheList() 0 4 1
A iShouldSeeAndInTheMenu() 0 4 1
A iShouldNotSeeAndInTheMenu() 0 9 3
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Behat\Context\Ui\Shop;
15
16
use Behat\Behat\Context\Context;
17
use Sylius\Behat\Element\Shop\MenuElementInterface;
18
use Sylius\Behat\Page\Shop\HomePageInterface;
19
use Webmozart\Assert\Assert;
20
21
final class HomepageContext implements Context
22
{
23
    /** @var HomePageInterface */
24
    private $homePage;
25
26
    /** @var MenuElementInterface */
27
    private $menuElement;
28
29
    public function __construct(HomePageInterface $homePage, MenuElementInterface $menuElement)
30
    {
31
        $this->homePage = $homePage;
32
        $this->menuElement = $menuElement;
33
    }
34
35
    /**
36
     * @When I check latest products
37
     * @When I visit the homepage
38
     */
39
    public function iCheckLatestProducts(): void
40
    {
41
        $this->homePage->open();
42
    }
43
44
    /**
45
     * @Then I should be redirected to the homepage
46
     */
47
    public function iShouldBeRedirectedToTheHomepage(): void
48
    {
49
        $this->homePage->verify();
50
    }
51
52
    /**
53
     * @Then I should see :numberOfProducts products in the list
54
     */
55
    public function iShouldSeeProductsInTheList(int $numberOfProducts): void
56
    {
57
        Assert::same(count($this->homePage->getLatestProductsNames()), $numberOfProducts);
58
    }
59
60
    /**
61
     * @Then I should see :firstMenuItem and :secondMenuItem in the menu
62
     */
63
    public function iShouldSeeAndInTheMenu(string ...$menuItems): void
64
    {
65
        Assert::allOneOf($menuItems, $this->menuElement->getMenuItems());
66
    }
67
68
    /**
69
     * @Then I should not see :firstMenuItem and :secondMenuItem in the menu
70
     */
71
    public function iShouldNotSeeAndInTheMenu(string ...$menuItems): void
72
    {
73
        $actualMenuItems = $this->menuElement->getMenuItems();
74
        foreach ($menuItems as $menuItem) {
75
            if (in_array($menuItem, $actualMenuItems)) {
76
                throw new \InvalidArgumentException(sprintf('Menu should not contain %s element', $menuItem));
77
            }
78
        }
79
    }
80
}
81