|
1
|
|
|
<?php |
|
2
|
|
|
namespace Naneau\FileGen\Test; |
|
3
|
|
|
|
|
4
|
|
|
use Naneau\FileGen\File\Contents\Copy as CopyContents; |
|
5
|
|
|
use Naneau\FileGen\Structure; |
|
6
|
|
|
use Naneau\FileGen\File; |
|
7
|
|
|
use Naneau\FileGen\Generator; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Copying of files |
|
11
|
|
|
*/ |
|
12
|
|
|
class CopyTest extends \Naneau\FileGen\Test\Generator\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Test copying |
|
16
|
|
|
* |
|
17
|
|
|
* @return void |
|
18
|
|
|
**/ |
|
19
|
|
|
public function testCopy() |
|
20
|
|
|
{ |
|
21
|
|
|
$generator = $this->createGenerator(); |
|
22
|
|
|
|
|
23
|
|
|
$structure = new Structure; |
|
24
|
|
|
$structure |
|
25
|
|
|
->file('foo', 'foo contents') |
|
26
|
|
|
->file( |
|
27
|
|
|
'bar', |
|
28
|
|
|
new CopyContents($generator->getRoot() . '/foo') |
|
|
|
|
|
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
|
|
$generator->generate($structure); |
|
32
|
|
|
|
|
33
|
|
|
// See if structure was generated |
|
34
|
|
|
$this->assertEquals( |
|
35
|
|
|
file_get_contents($generator->getRoot() . '/foo'), |
|
36
|
|
|
'foo contents' |
|
37
|
|
|
); |
|
38
|
|
|
$this->assertEquals( |
|
39
|
|
|
file_get_contents($generator->getRoot() . '/bar'), |
|
40
|
|
|
'foo contents' |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Test copy fail |
|
46
|
|
|
* |
|
47
|
|
|
* @expectedException Naneau\FileGen\File\Contents\Exception |
|
48
|
|
|
* @return void |
|
49
|
|
|
**/ |
|
50
|
|
View Code Duplication |
public function testNotExists() |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
$generator = $this->createGenerator(); |
|
53
|
|
|
|
|
54
|
|
|
$structure = new Structure; |
|
55
|
|
|
$structure |
|
56
|
|
|
->file('foo', 'foo contents') |
|
57
|
|
|
->file( |
|
58
|
|
|
'bar', |
|
59
|
|
|
new CopyContents($generator->getRoot() . '/I-do-not-exist') |
|
|
|
|
|
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
$generator->generate($structure); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Test copy fail |
|
67
|
|
|
* |
|
68
|
|
|
* @expectedException Naneau\FileGen\File\Contents\Exception |
|
69
|
|
|
* @return void |
|
70
|
|
|
**/ |
|
71
|
|
|
public function testNotReadable() |
|
72
|
|
|
{ |
|
73
|
|
|
$generator = $this->createGenerator(); |
|
74
|
|
|
|
|
75
|
|
|
// Create unreadable file |
|
76
|
|
|
touch($generator->getRoot() . '/not-readable'); |
|
77
|
|
|
chmod($generator->getRoot() . '/not-readable', 0000); |
|
78
|
|
|
|
|
79
|
|
|
$structure = new Structure; |
|
80
|
|
|
$structure |
|
81
|
|
|
->file( |
|
82
|
|
|
'bar', |
|
83
|
|
|
new CopyContents($generator->getRoot() . '/not-readable') |
|
|
|
|
|
|
84
|
|
|
); |
|
85
|
|
|
|
|
86
|
|
|
$generator->generate($structure); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: