|
1
|
|
|
<?php |
|
2
|
|
|
namespace Codeliner\CargoFeature; |
|
3
|
|
|
|
|
4
|
|
|
use Behat\Behat\Context\ClosuredContextInterface, |
|
5
|
|
|
Behat\Behat\Context\TranslatedContextInterface, |
|
6
|
|
|
Behat\Behat\Context\BehatContext, |
|
7
|
|
|
Behat\Behat\Exception\PendingException; |
|
8
|
|
|
use Behat\Gherkin\Node\PyStringNode, |
|
9
|
|
|
Behat\Gherkin\Node\TableNode; |
|
10
|
|
|
use Behat\MinkExtension\Context\MinkContext; |
|
11
|
|
|
use Zend\Mvc\Application; |
|
12
|
|
|
use Zend\ServiceManager\ServiceManager; |
|
13
|
|
|
|
|
14
|
|
|
// |
|
15
|
|
|
// Require 3rd-party libraries here: |
|
16
|
|
|
// |
|
17
|
|
|
// require_once 'PHPUnit/Autoload.php'; |
|
18
|
|
|
// require_once 'PHPUnit/Framework/Assert/Functions.php'; |
|
19
|
|
|
// |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Features context. |
|
23
|
|
|
*/ |
|
24
|
|
|
class FeatureContext extends MinkContext |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var \Interop\Container\ContainerInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private static $container; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Initializes context. |
|
33
|
|
|
* Every scenario gets it's own context object. |
|
34
|
|
|
* |
|
35
|
|
|
* @param array $parameters context parameters (set them up through behat.yml) |
|
|
|
|
|
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct() |
|
38
|
|
|
{ |
|
39
|
|
|
// Initialize your context here |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @BeforeSuite |
|
44
|
|
|
*/ |
|
45
|
|
|
static public function iniializeContainer() |
|
46
|
|
|
{ |
|
47
|
|
|
if (self::$container === null) { |
|
48
|
|
|
self::$container = require __DIR__ . '/../../config/container.php'; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @BeforeFeature |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function clearDatabase() |
|
56
|
|
|
{ |
|
57
|
|
|
$em = self::$container->get('doctrine.entitymanager.orm_default'); |
|
58
|
|
|
$q = $em->createQuery('delete from Codeliner\CargoBackend\Model\Cargo\Cargo'); |
|
59
|
|
|
$q->execute(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @Given /^I click the submit button$/ |
|
64
|
|
|
*/ |
|
65
|
|
|
public function iClickTheSubmitButton() |
|
66
|
|
|
{ |
|
67
|
|
|
$session = $this->getSession(); |
|
68
|
|
|
$page = $session->getPage(); |
|
69
|
|
|
|
|
70
|
|
|
$submit = $page->find('css', 'form input[type=submit]'); |
|
71
|
|
|
|
|
72
|
|
|
if ($submit) { |
|
73
|
|
|
$submit->click(); |
|
74
|
|
|
} else { |
|
75
|
|
|
throw new \RuntimeException("Can not find the submit btn"); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @Then /^I should wait until I see "([^"]*)"$/ |
|
81
|
|
|
*/ |
|
82
|
|
|
public function iShouldSeeAvailableRoutes($arg1) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->getSession()->wait(5000, '(0 === jQuery.active)'); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertElementOnPage($arg1); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @When /^I click on first item in the list "([^"]*)"$/ |
|
91
|
|
|
*/ |
|
92
|
|
|
public function iClickOnFirstItemInTheList($arg1) |
|
|
|
|
|
|
93
|
|
|
{ |
|
94
|
|
|
$session = $this->getSession(); |
|
95
|
|
|
$page = $session->getPage(); |
|
96
|
|
|
|
|
97
|
|
|
$ul = $page->find('css', '#cargo-list'); |
|
98
|
|
|
|
|
99
|
|
|
$li = $ul->find('css', 'li'); |
|
100
|
|
|
|
|
101
|
|
|
$li->find('css', 'a')->click(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @When /^I follow first "([^"]*)" link$/ |
|
106
|
|
|
*/ |
|
107
|
|
|
public function iFollowFirstLink($arg1) |
|
108
|
|
|
{ |
|
109
|
|
|
$page = $this->getSession()->getPage(); |
|
110
|
|
|
|
|
111
|
|
|
$link = $page->find('css', $arg1); |
|
112
|
|
|
|
|
113
|
|
|
if ($link) { |
|
114
|
|
|
$link->click(); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @Given /^I wait until I am on page "(?P<page>[^"]+)"$/ |
|
120
|
|
|
*/ |
|
121
|
|
|
public function iWaitUntilIAmOnPage($page) |
|
122
|
|
|
{ |
|
123
|
|
|
$matchingFound = false; |
|
124
|
|
|
|
|
125
|
|
|
for($i=1;$i++;$i<=5) { |
|
126
|
|
|
if (strpos($this->getSession()->getCurrentUrl(), $this->locatePath($page)) !== false) { |
|
127
|
|
|
$matchingFound = true; |
|
128
|
|
|
break; |
|
129
|
|
|
} |
|
130
|
|
|
sleep(1); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
if (!$matchingFound) { |
|
134
|
|
|
throw new \Exception('Stoped waiting, timelimit reached!'); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.