|
1
|
|
|
<?php |
|
2
|
|
|
use Robo\Robo; |
|
3
|
|
|
|
|
4
|
|
|
use Robo\Config\ConfigProcessor; |
|
5
|
|
|
use Robo\Config\YamlConfigLoader; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* This test must run first. :( |
|
9
|
|
|
*/ |
|
10
|
|
|
class AAA_RunnerErrorTest extends \Codeception\TestCase\Test |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var \Robo\Runner |
|
14
|
|
|
*/ |
|
15
|
|
|
private $runner; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var \CodeGuy |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $guy; |
|
21
|
|
|
|
|
22
|
|
|
public function _before() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->runner = new \Robo\Runner('\Robo\RoboFileFixture'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testHandleError() |
|
28
|
|
|
{ |
|
29
|
|
|
$tmpLevel = error_reporting(); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertFalse($this->runner->handleError()); |
|
32
|
|
|
error_reporting(0); |
|
33
|
|
|
$this->assertTrue($this->runner->handleError()); |
|
34
|
|
|
|
|
35
|
|
|
error_reporting($tmpLevel); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testErrorIsHandled() |
|
39
|
|
|
{ |
|
40
|
|
|
$tmpLevel = error_reporting(); |
|
41
|
|
|
|
|
42
|
|
|
// Set error_get_last to a known state. Note that it can never be |
|
43
|
|
|
// reset; see http://php.net/manual/en/function.error-get-last.php |
|
44
|
|
|
@trigger_error('control'); |
|
|
|
|
|
|
45
|
|
|
$error_description = error_get_last(); |
|
46
|
|
|
$this->assertEquals('control', $error_description['message']); |
|
47
|
|
|
@trigger_error(''); |
|
|
|
|
|
|
48
|
|
|
$error_description = error_get_last(); |
|
49
|
|
|
$this->assertEquals('', $error_description['message']); |
|
50
|
|
|
|
|
51
|
|
|
// Set error_reporting to a non-zero value. In this instance, |
|
52
|
|
|
// 'trigger_error' would abort our test script, so we use |
|
53
|
|
|
// @trigger_error so that execution will continue. With our |
|
54
|
|
|
// error handler in place, the value of error_get_last() does |
|
55
|
|
|
// not change. |
|
56
|
|
|
error_reporting(E_USER_ERROR); |
|
57
|
|
|
set_error_handler(array($this->runner, 'handleError')); |
|
58
|
|
|
@trigger_error('test error', E_USER_ERROR); |
|
|
|
|
|
|
59
|
|
|
$error_description = error_get_last(); |
|
60
|
|
|
$this->assertEquals('', $error_description['message']); |
|
61
|
|
|
|
|
62
|
|
|
// Set error_reporting to zero. Now, even 'trigger_error' |
|
63
|
|
|
// does not abort execution. The value of error_get_last() |
|
64
|
|
|
// still does not change. |
|
65
|
|
|
error_reporting(0); |
|
66
|
|
|
trigger_error('test error 2', E_USER_ERROR); |
|
67
|
|
|
$error_description = error_get_last(); |
|
68
|
|
|
$this->assertEquals('', $error_description['message']); |
|
69
|
|
|
|
|
70
|
|
|
error_reporting($tmpLevel); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.