|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Docker\Tests\Manager; |
|
4
|
|
|
|
|
5
|
|
|
use Docker\API\Model\ContainerConfig; |
|
6
|
|
|
use Docker\API\Model\ExecConfig; |
|
7
|
|
|
use Docker\API\Model\ExecStartConfig; |
|
8
|
|
|
use Docker\Manager\ContainerManager; |
|
9
|
|
|
use Docker\Manager\ExecManager; |
|
10
|
|
|
use Docker\Tests\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
class ExecManagerTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Return the container manager |
|
16
|
|
|
* |
|
17
|
|
|
* @return ExecManager |
|
18
|
|
|
*/ |
|
19
|
|
|
private function getManager() |
|
20
|
|
|
{ |
|
21
|
|
|
return self::getDocker()->getExecManager(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testStartStream() |
|
25
|
|
|
{ |
|
26
|
|
|
$createContainerResult = $this->createContainer(); |
|
27
|
|
|
|
|
28
|
|
|
$execConfig = new ExecConfig(); |
|
29
|
|
|
$execConfig->setAttachStdout(true); |
|
30
|
|
|
$execConfig->setAttachStderr(true); |
|
31
|
|
|
$execConfig->setCmd(["echo", "output"]); |
|
32
|
|
|
|
|
33
|
|
|
$execCreateResult = $this->getManager()->create($createContainerResult->getId(), $execConfig); |
|
34
|
|
|
|
|
35
|
|
|
$execStartConfig = new ExecStartConfig(); |
|
36
|
|
|
$execStartConfig->setDetach(false); |
|
37
|
|
|
$execStartConfig->setTty(false); |
|
38
|
|
|
|
|
39
|
|
|
$stream = $this->getManager()->start($execCreateResult->getId(), $execStartConfig, [], ExecManager::FETCH_STREAM); |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
$this->assertInstanceOf('Docker\Stream\DockerRawStream', $stream); |
|
42
|
|
|
|
|
43
|
|
|
$stdoutFull = ""; |
|
44
|
|
|
$stream->onStdout(function ($stdout) use (&$stdoutFull) { |
|
|
|
|
|
|
45
|
|
|
$stdoutFull .= $stdout; |
|
46
|
|
|
}); |
|
47
|
|
|
$stream->wait(); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
$this->assertEquals("output\n", $stdoutFull); |
|
50
|
|
|
|
|
51
|
|
|
self::getDocker()->getContainerManager()->kill($createContainerResult->getId(), [ |
|
52
|
|
|
'signal' => 'SIGKILL' |
|
53
|
|
|
]); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
private function createContainer() |
|
57
|
|
|
{ |
|
58
|
|
|
$containerConfig = new ContainerConfig(); |
|
59
|
|
|
$containerConfig->setImage('busybox:latest'); |
|
60
|
|
|
$containerConfig->setCmd(['sh']); |
|
61
|
|
|
$containerConfig->setOpenStdin(true); |
|
62
|
|
|
$containerConfig->setLabels(new \ArrayObject(['docker-php-test' => 'true'])); |
|
63
|
|
|
|
|
64
|
|
|
$containerCreateResult = self::getDocker()->getContainerManager()->create($containerConfig); |
|
65
|
|
|
self::getDocker()->getContainerManager()->start($containerCreateResult->getId()); |
|
66
|
|
|
|
|
67
|
|
|
return $containerCreateResult; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
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: