1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Behat\Behat\Context\Context; |
4
|
|
|
use Behat\Behat\Context\SnippetAcceptingContext; |
5
|
|
|
use Behat\Behat\Tester\Exception\PendingException; |
6
|
|
|
use Behat\Gherkin\Node\PyStringNode; |
7
|
|
|
use Behat\Gherkin\Node\TableNode; |
8
|
|
|
use rdx\behatvars\BehatVariablesDatabase; |
9
|
|
|
|
10
|
|
|
class SimpleFeatureContext implements Context, SnippetAcceptingContext { |
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @Given a value :value |
14
|
|
|
*/ |
15
|
|
|
public function aValue($value) { |
16
|
|
|
return $value; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @Given values :value1 and :value2 |
21
|
|
|
*/ |
22
|
|
|
public function valuesAnd($value1, $value2) { |
23
|
|
|
return [$value1, $value2]; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @Given values :value1 and :value2 and :value3 |
28
|
|
|
*/ |
29
|
|
|
public function valuesAndAnd($value1, $value2, $value3) { |
30
|
|
|
return [$value1, $value2, $value3]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @Then :a should equal :b |
35
|
|
|
*/ |
36
|
|
|
public function shouldEqual($a, $b) { |
37
|
|
|
if ($a != $b) { |
38
|
|
|
throw new \Exception("a ($a) does not equal b ($b)"); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @Then the database should contain: |
44
|
|
|
*/ |
45
|
|
|
public function theDatabaseShouldContain(PyStringNode $string) { |
46
|
|
|
// Convert database to TableNode, to compare against test string |
47
|
|
|
$table = array(); |
48
|
|
|
foreach (BehatVariablesDatabase::all() as $name => $value) { |
49
|
|
|
$table[] = array($name, $value); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$table = new TableNode($table); |
53
|
|
|
$table = trim($table); |
54
|
|
|
|
55
|
|
|
if (trim($string) != $table) { |
56
|
|
|
throw new \Exception("Database contents are wrong:\n$table"); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.