UndefinedMethodErrorEnhancerTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\ErrorHandler\Tests\ErrorEnhancer;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\ErrorHandler\Error\UndefinedMethodError;
  13. use Symfony\Component\ErrorHandler\ErrorEnhancer\UndefinedMethodErrorEnhancer;
  14. class UndefinedMethodErrorEnhancerTest extends TestCase
  15. {
  16. /**
  17. * @dataProvider provideUndefinedMethodData
  18. */
  19. public function testEnhance(string $originalMessage, string $enhancedMessage)
  20. {
  21. $enhancer = new UndefinedMethodErrorEnhancer();
  22. $expectedLine = __LINE__ + 1;
  23. $error = $enhancer->enhance(new \Error($originalMessage));
  24. $this->assertInstanceOf(UndefinedMethodError::class, $error);
  25. $this->assertSame($enhancedMessage, $error->getMessage());
  26. $this->assertSame(realpath(__FILE__), $error->getFile());
  27. $this->assertSame($expectedLine, $error->getLine());
  28. }
  29. public static function provideUndefinedMethodData()
  30. {
  31. return [
  32. [
  33. 'Call to undefined method SplObjectStorage::what()',
  34. 'Attempted to call an undefined method named "what" of class "SplObjectStorage".',
  35. ],
  36. [
  37. 'Call to undefined method SplObjectStorage::()',
  38. 'Attempted to call an undefined method named "" of class "SplObjectStorage".',
  39. ],
  40. [
  41. 'Call to undefined method SplObjectStorage::walid()',
  42. "Attempted to call an undefined method named \"walid\" of class \"SplObjectStorage\".\nDid you mean to call \"valid\"?",
  43. ],
  44. [
  45. 'Call to undefined method SplObjectStorage::offsetFet()',
  46. "Attempted to call an undefined method named \"offsetFet\" of class \"SplObjectStorage\".\nDid you mean to call e.g. \"offsetGet\", \"offsetSet\" or \"offsetUnset\"?",
  47. ],
  48. [
  49. 'Call to undefined method class@anonymous::test()',
  50. 'Attempted to call an undefined method named "test" of class "class@anonymous".',
  51. ],
  52. ];
  53. }
  54. }