InteractsWithDeprecationHandlingTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Illuminate\Tests\Testing\Concerns;
  3. use ErrorException;
  4. use Illuminate\Foundation\Testing\Concerns\InteractsWithDeprecationHandling;
  5. use PHPUnit\Framework\TestCase;
  6. class InteractsWithDeprecationHandlingTest extends TestCase
  7. {
  8. use InteractsWithDeprecationHandling;
  9. protected $original;
  10. protected $deprecationsFound = false;
  11. public function setUp(): void
  12. {
  13. parent::setUp();
  14. $this->original = set_error_handler(function () {
  15. $this->deprecationsFound = true;
  16. });
  17. }
  18. public function testWithDeprecationHandling()
  19. {
  20. $this->withDeprecationHandling();
  21. trigger_error('Something is deprecated', E_USER_DEPRECATED);
  22. $this->assertTrue($this->deprecationsFound);
  23. }
  24. public function testWithoutDeprecationHandling()
  25. {
  26. $this->withoutDeprecationHandling();
  27. $this->expectException(ErrorException::class);
  28. $this->expectExceptionMessage('Something is deprecated');
  29. trigger_error('Something is deprecated', E_USER_DEPRECATED);
  30. }
  31. public function tearDown(): void
  32. {
  33. set_error_handler($this->original);
  34. $this->originalDeprecationHandler = null;
  35. $this->deprecationsFound = false;
  36. parent::tearDown();
  37. }
  38. }