1
|
|
|
<?php |
2
|
|
|
use AspectMock\Test as test; |
|
|
|
|
3
|
|
|
|
4
|
|
|
class DockerTest extends \Codeception\TestCase\Test |
5
|
|
|
{ |
6
|
|
|
protected $container; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @var \AspectMock\Proxy\ClassProxy |
10
|
|
|
*/ |
11
|
|
|
protected $baseDocker; |
12
|
|
|
|
13
|
|
|
protected function _before() |
14
|
|
|
{ |
15
|
|
|
$this->baseDocker = test::double('Robo\Task\Docker\Base', [ |
16
|
|
|
'output' => new \Symfony\Component\Console\Output\NullOutput(), |
17
|
|
|
'logger' => new \Psr\Log\NullLogger(), |
18
|
|
|
]); |
19
|
|
|
} |
20
|
|
|
// tests |
21
|
|
View Code Duplication |
public function testDockerBuild() |
22
|
|
|
{ |
23
|
|
|
$docker = test::double('Robo\Task\Docker\Build', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); |
24
|
|
|
|
25
|
|
|
(new \Robo\Task\Docker\Build())->run(); |
26
|
|
|
$docker->verifyInvoked('executeCommand', ['docker build .']); |
27
|
|
|
|
28
|
|
|
(new \Robo\Task\Docker\Build())->tag('something')->run(); |
29
|
|
|
$docker->verifyInvoked('executeCommand', ['docker build -t something .']); |
30
|
|
|
|
31
|
|
|
(new \Robo\Task\Docker\Build())->enableBuildKit()->tag('something')->run(); |
32
|
|
|
$docker->verifyInvoked('executeCommand', ['DOCKER_BUILDKIT=1 docker build -t something .']); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
View Code Duplication |
public function testDockerCommit() |
36
|
|
|
{ |
37
|
|
|
$docker = test::double('Robo\Task\Docker\Commit', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); |
38
|
|
|
|
39
|
|
|
(new \Robo\Task\Docker\Commit('cid'))->run(); |
40
|
|
|
$docker->verifyInvoked('executeCommand', ['docker commit cid ']); |
41
|
|
|
|
42
|
|
|
(new \Robo\Task\Docker\Commit('cid'))->name('somename')->run(); |
43
|
|
|
$docker->verifyInvoked('executeCommand', ['docker commit cid somename ']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
View Code Duplication |
public function testDockerExec() |
47
|
|
|
{ |
48
|
|
|
$docker = test::double('Robo\Task\Docker\Exec', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); |
49
|
|
|
|
50
|
|
|
(new \Robo\Task\Docker\Exec('cid'))->run(); |
51
|
|
|
$docker->verifyInvoked('executeCommand', ['docker exec cid ']); |
52
|
|
|
|
53
|
|
|
(new \Robo\Task\Docker\Exec('cid'))->exec('pwd')->run(); |
54
|
|
|
$docker->verifyInvoked('executeCommand', ['docker exec cid pwd']); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
View Code Duplication |
public function testDockerPull() |
58
|
|
|
{ |
59
|
|
|
$docker = test::double('Robo\Task\Docker\Pull', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); |
60
|
|
|
|
61
|
|
|
(new \Robo\Task\Docker\Pull('image'))->run(); |
62
|
|
|
$docker->verifyInvoked('executeCommand', ['docker pull image ']); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
public function testDockerRemove() |
66
|
|
|
{ |
67
|
|
|
$docker = test::double('Robo\Task\Docker\Remove', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); |
68
|
|
|
|
69
|
|
|
(new \Robo\Task\Docker\Remove('container'))->run(); |
70
|
|
|
$docker->verifyInvoked('executeCommand', ['docker rm container ']); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
View Code Duplication |
public function testDockerRun() |
74
|
|
|
{ |
75
|
|
|
$docker = test::double('Robo\Task\Docker\Run', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger(), 'getUniqId' => '12345']); |
76
|
|
|
|
77
|
|
|
(new \Robo\Task\Docker\Run('cid'))->tmpDir('/tmp')->run(); |
78
|
|
|
$docker->verifyInvoked('executeCommand', ['docker run -i --cidfile /tmp/docker_12345.cid cid']); |
79
|
|
|
|
80
|
|
|
(new \Robo\Task\Docker\Run('cid'))->tmpDir('/tmp')->exec('pwd')->run(); |
81
|
|
|
$docker->verifyInvoked('executeCommand', ['docker run -i --cidfile /tmp/docker_12345.cid cid pwd']); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
View Code Duplication |
public function testDockerStart() |
85
|
|
|
{ |
86
|
|
|
$docker = test::double('Robo\Task\Docker\Start', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); |
87
|
|
|
|
88
|
|
|
(new \Robo\Task\Docker\Start('cid'))->run(); |
89
|
|
|
$docker->verifyInvoked('executeCommand', ['docker start cid']); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
View Code Duplication |
public function testDockerStop() |
93
|
|
|
{ |
94
|
|
|
$docker = test::double('Robo\Task\Docker\Stop', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); |
95
|
|
|
|
96
|
|
|
(new \Robo\Task\Docker\Stop('cid'))->run(); |
97
|
|
|
$docker->verifyInvoked('executeCommand', ['docker stop cid']); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: