PhpUnit9CompatTrait.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpZip\Tests\Polyfill;
  4. use PHPUnit\Framework\ExpectationFailedException;
  5. use PHPUnit\Runner\Version;
  6. use SebastianBergmann\RecursionContext\InvalidArgumentException;
  7. trait PhpUnit9CompatTrait
  8. {
  9. /**
  10. * Asserts that a file does not exist.
  11. *
  12. * @param string $filename
  13. * @param string $message
  14. *
  15. * @throws InvalidArgumentException
  16. * @throws ExpectationFailedException
  17. *
  18. * @noinspection PhpDeprecationInspection
  19. */
  20. public static function assertFileDoesNotExist(string $filename, string $message = ''): void
  21. {
  22. if (version_compare(Version::id(), '9.1.0', '<')) {
  23. self::assertFileNotExists($filename, $message);
  24. return;
  25. }
  26. parent::assertFileDoesNotExist($filename, $message);
  27. }
  28. /**
  29. * Asserts that a directory does not exist.
  30. *
  31. * @noinspection PhpDeprecationInspection
  32. *
  33. * @param string $directory
  34. * @param string $message
  35. *
  36. * @throws ExpectationFailedException
  37. * @throws InvalidArgumentException
  38. */
  39. public static function assertDirectoryDoesNotExist(string $directory, string $message = ''): void
  40. {
  41. if (version_compare(Version::id(), '9.1.0', '<')) {
  42. self::assertDirectoryNotExists($directory, $message);
  43. return;
  44. }
  45. parent::assertDirectoryDoesNotExist($directory, $message);
  46. }
  47. }