comparison vendor/psy/psysh/test/Exception/ErrorExceptionTest.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents
children c2387f117808
comparison
equal deleted inserted replaced
12:7a779792577d 13:5fb285c0d0e3
1 <?php
2
3 /*
4 * This file is part of Psy Shell.
5 *
6 * (c) 2012-2018 Justin Hileman
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Psy\Test\Exception;
13
14 use Psy\Exception\ErrorException;
15
16 class ErrorExceptionTest extends \PHPUnit\Framework\TestCase
17 {
18 public function testInstance()
19 {
20 $e = new ErrorException();
21
22 $this->assertInstanceOf('Psy\Exception\Exception', $e);
23 $this->assertInstanceOf('ErrorException', $e);
24 $this->assertInstanceOf('Psy\Exception\ErrorException', $e);
25 }
26
27 public function testMessage()
28 {
29 $e = new ErrorException('foo');
30
31 $this->assertContains('foo', $e->getMessage());
32 $this->assertSame('foo', $e->getRawMessage());
33 }
34
35 /**
36 * @dataProvider getLevels
37 */
38 public function testErrorLevels($level, $type)
39 {
40 $e = new ErrorException('foo', 0, $level);
41 $this->assertContains('PHP ' . $type, $e->getMessage());
42 }
43
44 /**
45 * @dataProvider getLevels
46 */
47 public function testThrowException($level, $type)
48 {
49 try {
50 ErrorException::throwException($level, '{whot}', '{file}', '13');
51 } catch (ErrorException $e) {
52 $this->assertContains('PHP ' . $type, $e->getMessage());
53 $this->assertContains('{whot}', $e->getMessage());
54 $this->assertContains('in {file}', $e->getMessage());
55 $this->assertContains('on line 13', $e->getMessage());
56 }
57 }
58
59 public function getLevels()
60 {
61 return [
62 [E_WARNING, 'Warning'],
63 [E_CORE_WARNING, 'Warning'],
64 [E_COMPILE_WARNING, 'Warning'],
65 [E_USER_WARNING, 'Warning'],
66 [E_STRICT, 'Strict error'],
67 [0, 'Error'],
68 ];
69 }
70
71 /**
72 * @dataProvider getUserLevels
73 */
74 public function testThrowExceptionAsErrorHandler($level, $type)
75 {
76 set_error_handler(['Psy\Exception\ErrorException', 'throwException']);
77 try {
78 trigger_error('{whot}', $level);
79 } catch (ErrorException $e) {
80 $this->assertContains('PHP ' . $type, $e->getMessage());
81 $this->assertContains('{whot}', $e->getMessage());
82 }
83 restore_error_handler();
84 }
85
86 public function getUserLevels()
87 {
88 return [
89 [E_USER_ERROR, 'Error'],
90 [E_USER_WARNING, 'Warning'],
91 [E_USER_NOTICE, 'Notice'],
92 [E_USER_DEPRECATED, 'Deprecated'],
93 ];
94 }
95
96 public function testIgnoreExecutionLoopFilename()
97 {
98 $e = new ErrorException('{{message}}', 0, 1, '/fake/path/to/Psy/ExecutionLoop.php');
99 $this->assertEmpty($e->getFile());
100
101 $e = new ErrorException('{{message}}', 0, 1, 'c:\fake\path\to\Psy\ExecutionLoop.php');
102 $this->assertEmpty($e->getFile());
103
104 $e = new ErrorException('{{message}}', 0, 1, '/fake/path/to/Psy/File.php');
105 $this->assertNotEmpty($e->getFile());
106 }
107 }