|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace SilverStripe\VendorPlugin\Tests\Methods; |
| 4 | + |
| 5 | +use Composer\Util\Filesystem; |
| 6 | +use Composer\Util\Platform; |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use SilverStripe\VendorPlugin\Methods\CopyMethod; |
| 9 | +use SilverStripe\VendorPlugin\Methods\SymlinkMethod; |
| 10 | +use SilverStripe\VendorPlugin\Util; |
| 11 | + |
| 12 | +class CopyMethodTest extends TestCase |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @var Filesystem |
| 16 | + */ |
| 17 | + protected $filesystem = null; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var string app base path |
| 21 | + */ |
| 22 | + protected $root = null; |
| 23 | + |
| 24 | + protected function setUp() |
| 25 | + { |
| 26 | + parent::setUp(); |
| 27 | + |
| 28 | + // Get temp dir |
| 29 | + $this->root = Util::joinPaths( |
| 30 | + sys_get_temp_dir(), |
| 31 | + 'CopyMethodTest', |
| 32 | + substr(sha1(uniqid()), 0, 10) |
| 33 | + ); |
| 34 | + |
| 35 | + // Setup filesystem |
| 36 | + $this->filesystem = new Filesystem(); |
| 37 | + $this->filesystem->ensureDirectoryExists($this->root); |
| 38 | + } |
| 39 | + |
| 40 | + protected function tearDown() |
| 41 | + { |
| 42 | + $this->filesystem->remove($this->root); |
| 43 | + parent::tearDown(); |
| 44 | + } |
| 45 | + |
| 46 | + public function testCopy() |
| 47 | + { |
| 48 | + $method = new CopyMethod(); |
| 49 | + $target = Util::joinPaths($this->root, 'resources', 'client'); |
| 50 | + $method->exposeDirectory( |
| 51 | + realpath(__DIR__.'/../fixtures/source/client'), |
| 52 | + $target |
| 53 | + ); |
| 54 | + |
| 55 | + // Ensure file exists |
| 56 | + $this->assertFileExists(Util::joinPaths($this->root, 'resources', 'client', 'subfolder', 'somefile.txt')); |
| 57 | + |
| 58 | + // Folder is a real folder and not a symlink |
| 59 | + $this->assertFalse($this->filesystem->isSymlinkedDirectory($target)); |
| 60 | + $this->assertDirectoryExists($target); |
| 61 | + |
| 62 | + |
| 63 | + // Parent folder is a real folder |
| 64 | + $this->assertFalse($this->filesystem->isSymlinkedDirectory(dirname($target))); |
| 65 | + $this->assertDirectoryExists(dirname($target)); |
| 66 | + } |
| 67 | + |
| 68 | + public function testRecoversFromSymlink() |
| 69 | + { |
| 70 | + $method = new SymlinkMethod(); |
| 71 | + $target = Util::joinPaths($this->root, 'resources', 'client'); |
| 72 | + $method->exposeDirectory( |
| 73 | + realpath(__DIR__.'/../fixtures/source/client'), |
| 74 | + $target |
| 75 | + ); |
| 76 | + |
| 77 | + $this->testCopy(); |
| 78 | + } |
| 79 | +} |
0 commit comments