菜谱项目

UndefinedMethodFatalErrorHandlerTest.php 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 array(
  32. array(
  33. array(
  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. array(
  42. array(
  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. array(
  51. array(
  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. array(
  60. array(
  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. }