UndefinedMethodFatalErrorHandlerTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\UndefinedMethodFatalErrorHandler;
  13. class UndefinedMethodFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * @dataProvider provideUndefinedMethodData
  17. */
  18. public function testUndefinedMethod($error, $translatedMessage)
  19. {
  20. $handler = new UndefinedMethodFatalErrorHandler();
  21. $exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));
  22. $this->assertInstanceOf('Symfony\Component\Debug\Exception\UndefinedMethodException', $exception);
  23. $this->assertSame($translatedMessage, $exception->getMessage());
  24. $this->assertSame($error['type'], $exception->getSeverity());
  25. $this->assertSame($error['file'], $exception->getFile());
  26. $this->assertSame($error['line'], $exception->getLine());
  27. }
  28. public function provideUndefinedMethodData()
  29. {
  30. return array(
  31. array(
  32. array(
  33. 'type' => 1,
  34. 'line' => 12,
  35. 'file' => 'foo.php',
  36. 'message' => 'Call to undefined method SplObjectStorage::what()',
  37. ),
  38. 'Attempted to call an undefined method named "what" of class "SplObjectStorage".',
  39. ),
  40. array(
  41. array(
  42. 'type' => 1,
  43. 'line' => 12,
  44. 'file' => 'foo.php',
  45. 'message' => 'Call to undefined method SplObjectStorage::walid()',
  46. ),
  47. "Attempted to call an undefined method named \"walid\" of class \"SplObjectStorage\".\nDid you mean to call \"valid\"?",
  48. ),
  49. array(
  50. array(
  51. 'type' => 1,
  52. 'line' => 12,
  53. 'file' => 'foo.php',
  54. 'message' => 'Call to undefined method SplObjectStorage::offsetFet()',
  55. ),
  56. "Attempted to call an undefined method named \"offsetFet\" of class \"SplObjectStorage\".\nDid you mean to call e.g. \"offsetGet\", \"offsetSet\" or \"offsetUnset\"?",
  57. ),
  58. );
  59. }
  60. }