upstream
/
vendor
/
symfony
/
debug
/
Tests
/
FatalErrorHandler
/
UndefinedFunctionFatalErrorHandlerTest.php
UndefinedFunctionFatalErrorHandlerTest.php in UpStream: a Project Management Plugin for WordPress trunk, at vendor/symfony/debug/Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 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 Symfony\Component\Debug\Tests\FatalErrorHandler; |
| 13 | |
| 14 | use PHPUnit\Framework\TestCase; |
| 15 | use Symfony\Component\Debug\Exception\FatalErrorException; |
| 16 | use Symfony\Component\Debug\FatalErrorHandler\UndefinedFunctionFatalErrorHandler; |
| 17 | |
| 18 | class UndefinedFunctionFatalErrorHandlerTest extends TestCase |
| 19 | { |
| 20 | /** |
| 21 | * @dataProvider provideUndefinedFunctionData |
| 22 | */ |
| 23 | public function testUndefinedFunction($error, $translatedMessage) |
| 24 | { |
| 25 | $handler = new UndefinedFunctionFatalErrorHandler(); |
| 26 | $exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line'])); |
| 27 | |
| 28 | $this->assertInstanceOf('Symfony\Component\Debug\Exception\UndefinedFunctionException', $exception); |
| 29 | // class names are case insensitive and PHP/HHVM do not return the same |
| 30 | $this->assertSame(strtolower($translatedMessage), strtolower($exception->getMessage())); |
| 31 | $this->assertSame($error['type'], $exception->getSeverity()); |
| 32 | $this->assertSame($error['file'], $exception->getFile()); |
| 33 | $this->assertSame($error['line'], $exception->getLine()); |
| 34 | } |
| 35 | |
| 36 | public function provideUndefinedFunctionData() |
| 37 | { |
| 38 | return [ |
| 39 | [ |
| 40 | [ |
| 41 | 'type' => 1, |
| 42 | 'line' => 12, |
| 43 | 'file' => 'foo.php', |
| 44 | 'message' => 'Call to undefined function test_namespaced_function()', |
| 45 | ], |
| 46 | "Attempted to call function \"test_namespaced_function\" from the global namespace.\nDid you mean to call \"\\symfony\\component\\debug\\tests\\fatalerrorhandler\\test_namespaced_function\"?", |
| 47 | ], |
| 48 | [ |
| 49 | [ |
| 50 | 'type' => 1, |
| 51 | 'line' => 12, |
| 52 | 'file' => 'foo.php', |
| 53 | 'message' => 'Call to undefined function Foo\\Bar\\Baz\\test_namespaced_function()', |
| 54 | ], |
| 55 | "Attempted to call function \"test_namespaced_function\" from namespace \"Foo\\Bar\\Baz\".\nDid you mean to call \"\\symfony\\component\\debug\\tests\\fatalerrorhandler\\test_namespaced_function\"?", |
| 56 | ], |
| 57 | [ |
| 58 | [ |
| 59 | 'type' => 1, |
| 60 | 'line' => 12, |
| 61 | 'file' => 'foo.php', |
| 62 | 'message' => 'Call to undefined function foo()', |
| 63 | ], |
| 64 | 'Attempted to call function "foo" from the global namespace.', |
| 65 | ], |
| 66 | [ |
| 67 | [ |
| 68 | 'type' => 1, |
| 69 | 'line' => 12, |
| 70 | 'file' => 'foo.php', |
| 71 | 'message' => 'Call to undefined function Foo\\Bar\\Baz\\foo()', |
| 72 | ], |
| 73 | 'Attempted to call function "foo" from namespace "Foo\Bar\Baz".', |
| 74 | ], |
| 75 | ]; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | function test_namespaced_function() |
| 80 | { |
| 81 | } |
| 82 |