1
|
|
|
<?php |
2
|
|
|
namespace Naneau\FileGen\Test\Structure; |
3
|
|
|
|
4
|
|
|
use Naneau\FileGen\Structure; |
5
|
|
|
use Naneau\FileGen\Directory; |
6
|
|
|
use Naneau\FileGen\File; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Test structure generation |
10
|
|
|
*/ |
11
|
|
|
class StructureTest extends \PHPUnit\Framework\TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @return void |
15
|
|
|
**/ |
16
|
|
|
public function testStructure() |
17
|
|
|
{ |
18
|
|
|
// Note leading slashes in some |
19
|
|
|
$structure = new Structure; |
20
|
|
|
$structure |
21
|
|
|
->directory('foo') |
22
|
|
|
->directory('/bar') |
23
|
|
|
->file('foo/bar', 'bar contents') |
24
|
|
|
->file('foo/baz', 'baz contents') |
25
|
|
|
->link('/from/this/file', 'to/this') |
26
|
|
|
->link('/from/another/file', '/to/that'); |
27
|
|
|
|
28
|
|
|
$this->assertInstanceOf( |
29
|
|
|
'Naneau\FileGen\Directory', |
30
|
|
|
$structure->scan('foo') |
31
|
|
|
); |
32
|
|
|
$this->assertInstanceOf( |
33
|
|
|
'Naneau\FileGen\Directory', |
34
|
|
|
$structure->scan('bar') |
35
|
|
|
); |
36
|
|
|
$this->assertInstanceOf( |
37
|
|
|
'Naneau\FileGen\File', |
38
|
|
|
$structure->scan('foo/bar') |
39
|
|
|
); |
40
|
|
|
$this->assertInstanceOf( |
41
|
|
|
'Naneau\FileGen\SymLink', |
42
|
|
|
$structure->scan('to/this') |
43
|
|
|
); |
44
|
|
|
$this->assertInstanceOf( |
45
|
|
|
'Naneau\FileGen\SymLink', |
46
|
|
|
$structure->scan('to/that') |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* test invalid structure |
52
|
|
|
* |
53
|
|
|
* @expectedException Naneau\FileGen\Structure\Exception |
54
|
|
|
* @return void |
55
|
|
|
**/ |
56
|
|
|
public function testDirectoryFileMix() |
57
|
|
|
{ |
58
|
|
|
// Can't add file under a node that's a file already |
59
|
|
|
$structure = new Structure; |
60
|
|
|
$structure |
61
|
|
|
->file('foo', 'bar contents') |
62
|
|
|
->file('foo/baz', 'baz contents'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return void |
67
|
|
|
**/ |
68
|
|
|
public function testParameterDefinition() |
69
|
|
|
{ |
70
|
|
|
// Note leading slashes in some |
71
|
|
|
$structure = new Structure; |
72
|
|
|
$structure |
73
|
|
|
// Throw in a file and directory |
74
|
|
|
->directory('foo') |
75
|
|
|
->file('bar') |
76
|
|
|
|
77
|
|
|
// Simple parameters |
78
|
|
|
->parameter('foo', 'The foo parameter') |
79
|
|
|
->parameter('bar', 'The bar parameter'); |
80
|
|
|
|
81
|
|
|
$this->assertInstanceOf( |
82
|
|
|
'Naneau\FileGen\Directory', |
83
|
|
|
$structure->scan('foo') |
84
|
|
|
); |
85
|
|
|
$this->assertInstanceOf( |
86
|
|
|
'Naneau\FileGen\File', |
87
|
|
|
$structure->scan('bar') |
88
|
|
|
); |
89
|
|
|
$this->assertInstanceOf( |
90
|
|
|
'Naneau\FileGen\Parameter\Parameter', |
91
|
|
|
$structure->getParameterDefinition()->get('foo') |
92
|
|
|
); |
93
|
|
|
$this->assertInstanceOf( |
94
|
|
|
'Naneau\FileGen\Parameter\Parameter', |
95
|
|
|
$structure->getParameterDefinition()->get('bar') |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|