UndefinedFunctionErrorEnhancerTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\UndefinedFunctionError;
  13. use Symfony\Component\ErrorHandler\ErrorEnhancer\UndefinedFunctionErrorEnhancer;
  14. class UndefinedFunctionErrorEnhancerTest extends TestCase
  15. {
  16. /**
  17. * @dataProvider provideUndefinedFunctionData
  18. */
  19. public function testEnhance(string $originalMessage, string $enhancedMessage)
  20. {
  21. $enhancer = new UndefinedFunctionErrorEnhancer();
  22. $expectedLine = __LINE__ + 1;
  23. $error = $enhancer->enhance(new \Error($originalMessage));
  24. $this->assertInstanceOf(UndefinedFunctionError::class, $error);
  25. // class names are case insensitive and PHP do not return the same
  26. $this->assertSame(strtolower($enhancedMessage), strtolower($error->getMessage()));
  27. $this->assertSame(realpath(__FILE__), $error->getFile());
  28. $this->assertSame($expectedLine, $error->getLine());
  29. }
  30. public static function provideUndefinedFunctionData()
  31. {
  32. return [
  33. [
  34. 'Call to undefined function test_namespaced_function()',
  35. "Attempted to call function \"test_namespaced_function\" from the global namespace.\nDid you mean to call \"\\symfony\\component\\errorhandler\\tests\\errorenhancer\\test_namespaced_function\"?",
  36. ],
  37. [
  38. 'Call to undefined function Foo\\Bar\\Baz\\test_namespaced_function()',
  39. "Attempted to call function \"test_namespaced_function\" from namespace \"Foo\\Bar\\Baz\".\nDid you mean to call \"\\symfony\\component\\errorhandler\\tests\\errorenhancer\\test_namespaced_function\"?",
  40. ],
  41. [
  42. 'Call to undefined function foo()',
  43. 'Attempted to call function "foo" from the global namespace.',
  44. ],
  45. [
  46. 'Call to undefined function Foo\\Bar\\Baz\\foo()',
  47. 'Attempted to call function "foo" from namespace "Foo\Bar\Baz".',
  48. ],
  49. ];
  50. }
  51. }
  52. function test_namespaced_function()
  53. {
  54. }