FatalErrorExceptionTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2023 Justin Hileman
  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 Psy\Test\Exception;
  11. use Psy\Exception\Exception;
  12. use Psy\Exception\FatalErrorException;
  13. class FatalErrorExceptionTest extends \Psy\Test\TestCase
  14. {
  15. public function testInstance()
  16. {
  17. $e = new FatalErrorException();
  18. $this->assertInstanceOf(Exception::class, $e);
  19. $this->assertInstanceOf(\ErrorException::class, $e);
  20. $this->assertInstanceOf(FatalErrorException::class, $e);
  21. }
  22. public function testMessage()
  23. {
  24. $e = new FatalErrorException('{msg}', 0, 0, '{filename}', 13);
  25. $this->assertSame('{msg}', $e->getRawMessage());
  26. $this->assertStringContainsString('{msg}', $e->getMessage());
  27. $this->assertStringContainsString('{filename}', $e->getMessage());
  28. $this->assertStringContainsString('line 13', $e->getMessage());
  29. }
  30. public function testMessageWithNoFilename()
  31. {
  32. $e = new FatalErrorException('{msg}');
  33. $this->assertSame('{msg}', $e->getRawMessage());
  34. $this->assertStringContainsString('{msg}', $e->getMessage());
  35. $this->assertStringContainsString('eval()\'d code', $e->getMessage());
  36. }
  37. public function testNegativeOneLineNumberIgnored()
  38. {
  39. $e = new FatalErrorException('{msg}', 0, 1, null, -1);
  40. // In PHP 8.0+, the line number will be (as of the time of this change) 53, because it's
  41. // the line where the exception was first constructed. In older PHP versions, it'll be 0.
  42. $this->assertNotEquals(-1, $e->getLine());
  43. if (\version_compare(\PHP_VERSION, '8.0', '<')) {
  44. $this->assertSame(0, $e->getLine());
  45. }
  46. }
  47. }