These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | use Robo\Robo; |
||
3 | |||
4 | /** |
||
5 | * This test must run first. :( |
||
6 | */ |
||
7 | class AAA_RunnerErrorTest extends \Codeception\TestCase\Test |
||
8 | { |
||
9 | /** |
||
10 | * @var \Robo\Runner |
||
11 | */ |
||
12 | private $runner; |
||
13 | |||
14 | /** |
||
15 | * @var \CodeGuy |
||
16 | */ |
||
17 | protected $guy; |
||
18 | |||
19 | public function _before() |
||
20 | { |
||
21 | $this->runner = new \Robo\Runner('\Robo\RoboFileFixture'); |
||
22 | } |
||
23 | |||
24 | public function testHandleError() |
||
25 | { |
||
26 | $tmpLevel = error_reporting(); |
||
27 | |||
28 | $this->assertFalse($this->runner->handleError()); |
||
29 | error_reporting(0); |
||
30 | $this->assertTrue($this->runner->handleError()); |
||
31 | |||
32 | error_reporting($tmpLevel); |
||
33 | } |
||
34 | |||
35 | public function testErrorIsHandled() |
||
36 | { |
||
37 | $tmpLevel = error_reporting(); |
||
38 | |||
39 | // Set error_get_last to a known state. Note that it can never be |
||
40 | // reset; see http://php.net/manual/en/function.error-get-last.php |
||
41 | @trigger_error('control'); |
||
42 | $error_description = error_get_last(); |
||
43 | $this->assertEquals('control', $error_description['message']); |
||
44 | @trigger_error(''); |
||
45 | $error_description = error_get_last(); |
||
46 | $this->assertEquals('', $error_description['message']); |
||
47 | |||
48 | // Set error_reporting to a non-zero value. In this instance, |
||
49 | // 'trigger_error' would abort our test script, so we use |
||
50 | // @trigger_error so that execution will continue. With our |
||
51 | // error handler in place, the value of error_get_last() does |
||
52 | // not change. |
||
53 | error_reporting(E_USER_ERROR); |
||
54 | set_error_handler(array($this->runner, 'handleError')); |
||
55 | @trigger_error('test error', E_USER_ERROR); |
||
0 ignored issues
–
show
|
|||
56 | $error_description = error_get_last(); |
||
57 | $this->assertEquals('', $error_description['message']); |
||
58 | |||
59 | // Set error_reporting to zero. Now, even 'trigger_error' |
||
60 | // does not abort execution. The value of error_get_last() |
||
61 | // still does not change. |
||
62 | error_reporting(0); |
||
63 | trigger_error('test error 2', E_USER_ERROR); |
||
64 | $error_description = error_get_last(); |
||
65 | $this->assertEquals('', $error_description['message']); |
||
66 | |||
67 | error_reporting($tmpLevel); |
||
68 | } |
||
69 | } |
||
70 |
If you suppress an error, we recommend checking for the error condition explicitly: