Completed
Push — focused-specs ( 446344 )
by Brian
01:57 queued 27s
created

Dsl.php ➔ fit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 10 and the first side effect is on line 128.

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.

Loading history...
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
    Context::getInstance()->addSuite($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
 * Create a pending suite
39
 *
40
 * @param $description
41
 * @param callable $fn
42
 */
43
function xdescribe($description, callable $fn)
44
{
45
    Context::getInstance()->addSuite($description, $fn, true);
46
}
47
48
/**
49
 * Create a pending context
50
 *
51
 * @param $description
52
 * @param callable $fn
53
 */
54
function xcontext($description, callable $fn)
55
{
56
    Context::getInstance()->addSuite($description, $fn, true);
57
}
58
59
/**
60
 * Create a pending spec
61
 *
62
 * @param $description
63
 * @param callable $fn
64
 */
65
function xit($description, callable $fn = null)
66
{
67
    Context::getInstance()->addTest($description, $fn, true);
68
}
69
70
/**
71
 * Create a focused suite
72
 *
73
 * @param $description
74
 * @param callable $fn
75
 */
76
function fdescribe($description, callable $fn)
77
{
78
    Context::getInstance()->addSuite($description, $fn, null, true);
79
}
80
81
/**
82
 * Create a focused context
83
 *
84
 * @param $description
85
 * @param callable $fn
86
 */
87
function fcontext($description, callable $fn)
88
{
89
    Context::getInstance()->addSuite($description, $fn, null, true);
90
}
91
92
/**
93
 * Create a focused spec
94
 *
95
 * @param $description
96
 * @param callable $fn
97
 */
98
function fit($description, callable $fn = null)
99
{
100
    Context::getInstance()->addTest($description, $fn, null, true);
101
}
102
103
/**
104
 * Add a setup function for all specs in the
105
 * current suite
106
 *
107
 * @param callable $fn
108
 */
109
function beforeEach(callable $fn)
110
{
111
    Context::getInstance()->addSetupFunction($fn);
112
}
113
114
/**
115
 * Add a tear down function for all specs in the
116
 * current suite
117
 *
118
 * @param callable $fn
119
 */
120
function afterEach(callable $fn)
121
{
122
    Context::getInstance()->addTearDownFunction($fn);
123
}
124
125
/**
126
 * Change default assert behavior to throw exceptions
127
 */
128
assert_options(ASSERT_WARNING, false);
129
assert_options(ASSERT_CALLBACK, function ($script, $line, $message, $description) {
130
    throw new Exception($description);
131
});
132