1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ScenarioStateBehatExtension project. |
5
|
|
|
* |
6
|
|
|
* (c) Rodrigue Villetard <[email protected]> |
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
|
|
|
use Gorghoa\ScenarioStateBehatExtension\Annotation\ScenarioStateArgument; |
13
|
|
|
use Gorghoa\ScenarioStateBehatExtension\Context\ScenarioStateAwareContext; |
14
|
|
|
use Gorghoa\ScenarioStateBehatExtension\ScenarioStateInterface; |
15
|
|
|
use Gorghoa\ScenarioStateBehatExtension\TestApp\Gorilla; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Rodrigue Villetard <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class FeatureContext implements ScenarioStateAwareContext |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @beforeSuite |
24
|
|
|
*/ |
25
|
|
|
public static function setUpSuite() |
26
|
|
|
{ |
27
|
|
|
require_once __DIR__.'/../../autoload.php'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var ScenarioStateInterface |
32
|
|
|
*/ |
33
|
|
|
private $scenarioState; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param ScenarioStateInterface $scenarioState |
37
|
|
|
*/ |
38
|
|
|
public function setScenarioState(ScenarioStateInterface $scenarioState) |
39
|
|
|
{ |
40
|
|
|
$this->scenarioState = $scenarioState; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @BeforeScenario |
45
|
|
|
*/ |
46
|
|
|
public function initBananas() |
47
|
|
|
{ |
48
|
|
|
$this->scenarioState->provideStateFragment('bananas', ['foo', 'bar']); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @BeforeScenario |
53
|
|
|
* |
54
|
|
|
* @ScenarioStateArgument("bananas") |
55
|
|
|
* |
56
|
|
|
* @param array $bananas |
57
|
|
|
*/ |
58
|
|
|
public function saveBananas(\Behat\Behat\Hook\Scope\BeforeScenarioScope $scope, array $bananas) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
\PHPUnit_Framework_Assert::assertEquals(['foo', 'bar'], $bananas); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @When the bonobo takes a banana |
65
|
|
|
*/ |
66
|
|
|
public function takeBanana() |
67
|
|
|
{ |
68
|
|
|
$this->scenarioState->provideStateFragment('scenarioBanana', 'Yammy Banana'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @When gives this banana to gorilla |
73
|
|
|
* |
74
|
|
|
* @ScenarioStateArgument("scenarioBanana") |
75
|
|
|
* |
76
|
|
|
* @param string $scenarioBanana |
77
|
|
|
*/ |
78
|
|
|
public function giveBananaToGorilla($scenarioBanana) |
79
|
|
|
{ |
80
|
|
|
\PHPUnit_Framework_Assert::assertEquals('Yammy Banana', $scenarioBanana); |
81
|
|
|
$gorilla = new Gorilla(); |
82
|
|
|
$gorilla->setBanana($scenarioBanana); |
83
|
|
|
$this->scenarioState->provideStateFragment('scenarioGorilla', $gorilla); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @Then the gorilla has the banana |
88
|
|
|
* |
89
|
|
|
* @ScenarioStateArgument("scenarioBanana") |
90
|
|
|
* @ScenarioStateArgument(name="scenarioGorilla", argument="gorilla") |
91
|
|
|
* |
92
|
|
|
* @param string $scenarioBanana |
93
|
|
|
* @param Gorilla $gorilla |
94
|
|
|
*/ |
95
|
|
|
public function gorillaHasBanana($scenarioBanana, Gorilla $gorilla) |
96
|
|
|
{ |
97
|
|
|
\PHPUnit_Framework_Assert::assertEquals('Yammy Banana', $scenarioBanana); |
98
|
|
|
\PHPUnit_Framework_Assert::assertEquals('Yammy Banana', $gorilla->getBanana()); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.