DirectoryTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Cache;
  13. use PhpCsFixer\Cache\Directory;
  14. use PhpCsFixer\Cache\DirectoryInterface;
  15. use PhpCsFixer\Tests\TestCase;
  16. /**
  17. * @author Andreas Möller <am@localheinz.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Cache\Directory
  22. */
  23. final class DirectoryTest extends TestCase
  24. {
  25. public function testIsFinal(): void
  26. {
  27. $reflection = new \ReflectionClass(Directory::class);
  28. self::assertTrue($reflection->isFinal());
  29. }
  30. public function testImplementsDirectoryInterface(): void
  31. {
  32. $reflection = new \ReflectionClass(Directory::class);
  33. self::assertTrue($reflection->implementsInterface(DirectoryInterface::class));
  34. }
  35. public function testGetRelativePathToReturnsFileIfAboveLevelOfDirectoryName(): void
  36. {
  37. $directoryName = __DIR__.\DIRECTORY_SEPARATOR.'foo';
  38. $file = __DIR__.\DIRECTORY_SEPARATOR.'hello.php';
  39. $directory = new Directory($directoryName);
  40. self::assertSame($file, $directory->getRelativePathTo($file));
  41. }
  42. public function testGetRelativePathToReturnsRelativePathIfWithinDirectoryName(): void
  43. {
  44. $directoryName = __DIR__.\DIRECTORY_SEPARATOR.'foo';
  45. $file = __DIR__.\DIRECTORY_SEPARATOR.'foo'.\DIRECTORY_SEPARATOR.'bar'.\DIRECTORY_SEPARATOR.'hello.php';
  46. $directory = new Directory($directoryName);
  47. self::assertSame('bar'.\DIRECTORY_SEPARATOR.'hello.php', $directory->getRelativePathTo($file));
  48. }
  49. }