Skip to content

Commit f2490f8

Browse files
committed
Remove duplicated code in behat FeatureContext
1 parent cb8776a commit f2490f8

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

Diff for: features/bootstrap/FeatureContext.php

+27-26
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,6 @@ public function __construct()
2121
{
2222
}
2323

24-
/**
25-
* @Then I should see the terminal
26-
*/
27-
public function iShouldSeeTheTerminal()
28-
{
29-
$page = $this->getSession()->getPage();
30-
$elementList = $page->find('css', '.terminal');
31-
foreach ($elementList as $element) {
32-
if (!$element->isVisible()) {
33-
throw new ExpectationException(
34-
'Terminal is not visible, but visible expected.',
35-
$this->getSession()
36-
);
37-
}
38-
}
39-
}
40-
4124
/**
4225
* @When I execute command :command
4326
*/
@@ -54,20 +37,38 @@ public function iExecuteCommand($command)
5437
");
5538
}
5639

40+
/**
41+
* @Then I should see the terminal
42+
*/
43+
public function iShouldSeeTheTerminal()
44+
{
45+
$terminal = $this->getTerminal();
46+
if (!$terminal->isVisible()) {
47+
throw new ExpectationException(
48+
'Terminal is not visible, but visible expected.',
49+
$this->getSession()
50+
);
51+
}
52+
}
53+
5754
/**
5855
* @Then I should not see the terminal
5956
*/
6057
public function iShouldNotSeeTheTerminal()
6158
{
62-
$page = $this->getSession()->getPage();
63-
$elementList = $page->findAll('css', '.terminal');
64-
foreach ($elementList as $element) {
65-
if ($element->isVisible()) {
66-
throw new ExpectationException(
67-
'Terminal is visible, but invisible expected.',
68-
$this->getSession()
69-
);
70-
}
59+
$terminal = $this->getTerminal();
60+
if ($terminal->isVisible()) {
61+
throw new ExpectationException(
62+
'Terminal is visible, but invisible expected.',
63+
$this->getSession()
64+
);
7165
}
7266
}
67+
68+
private function getTerminal()
69+
{
70+
return $this->getSession()
71+
->getPage()
72+
->find('css', '.terminal');
73+
}
7374
}

0 commit comments

Comments
 (0)