1 | <?php |
||
8 | class ImageManagerTest extends TestCase |
||
9 | { |
||
10 | /** |
||
11 | * Return a container manager |
||
12 | * |
||
13 | * @return ImageResource |
||
14 | */ |
||
15 | private function getManager() |
||
19 | |||
20 | public function testPull() |
||
27 | |||
28 | /** |
||
29 | public function testFind() |
||
30 | { |
||
31 | $manager = $this->getManager(); |
||
32 | $image = $manager->find('test', 'foo'); |
||
33 | |||
34 | $this->assertEquals('test', $image->getRepository()); |
||
35 | $this->assertEquals('foo', $image->getTag()); |
||
36 | $this->assertNotNull($image->getId()); |
||
37 | } |
||
38 | |||
39 | public function testFindInexistant() |
||
40 | { |
||
41 | $manager = $this->getManager(); |
||
42 | |||
43 | $this->setExpectedException('\\Docker\\Exception\\ImageNotFoundException', 'Image not found'); |
||
44 | $manager->find('test'); |
||
45 | } |
||
46 | |||
47 | public function testPull() |
||
48 | { |
||
49 | $manager = $this->getManager(); |
||
50 | $image = $manager->pull('cogniteev/echo', 'latest'); |
||
51 | |||
52 | $this->assertEquals('cogniteev/echo', $image->getRepository()); |
||
53 | $this->assertEquals('latest', $image->getTag()); |
||
54 | $this->assertNotNull($image->getId()); |
||
55 | } |
||
56 | |||
57 | public function testFindAll() |
||
58 | { |
||
59 | $manager = $this->getManager(); |
||
60 | |||
61 | $this->assertInternalType('array', $manager->findAll()); |
||
62 | $this->assertGreaterThanOrEqual(1, count($manager->findAll())); |
||
63 | } |
||
64 | |||
65 | public function testFindAllAll() |
||
66 | { |
||
67 | $manager = $this->getManager(); |
||
68 | |||
69 | $images1 = $manager->findAll(); |
||
70 | $images2 = $manager->findAll(false, true); |
||
71 | |||
72 | $this->assertInternalType('array', $images2); |
||
73 | $this->assertGreaterThan(count($images1), count($images2)); |
||
74 | } |
||
75 | |||
76 | public function testFindAllDangling() |
||
77 | { |
||
78 | $manager = $this->getManager(); |
||
79 | |||
80 | $images = $manager->findAll(true); |
||
81 | |||
82 | $this->assertInternalType('array', $images); |
||
83 | $this->assertGreaterThanOrEqual(1, count($images)); |
||
84 | } |
||
85 | |||
86 | public function testRemove() |
||
87 | { |
||
88 | $manager = $this->getManager(); |
||
89 | |||
90 | $image = $manager->find('ubuntu', 'vivid'); |
||
91 | $manager->remove($image, true); |
||
92 | |||
93 | $this->setExpectedException('\\Docker\\Exception\\ImageNotFoundException', 'Image not found'); |
||
94 | $manager->inspect($image); |
||
95 | } |
||
96 | |||
97 | public function testRemoveImages() |
||
98 | { |
||
99 | $containers = ['ubuntu:precise', '69c02692b0c1']; |
||
100 | $manager = $this |
||
101 | ->getMockBuilder('\Docker\Manager\ImageManager') |
||
102 | ->setMethods(['remove']) |
||
103 | ->disableOriginalConstructor() |
||
104 | ->getMock(); |
||
105 | |||
106 | $manager->expects($this->exactly(2)) |
||
107 | ->method('remove') |
||
108 | ->with($this->isInstanceOf('\Docker\Image'), false, false) |
||
109 | ->will($this->returnSelf()); |
||
110 | |||
111 | $manager->removeImages($containers); |
||
112 | } |
||
113 | |||
114 | public function testSearch() |
||
115 | { |
||
116 | $manager = $this->getManager(); |
||
117 | |||
118 | $result = $manager->search('test-image-not-exist'); |
||
119 | $this->assertEmpty($result); |
||
120 | } |
||
121 | |||
122 | public function testTag() |
||
123 | { |
||
124 | $image = $this->getManager()->find('test', 'foo'); |
||
125 | |||
126 | $this->getManager()->tag($image, 'docker-php/unit-test', 'latest'); |
||
127 | |||
128 | $this->assertEquals('docker-php/unit-test', $image->getRepository()); |
||
129 | $this->assertEquals('latest', $image->getTag()); |
||
130 | |||
131 | $newImage = $this->getManager()->find('docker-php/unit-test', 'latest'); |
||
132 | $this->assertEquals($image->getId(), $newImage->getId()); |
||
133 | |||
134 | $this->getManager()->removeImages(array($newImage)); |
||
135 | } |
||
136 | |||
137 | public function testHistory() |
||
138 | { |
||
139 | $image = $this->getManager()->find('test', 'foo'); |
||
140 | $history = $this->getManager()->history($image); |
||
141 | |||
142 | $this->assertGreaterThan(1, count($history)); |
||
143 | $this->assertEquals('/bin/true', $history[0]['CreatedBy']); |
||
144 | }**/ |
||
145 | } |
||
146 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.