Passed
Branch master (a2c9fd)
by Sebastiaan
02:11
created

EventTest   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 232
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 2
dl 0
loc 232
rs 10
c 0
b 0
f 0

19 Methods

Rating   Name   Duplication   Size   Complexity  
A it_can_compile_the_command() 0 6 1
A it_can_switch_user() 0 7 1
A it_can_switch_directory() 0 7 1
A it_can_append_output() 0 7 1
A it_can_overwrite_output() 0 7 1
A it_can_run_every_minute() 0 7 1
A it_can_run_n_minutes() 0 7 1
A it_can_run_hourly() 0 7 1
A it_can_run_on_every_hour() 0 7 1
A it_can_run_daily() 0 7 1
A it_can_run_daily_at_a_specific_time() 0 9 1
A it_can_run_on_specific_days() 0 10 1
A it_can_run_on_weekdays_only() 0 7 1
A it_can_run_weekly() 0 7 1
A it_can_run_monthly() 0 7 1
A it_can_run_quarterly() 0 7 1
A it_can_run_yearly() 0 7 1
B it_allows_for_filtering() 0 24 1
A it_can_prevent_overlapping() 0 7 1
1
<?php
2
3
use Basebuilder\Scheduling\Event;
4
5
class EventTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    /**
8
     * @test
9
     */
10
    function it_can_compile_the_command()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
11
    {
12
        $event = new Event('php -i');
13
14
        $this->assertSame("sh -c 'php -i 1>> '/dev/null' 2>> '/dev/null''", $event->compileCommand());
15
    }
16
17
    /**
18
     * @test
19
     */
20
    function it_can_switch_user()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
21
    {
22
        $event = new Event('php -i');
23
        $event->asUser('foo');
24
25
        $this->assertSame("sudo -u foo -- sh -c 'php -i 1>> '/dev/null' 2>> '/dev/null''", $event->compileCommand());
26
    }
27
28
    /**
29
     * @test
30
     */
31
    function it_can_switch_directory()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
32
    {
33
        $event = new Event('php -i');
34
        $event->in('/foo/bar');
35
36
        $this->assertSame("cd /foo/bar; sh -c 'php -i 1>> '/dev/null' 2>> '/dev/null''", $event->compileCommand());
37
    }
38
39
    /**
40
     * @test
41
     */
42
    function it_can_append_output()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
43
    {
44
        $event = new Event('php -i');
45
        $event->appendOutput(true);
46
47
        $this->assertSame("sh -c 'php -i 1>> '/dev/null' 2>> '/dev/null''", $event->compileCommand());
48
    }
49
50
    /**
51
     * @test
52
     */
53
    function it_can_overwrite_output()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
54
    {
55
        $event = new Event('php -i');
56
        $event->appendOutput(false);
57
58
        $this->assertSame("sh -c 'php -i 1> '/dev/null' 2> '/dev/null''", $event->compileCommand());
59
    }
60
61
    /**
62
     * @test
63
     */
64
    function it_can_run_every_minute()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
65
    {
66
        $event = new Event('php -i');
67
        $event->everyMinute();
68
69
        $this->assertSame('* * * * * *', (string) $event->getCronExpression());
70
    }
71
72
    /**
73
     * @test
74
     */
75
    function it_can_run_n_minutes()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
76
    {
77
        $event = new Event('php -i');
78
        $event->everyNMinutes(5);
79
80
        $this->assertSame("*/5 * * * * *", (string) $event->getCronExpression());
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal */5 * * * * * does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
81
    }
82
83
    /**
84
     * @test
85
     */
86
    function it_can_run_hourly()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
87
    {
88
        $event = new Event('php -i');
89
        $event->hourly();
90
91
        $this->assertSame('0 * * * * *', (string) $event->getCronExpression());
92
    }
93
94
    /**
95
     * @test
96
     */
97
    function it_can_run_on_every_hour()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
98
    {
99
        $event = new Event('php -i');
100
        $event->hour(1);
101
102
        $this->assertSame('* 1 * * * *', (string) $event->getCronExpression());
103
    }
104
105
    /**
106
     * @test
107
     */
108
    function it_can_run_daily()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
109
    {
110
        $event = new Event('php -i');
111
        $event->daily();
112
113
        $this->assertSame('0 0 * * * *', (string) $event->getCronExpression());
114
    }
115
116
    /**
117
     * @test
118
     */
119
    function it_can_run_daily_at_a_specific_time()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
120
    {
121
        $event = new Event('php -i');
122
        $event->dailyAt('10:05');
123
        $this->assertSame('5 10 * * * *', (string) $event->getCronExpression());
124
125
        $event->dailyAt('10');
126
        $this->assertSame('0 10 * * * *', (string) $event->getCronExpression());
127
    }
128
129
    /**
130
     * @test
131
     */
132
    function it_can_run_on_specific_days()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
133
    {
134
        $event = new Event('php -i');
135
136
        $event->days([1, 2 ,3 ]);
137
        $this->assertSame('* * * * 1,2,3 *', (string) $event->getCronExpression());
138
139
        $event->days(4, 5, 6);
140
        $this->assertSame('* * * * 4,5,6 *', (string) $event->getCronExpression());
141
    }
142
143
    /**
144
     * @test
145
     */
146
    function it_can_run_on_weekdays_only()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
147
    {
148
        $event = new Event('php -i');
149
        $event->weekdays();
150
151
        $this->assertSame('* * * * 1-5 *', (string) $event->getCronExpression());
152
    }
153
154
    /**
155
     * @test
156
     */
157
    function it_can_run_weekly()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
158
    {
159
        $event = new Event('php -i');
160
        $event->weekly();
161
162
        $this->assertSame('0 0 * * 0 *', (string) $event->getCronExpression());
163
    }
164
165
    /**
166
     * @test
167
     */
168
    function it_can_run_monthly()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
169
    {
170
        $event = new Event('php -i');
171
        $event->monthly();
172
173
        $this->assertSame('0 0 1 * * *', (string) $event->getCronExpression());
174
    }
175
176
    /**
177
     * @test
178
     */
179
    function it_can_run_quarterly()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
180
    {
181
        $event = new Event('php -i');
182
        $event->quarterly();
183
184
        $this->assertSame('0 0 1 */3 * *', (string) $event->getCronExpression());
185
    }
186
187
    /**
188
     * @test
189
     */
190
    function it_can_run_yearly()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
191
    {
192
        $event = new Event('php -i');
193
        $event->yearly();
194
195
        $this->assertSame('0 0 1 1 * *', (string) $event->getCronExpression());
196
    }
197
198
    /**
199
     * @test
200
     */
201
    function it_allows_for_filtering()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
202
    {
203
        $event = new Event('php -i');
204
        $event->everyMinute();
205
206
        $this->assertTrue($event->isDue());
207
208
        $event->skip(function () {
209
            return true;
210
        });
211
212
        $this->assertFalse($event->isDue());
213
214
        $event = new Event('php -i');
215
        $event->everyMinute();
216
217
        $this->assertTrue($event->isDue());
218
219
        $event->when(function () {
220
            return false;
221
        });
222
223
        $this->assertFalse($event->isDue());
224
    }
225
226
    /**
227
     * @group fix
228
     */
229
    function it_can_prevent_overlapping()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
230
    {
231
        $event = new Event('php -i');
232
        $event->preventOverlapping();
233
234
        preg_match('/\(touch \w*; php -i; rm \w*\); 1>> /dev/null 2>> /dev/null/', $event->compileCommand());
235
    }
236
}
237