UndefinedFunctionFatalErrorHandlerTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 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 [
  33. [
  34. [
  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. [
  43. [
  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. [
  52. [
  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. [
  61. [
  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. }