Completed
Pull Request — example/managing-articles (#87)
by Loïc
03:50
created

ManagingArticlesContext::iChangeItsTitleAs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
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 App\Behat\Context\Ui\Backend;
15
16
use App\Behat\Page\Backend\Article\IndexPage;
17
use App\Behat\Page\Backend\Article\CreatePage;
18
use App\Behat\Page\Backend\Article\UpdatePage;
19
use App\Entity\Article;
20
use Behat\Behat\Context\Context;
21
use Webmozart\Assert\Assert;
22
23
final class ManagingArticlesContext implements Context
24
{
25
    /**
26
     * @var CreatePage
27
     */
28
    private $createPage;
29
30
    /**
31
     * @var IndexPage
32
     */
33
    private $indexPage;
34
35
    /**
36
     * @var UpdatePage
37
     */
38
    private $updatePage;
39
40
    /**
41
     * @param CreatePage $createPage
42
     * @param IndexPage  $indexPage
43
     * @pram UpdatePage $updatePage
44
     */
45
    public function __construct(
46
        CreatePage $createPage,
47
        IndexPage $indexPage,
48
        UpdatePage $updatePage
49
    ) {
50
        $this->createPage = $createPage;
51
        $this->indexPage = $indexPage;
52
        $this->updatePage = $updatePage;
53
    }
54
55
    /**
56
     * @Given I want to create a new article
57
     */
58
    public function iWantToCreateANewArticle()
59
    {
60
        $this->createPage->open();
61
    }
62
63
    /**
64
     * @When I want to browse articles
65
     */
66
    public function iWantToBrowseArticles()
67
    {
68
        $this->indexPage->open();
69
    }
70
71
    /**
72
     * @Given I want to modify the :article article
73
     */
74
    public function iWantToModifyAnArticle(Article $article)
75
    {
76
        $this->updatePage->open(['id' => $article->getId()]);
77
    }
78
79
    /**
80
     * @When I specify its title as :title
81
     * @When I do not specify its title
82
     */
83
    public function iSpecifyItsEmailAs($title = null)
84
    {
85
        $this->createPage->specifyTitle($title);
86
    }
87
88
    /**
89
     * @When I rename it to :title
90
     */
91
    public function iChangeItsTitleAs($title = null)
92
    {
93
        $this->updatePage->changeTitle($title);
94
    }
95
96
    /**
97
     * @When I add it
98
     * @When I try to add it
99
     */
100
    public function iAddIt()
101
    {
102
        $this->createPage->create();
103
    }
104
105
    /**
106
     * @When I save my changes
107
     */
108
    public function iSaveMyChanges()
109
    {
110
        $this->updatePage->saveChanges();
111
    }
112
113
    /**
114
     * @When I delete article with title :title
115
     */
116
    public function iDeleteArticleWithTitle($title)
117
    {
118
        $this->indexPage->deleteResourceOnPage(['title' => $title]);
119
    }
120
121
    /**
122
     * @Then /^there should be (\d+) articles in the list$/
123
     */
124
    public function iShouldSeeArticlesInTheList(int $number = 1): void
125
    {
126
        Assert::same($this->indexPage->countItems(), (int) $number);
127
    }
128
129
    /**
130
     * @Then I should (also )see the article :title in the list
131
     * @Then the article :title should appear in the website
132
     */
133
    public function theArticleShouldAppearInTheWebsite($title)
134
    {
135
        $this->indexPage->open();
136
137
        Assert::true($this->indexPage->isSingleResourceOnPage(['title' => $title]));
138
    }
139
140
    /**
141
     * @Then there should not be :title article anymore
142
     */
143
    public function thereShouldBeNoAnymore($title)
144
    {
145
        Assert::false($this->indexPage->isSingleResourceOnPage(['title' => $title]));
146
    }
147
}
148