UndefinedFunctionFatalErrorHandlerTest.php 3.1 KB

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