1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DockerCompose\Tests\Manager; |
4
|
|
|
|
5
|
|
|
use PHPUnit_Framework_TestCase; |
6
|
|
|
use DockerCompose\ComposeFile; |
7
|
|
|
use DockerCompose\ComposeFileCollection; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class ComposeManagerRemoveTest extends PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
public function setUp() |
13
|
|
|
{ |
14
|
|
|
$this->mockedManager = $this->getMockBuilder('\DockerCompose\Manager\ComposeManager') |
15
|
|
|
->setMethods(['execute']) |
16
|
|
|
->getMock(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Test remove whithout error |
21
|
|
|
*/ |
22
|
|
|
public function testRemove() |
23
|
|
|
{ |
24
|
|
|
$this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0)); |
25
|
|
|
$this->assertEquals($this->mockedManager->remove(), 'ok'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Test remove force |
30
|
|
|
*/ |
31
|
|
|
public function testRemoveForce() |
32
|
|
|
{ |
33
|
|
|
$this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0)); |
34
|
|
|
$this->assertEquals($this->mockedManager->remove([], true), 'ok'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Test remove volumes |
39
|
|
|
*/ |
40
|
|
|
public function testRemoveVolumes() |
41
|
|
|
{ |
42
|
|
|
$this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0)); |
43
|
|
|
$this->assertEquals($this->mockedManager->remove([], false, true), 'ok'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Test remove force and volumes |
48
|
|
|
*/ |
49
|
|
|
public function testRemoveForceAndVolumes() |
50
|
|
|
{ |
51
|
|
|
$this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0)); |
52
|
|
|
$this->assertEquals($this->mockedManager->remove([], true, true), 'ok'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Test remove success with one compose file |
57
|
|
|
*/ |
58
|
|
|
public function testRemoveWithOneComposeFileSpecified() |
59
|
|
|
{ |
60
|
|
|
|
61
|
|
|
$this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0)); |
62
|
|
|
$this->assertEquals($this->mockedManager->remove('docker-compose.test.yml'), 'ok'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Test remove success with two compose files |
67
|
|
|
*/ |
68
|
|
|
public function testRemoveWithTwoComposeFilesSpecified() |
69
|
|
|
{ |
70
|
|
|
|
71
|
|
|
$this->mockedManager->method('execute')->willReturn(array('output' => 'ok', 'code' => 0)); |
72
|
|
|
$this->assertEquals($this->mockedManager->remove(['docker-compose.yml', 'docker-compose.test.yml']), 'ok'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Test remove with ComposeFileNotFoundException |
77
|
|
|
* |
78
|
|
|
* @expectedException \DockerCompose\Exception\ComposeFileNotFoundException |
79
|
|
|
*/ |
80
|
|
View Code Duplication |
public function testRemoveThrowComposeFileNotFound() |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
$error = 'Can\'t find a suitable configuration file in this directory or any parent. Are you in the right directory?\n'; |
83
|
|
|
$error .= 'Supported filenames: docker-compose.yml, docker-compose.yaml, fig.yml, fig.yaml'; |
84
|
|
|
$this->mockedManager->method('execute')->willReturn(array('output' => $error, 'code' => 1)); |
85
|
|
|
$this->mockedManager->remove(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Test remove with DockerHostConnexionErrorException |
90
|
|
|
* |
91
|
|
|
* @expectedException \DockerCompose\Exception\DockerHostConnexionErrorException |
92
|
|
|
*/ |
93
|
|
View Code Duplication |
public function testRemoveThrowDockerHostConnexionErrorException() |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$error = 'Couldn\'t connect to Docker daemon at http+docker://localunixsocket - is it running?\n'; |
96
|
|
|
$error .= 'If it\'s at a non-standard location, specify the URL with the DOCKER_HOST environment variable.'; |
97
|
|
|
$this->mockedManager->method('execute')->willReturn(array('output' => $error, 'code' => 1)); |
98
|
|
|
$this->mockedManager->remove(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Test remove with DockerInstallationMissingException |
103
|
|
|
* |
104
|
|
|
* @expectedException \DockerCompose\Exception\DockerInstallationMissingException |
105
|
|
|
*/ |
106
|
|
|
public function testRemoveThrowDockerInstallationMissingException() |
107
|
|
|
{ |
108
|
|
|
$this->mockedManager->method('execute')->willReturn(array('output' => '', 'code' => 127)); |
109
|
|
|
$this->mockedManager->remove(); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.