1
|
|
|
<?php |
|
|
|
|
2
|
|
|
use Peridot\Runner\Context; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Creates a suite and sets it on the suite factory |
6
|
|
|
* |
7
|
|
|
* @param string $description |
8
|
|
|
* @param callable $fn |
9
|
|
|
*/ |
10
|
|
|
function describe($description, callable $fn) |
11
|
|
|
{ |
12
|
|
|
Context::getInstance()->addSuite($description, $fn); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Identical to describe. Useful for test readability |
17
|
|
|
* |
18
|
|
|
* @param $description |
19
|
|
|
* @param callable $fn |
20
|
|
|
*/ |
21
|
|
|
function context($description, callable $fn) |
22
|
|
|
{ |
23
|
|
|
describe($description, $fn); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Create a spec and add it to the current suite |
28
|
|
|
* |
29
|
|
|
* @param $description |
30
|
|
|
* @param $fn |
31
|
|
|
*/ |
32
|
|
|
function it($description, callable $fn = null) |
33
|
|
|
{ |
34
|
|
|
Context::getInstance()->addTest($description, $fn); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Identical to it. Useful for test readability |
39
|
|
|
* |
40
|
|
|
* @param $description |
41
|
|
|
* @param $fn |
42
|
|
|
*/ |
43
|
|
|
function test($description, callable $fn = null) |
44
|
|
|
{ |
45
|
|
|
it($description, $fn); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Create a pending suite |
50
|
|
|
* |
51
|
|
|
* @param $description |
52
|
|
|
* @param callable $fn |
53
|
|
|
*/ |
54
|
|
|
function xdescribe($description, callable $fn) |
55
|
|
|
{ |
56
|
|
|
Context::getInstance()->addSuite($description, $fn, true); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Create a pending context |
61
|
|
|
* |
62
|
|
|
* @param $description |
63
|
|
|
* @param callable $fn |
64
|
|
|
*/ |
65
|
|
|
function xcontext($description, callable $fn) |
66
|
|
|
{ |
67
|
|
|
Context::getInstance()->addSuite($description, $fn, true); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Create a pending spec |
72
|
|
|
* |
73
|
|
|
* @param $description |
74
|
|
|
* @param callable $fn |
75
|
|
|
*/ |
76
|
|
|
function xit($description, callable $fn = null) |
77
|
|
|
{ |
78
|
|
|
Context::getInstance()->addTest($description, $fn, true); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Create a pending spec |
83
|
|
|
* |
84
|
|
|
* @param $description |
85
|
|
|
* @param callable $fn |
86
|
|
|
*/ |
87
|
|
|
function xtest($description, callable $fn = null) |
88
|
|
|
{ |
89
|
|
|
xit($description, $fn); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Create a focused suite |
94
|
|
|
* |
95
|
|
|
* @param $description |
96
|
|
|
* @param callable $fn |
97
|
|
|
*/ |
98
|
|
|
function fdescribe($description, callable $fn) |
99
|
|
|
{ |
100
|
|
|
Context::getInstance()->addSuite($description, $fn, null, true); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Create a focused context |
105
|
|
|
* |
106
|
|
|
* @param $description |
107
|
|
|
* @param callable $fn |
108
|
|
|
*/ |
109
|
|
|
function fcontext($description, callable $fn) |
110
|
|
|
{ |
111
|
|
|
Context::getInstance()->addSuite($description, $fn, null, true); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Create a focused spec |
116
|
|
|
* |
117
|
|
|
* @param $description |
118
|
|
|
* @param callable $fn |
119
|
|
|
*/ |
120
|
|
|
function fit($description, callable $fn = null) |
121
|
|
|
{ |
122
|
|
|
Context::getInstance()->addTest($description, $fn, null, true); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Create a focused spec |
127
|
|
|
* |
128
|
|
|
* @param $description |
129
|
|
|
* @param callable $fn |
130
|
|
|
*/ |
131
|
|
|
function ftest($description, callable $fn = null) |
132
|
|
|
{ |
133
|
|
|
fit($description, $fn); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Add a setup function for all specs in the |
138
|
|
|
* current suite |
139
|
|
|
* |
140
|
|
|
* @param callable $fn |
141
|
|
|
*/ |
142
|
|
|
function beforeEach(callable $fn) |
143
|
|
|
{ |
144
|
|
|
Context::getInstance()->addSetupFunction($fn); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Add a tear down function for all specs in the |
149
|
|
|
* current suite |
150
|
|
|
* |
151
|
|
|
* @param callable $fn |
152
|
|
|
*/ |
153
|
|
|
function afterEach(callable $fn) |
154
|
|
|
{ |
155
|
|
|
Context::getInstance()->addTearDownFunction($fn); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Change default assert behavior to throw exceptions |
160
|
|
|
*/ |
161
|
|
|
assert_options(ASSERT_WARNING, false); |
162
|
|
|
assert_options(ASSERT_CALLBACK, ['Peridot\AssertException', 'handle']); |
163
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.