DirectoryTest.php 1.7 KB

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