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