1
|
|
|
<?php |
2
|
|
|
namespace Robo; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
use Robo\Traits\TestTasksTrait; |
6
|
|
|
|
7
|
|
|
class FilesystemStackTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
use TestTasksTrait; |
10
|
|
|
use Collection\loadTasks; |
11
|
|
|
use Task\Filesystem\loadTasks; |
12
|
|
|
|
13
|
|
|
protected $fixtures; |
14
|
|
|
|
15
|
|
|
public function setUp() |
16
|
|
|
{ |
17
|
|
|
$this->fixtures = new Fixtures(); |
18
|
|
|
$this->initTestTasksTrait(); |
19
|
|
|
$this->fixtures->createAndCdToSandbox(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function tearDown() |
23
|
|
|
{ |
24
|
|
|
$this->fixtures->cleanup(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
View Code Duplication |
public function testDirAndFileCreation() |
28
|
|
|
{ |
29
|
|
|
// Set up a collection to add tasks to |
30
|
|
|
$collection = $this->collectionBuilder(); |
31
|
|
|
|
32
|
|
|
// Set up a filesystem stack |
33
|
|
|
$collection->taskFilesystemStack() |
|
|
|
|
34
|
|
|
->mkdir('simulatedir') |
35
|
|
|
->touch('simulatedir/error.txt'); |
36
|
|
|
|
37
|
|
|
$this->assertFileNotExists('simulatedir/error.txt'); |
38
|
|
|
|
39
|
|
|
// Run the task collection; the files should be present afterwards |
40
|
|
|
$result = $collection->run(); |
41
|
|
|
$this->assertTrue($result->wasSuccessful(), $result->getMessage()); |
42
|
|
|
$this->assertFileExists('simulatedir/error.txt'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testCreateDir() |
46
|
|
|
{ |
47
|
|
|
$this->assertFileNotExists('log/error.txt'); |
48
|
|
|
$result = $this->taskFilesystemStack() |
|
|
|
|
49
|
|
|
->mkdir('log') |
50
|
|
|
->touch('log/error.txt') |
51
|
|
|
->run(); |
52
|
|
|
$this->assertTrue($result->wasSuccessful(), $result->getMessage()); |
53
|
|
|
$this->assertFileExists('log/error.txt'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testDeleteFile() |
57
|
|
|
{ |
58
|
|
|
$this->assertFileExists('a.txt'); |
59
|
|
|
$result = $this->taskFilesystemStack() |
|
|
|
|
60
|
|
|
->stopOnFail() |
61
|
|
|
->remove('a.txt') |
62
|
|
|
->run(); |
63
|
|
|
$this->assertTrue($result->wasSuccessful(), $result->getMessage()); |
64
|
|
|
$this->assertFileNotExists('a.txt'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testCrossVolumeRename() |
68
|
|
|
{ |
69
|
|
|
$fsStack = $this->taskFilesystemStack() |
|
|
|
|
70
|
|
|
->mkdir('log') |
71
|
|
|
->touch('log/error.txt'); |
72
|
|
|
$result = $fsStack->run(); |
73
|
|
|
$this->assertTrue($result->wasSuccessful(), $result->getMessage()); |
74
|
|
|
|
75
|
|
|
// We can't force _rename to run the cross-volume |
76
|
|
|
// code path, so we will directly call the protected |
77
|
|
|
// method crossVolumeRename to test to ensure it works. |
78
|
|
|
// We will get a reference to it via reflection, set |
79
|
|
|
// the reflected method object to public, and then |
80
|
|
|
// call it via reflection. |
81
|
|
|
$class = new \ReflectionClass('\Robo\Task\Filesystem\FilesystemStack'); |
82
|
|
|
$method = $class->getMethod('crossVolumeRename'); |
83
|
|
|
$method->setAccessible(true); |
84
|
|
|
$actualFsStackTask = $fsStack->getCollectionBuilderCurrentTask(); |
85
|
|
|
$method->invokeArgs($actualFsStackTask, ['log', 'logfiles']); |
86
|
|
|
|
87
|
|
|
$this->assertFileNotExists('log/error.txt'); |
88
|
|
|
$this->assertFileExists('logfiles/error.txt'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: