1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Docker\Tests\Manager; |
4
|
|
|
|
5
|
|
|
use Docker\API\Model\AuthConfig; |
6
|
|
|
use Docker\API\Model\BuildInfo; |
7
|
|
|
use Docker\API\Model\CreateImageInfo; |
8
|
|
|
use Docker\API\Model\PushImageInfo; |
9
|
|
|
use Docker\Context\ContextBuilder; |
10
|
|
|
use Docker\Manager\ImageManager; |
11
|
|
|
use Docker\Tests\TestCase; |
12
|
|
|
|
13
|
|
|
class ImageManagerTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Return a container manager |
17
|
|
|
* |
18
|
|
|
* @return ImageManager |
19
|
|
|
*/ |
20
|
|
|
private function getManager() |
21
|
|
|
{ |
22
|
|
|
return $this->getDocker()->getImageManager(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testBuildStream() |
26
|
|
|
{ |
27
|
|
|
$contextBuilder = new ContextBuilder(); |
28
|
|
|
$contextBuilder->from('ubuntu:precise'); |
29
|
|
|
$contextBuilder->add('/test', 'test file content'); |
30
|
|
|
|
31
|
|
|
$buildStream = $this->getManager()->build($contextBuilder->getContext()->read(), ['t' => 'test-image'], ImageManager::FETCH_STREAM); |
32
|
|
|
|
33
|
|
|
$this->assertInstanceOf('Docker\Stream\BuildStream', $buildStream); |
34
|
|
|
|
35
|
|
|
$lastMessage = ""; |
36
|
|
|
|
37
|
|
|
$buildStream->onFrame(function (BuildInfo $frame) use (&$lastMessage) { |
|
|
|
|
38
|
|
|
$lastMessage = $frame->getStream(); |
39
|
|
|
}); |
40
|
|
|
$buildStream->wait(); |
|
|
|
|
41
|
|
|
|
42
|
|
|
$this->assertContains("Successfully built", $lastMessage); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testBuildObject() |
46
|
|
|
{ |
47
|
|
|
$contextBuilder = new ContextBuilder(); |
48
|
|
|
$contextBuilder->from('ubuntu:precise'); |
49
|
|
|
$contextBuilder->add('/test', 'test file content'); |
50
|
|
|
|
51
|
|
|
$buildInfos = $this->getManager()->build($contextBuilder->getContext()->read(), ['t' => 'test-image'], ImageManager::FETCH_OBJECT); |
52
|
|
|
|
53
|
|
|
$this->assertInternalType('array', $buildInfos); |
54
|
|
|
$this->assertContains("Successfully built", $buildInfos[count($buildInfos) - 1]->getStream()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testCreateStream() |
58
|
|
|
{ |
59
|
|
|
$createImageStream = $this->getManager()->create([ |
60
|
|
|
'fromImage' => 'registry:latest' |
61
|
|
|
], ImageManager::FETCH_STREAM); |
62
|
|
|
|
63
|
|
|
$this->assertInstanceOf('Docker\Stream\CreateImageStream', $createImageStream); |
64
|
|
|
|
65
|
|
|
$firstMessage = null; |
66
|
|
|
|
67
|
|
|
$createImageStream->onFrame(function (CreateImageInfo $createImageInfo) use (&$firstMessage) { |
|
|
|
|
68
|
|
|
if (null === $firstMessage) { |
69
|
|
|
$firstMessage = $createImageInfo->getStatus(); |
70
|
|
|
} |
71
|
|
|
}); |
72
|
|
|
$createImageStream->wait(); |
|
|
|
|
73
|
|
|
|
74
|
|
|
$this->assertContains("Pulling from library/registry", $firstMessage); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testCreateObject() |
78
|
|
|
{ |
79
|
|
|
$createImagesInfos = $this->getManager()->create([ |
80
|
|
|
'fromImage' => 'registry:latest' |
81
|
|
|
], ImageManager::FETCH_OBJECT); |
82
|
|
|
|
83
|
|
|
$this->assertInternalType('array', $createImagesInfos); |
84
|
|
|
$this->assertContains("Pulling from library/registry", $createImagesInfos[0]->getStatus()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testPushStream() |
88
|
|
|
{ |
89
|
|
|
$contextBuilder = new ContextBuilder(); |
90
|
|
|
$contextBuilder->from('ubuntu:precise'); |
91
|
|
|
$contextBuilder->add('/test', 'test file content'); |
92
|
|
|
|
93
|
|
|
$this->getManager()->build($contextBuilder->getContext()->read(), ['t' => 'localhost:5000/test-image'], ImageManager::FETCH_OBJECT); |
94
|
|
|
|
95
|
|
|
$registryConfig = new AuthConfig(); |
96
|
|
|
$registryConfig->setServeraddress('localhost:5000'); |
97
|
|
|
$pushImageStream = $this->getManager()->push('localhost:5000/test-image', [ |
98
|
|
|
'X-Registry-Auth' => $registryConfig |
99
|
|
|
], ImageManager::FETCH_STREAM); |
100
|
|
|
|
101
|
|
|
$this->assertInstanceOf('Docker\Stream\PushStream', $pushImageStream); |
102
|
|
|
|
103
|
|
|
$firstMessage = null; |
104
|
|
|
|
105
|
|
|
$pushImageStream->onFrame(function (PushImageInfo $pushImageInfo) use (&$firstMessage) { |
|
|
|
|
106
|
|
|
if (null === $firstMessage) { |
107
|
|
|
$firstMessage = $pushImageInfo->getStatus(); |
108
|
|
|
} |
109
|
|
|
}); |
110
|
|
|
$pushImageStream->wait(); |
|
|
|
|
111
|
|
|
|
112
|
|
|
$this->assertContains("The push refers to a repository [localhost:5000/test-image]", $firstMessage); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testPushObject() |
116
|
|
|
{ |
117
|
|
|
$contextBuilder = new ContextBuilder(); |
118
|
|
|
$contextBuilder->from('ubuntu:precise'); |
119
|
|
|
$contextBuilder->add('/test', 'test file content'); |
120
|
|
|
|
121
|
|
|
$this->getManager()->build($contextBuilder->getContext()->read(), ['t' => 'localhost:5000/test-image'], ImageManager::FETCH_OBJECT); |
122
|
|
|
|
123
|
|
|
$registryConfig = new AuthConfig(); |
124
|
|
|
$registryConfig->setServeraddress('localhost:5000'); |
125
|
|
|
$pushImageInfos = $this->getManager()->push('localhost:5000/test-image', [ |
126
|
|
|
'X-Registry-Auth' => $registryConfig |
127
|
|
|
], ImageManager::FETCH_OBJECT); |
128
|
|
|
|
129
|
|
|
$this->assertInternalType('array', $pushImageInfos); |
130
|
|
|
$this->assertContains("The push refers to a repository [localhost:5000/test-image]", $pushImageInfos[0]->getStatus()); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: