UndefinedMethodFatalErrorHandlerTest.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\UndefinedMethodFatalErrorHandler;
  14. class UndefinedMethodFatalErrorHandlerTest extends TestCase
  15. {
  16. /**
  17. * @dataProvider provideUndefinedMethodData
  18. */
  19. public function testUndefinedMethod($error, $translatedMessage)
  20. {
  21. $handler = new UndefinedMethodFatalErrorHandler();
  22. $exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));
  23. $this->assertInstanceOf('Symfony\Component\Debug\Exception\UndefinedMethodException', $exception);
  24. $this->assertSame($translatedMessage, $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 provideUndefinedMethodData()
  30. {
  31. return [
  32. [
  33. [
  34. 'type' => 1,
  35. 'line' => 12,
  36. 'file' => 'foo.php',
  37. 'message' => 'Call to undefined method SplObjectStorage::what()',
  38. ],
  39. 'Attempted to call an undefined method named "what" of class "SplObjectStorage".',
  40. ],
  41. [
  42. [
  43. 'type' => 1,
  44. 'line' => 12,
  45. 'file' => 'foo.php',
  46. 'message' => 'Call to undefined method SplObjectStorage::walid()',
  47. ],
  48. "Attempted to call an undefined method named \"walid\" of class \"SplObjectStorage\".\nDid you mean to call \"valid\"?",
  49. ],
  50. [
  51. [
  52. 'type' => 1,
  53. 'line' => 12,
  54. 'file' => 'foo.php',
  55. 'message' => 'Call to undefined method SplObjectStorage::offsetFet()',
  56. ],
  57. "Attempted to call an undefined method named \"offsetFet\" of class \"SplObjectStorage\".\nDid you mean to call e.g. \"offsetGet\", \"offsetSet\" or \"offsetUnset\"?",
  58. ],
  59. [
  60. [
  61. 'type' => 1,
  62. 'message' => 'Call to undefined method class@anonymous::test()',
  63. 'file' => '/home/possum/work/symfony/test.php',
  64. 'line' => 11,
  65. ],
  66. 'Attempted to call an undefined method named "test" of class "class@anonymous".',
  67. ],
  68. ];
  69. }
  70. }