1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Behat\Behat\Context\Context; |
4
|
|
|
use Behat\Gherkin\Node\TableNode; |
5
|
|
|
use Davispeixoto\Workflow\Exceptions\InvalidTransitionException; |
6
|
|
|
use Davispeixoto\Workflow\Tests\Auxiliary\SalesStates; |
7
|
|
|
use Davispeixoto\Workflow\Tests\Auxiliary\SalesWorkflow; |
8
|
|
|
use MyCLabs\Enum\Enum; |
9
|
|
|
use PHPUnit\Framework\Assert; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Defines application features from the specific context. |
13
|
|
|
*/ |
14
|
|
|
class FeatureContext implements Context |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var SalesWorkflow |
18
|
|
|
*/ |
19
|
|
|
private $workflow; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string $exceptionMessage |
23
|
|
|
*/ |
24
|
|
|
private $exceptionMessage; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string $exceptionClass |
28
|
|
|
*/ |
29
|
|
|
private $exceptionClass; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Enum |
33
|
|
|
*/ |
34
|
|
|
private $currentState; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Initializes context. |
38
|
|
|
* |
39
|
|
|
* Every scenario gets its own context instance. |
40
|
|
|
* You can also pass arbitrary arguments to the |
41
|
|
|
* context constructor through behat.yml. |
42
|
|
|
*/ |
43
|
|
|
public function __construct() |
44
|
|
|
{ |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @Given there is the following states for sales: |
50
|
|
|
*/ |
51
|
|
|
public function thereIsTheFollowingStatesForSales(TableNode $table) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
return true; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @Given there is the following sales lifecycle |
58
|
|
|
*/ |
59
|
|
|
public function thereIsTheFollowingSalesLifecycle(TableNode $table) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
return true; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @Given there is the background |
66
|
|
|
*/ |
67
|
|
|
public function thereIsTheBackground() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
return true; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @Given There is a sale in :arg1 state |
74
|
|
|
*/ |
75
|
|
|
public function thereIsASaleInState($arg1) |
76
|
|
|
{ |
77
|
|
|
$values = SalesStates::values(); |
78
|
|
|
$this->workflow = new SalesWorkflow($values[$arg1]); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @When I change its state to :arg1 |
83
|
|
|
*/ |
84
|
|
|
public function iChangeItsStateTo($arg1) |
85
|
|
|
{ |
86
|
|
|
$this->exceptionMessage = ''; |
87
|
|
|
$this->exceptionClass = ''; |
88
|
|
|
|
89
|
|
|
try { |
90
|
|
|
$values = SalesStates::values(); |
91
|
|
|
$this->workflow->setCurrentStatus($values[$arg1]); |
92
|
|
|
} catch (InvalidTransitionException $invalidTransitionException) { |
93
|
|
|
$this->exceptionMessage = $invalidTransitionException->getMessage(); |
94
|
|
|
$this->exceptionClass = InvalidTransitionException::class; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @Then sales must be in :arg1 state |
100
|
|
|
*/ |
101
|
|
|
public function salesMustBeInState($arg1) |
102
|
|
|
{ |
103
|
|
|
$values = SalesStates::values(); |
104
|
|
|
$state = $values[$arg1]; |
105
|
|
|
Assert::assertEquals($state->getValue(), $this->workflow->getCurrentStatus()->getValue()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @Then I should receive an error message |
110
|
|
|
*/ |
111
|
|
|
public function iShouldReceiveAnErrorMessage() |
112
|
|
|
{ |
113
|
|
|
Assert::assertEquals(InvalidTransitionException::class, $this->exceptionClass); |
114
|
|
|
Assert::assertNotEmpty($this->exceptionMessage); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @When I check its state |
119
|
|
|
*/ |
120
|
|
|
public function iCheckItsState() |
121
|
|
|
{ |
122
|
|
|
$this->currentState = $this->workflow->getCurrentStatus(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @Then I should see it is not finished |
127
|
|
|
*/ |
128
|
|
|
public function iShouldSeeItIsNotFinished() |
129
|
|
|
{ |
130
|
|
|
Assert::assertEquals(false, $this->workflow->isFinished()); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @Then I should see it is finished |
135
|
|
|
*/ |
136
|
|
|
public function iShouldSeeItIsFinished() |
137
|
|
|
{ |
138
|
|
|
Assert::assertEquals(true, $this->workflow->isFinished()); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.