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