forked from docker-php/docker-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerAsyncTest.php
More file actions
86 lines (68 loc) · 2.74 KB
/
Copy pathDockerAsyncTest.php
File metadata and controls
86 lines (68 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
declare(strict_types=1);
namespace Docker\Tests;
use Amp\Loop;
use Docker\API\Model\ContainersCreatePostBody;
use Docker\API\Model\EventsGetResponse200;
use Docker\DockerAsync;
use Docker\Stream\ArtaxCallbackStream;
class DockerAsyncTest extends \PHPUnit\Framework\TestCase
{
public function testStaticConstructor(): void
{
$this->assertInstanceOf(DockerAsync::class, DockerAsync::create());
}
public function testAsync(): void
{
Loop::run(function () {
$docker = DockerAsync::create();
$containerConfig = new ContainersCreatePostBody();
$containerConfig->setImage('busybox:latest');
$containerConfig->setCmd(['echo', '-n', 'output']);
$containerConfig->setAttachStdout(true);
$containerConfig->setLabels(new \ArrayObject(['docker-php-test' => 'true']));
$response = yield $docker->imageCreate('', [
'fromImage' => 'busybox:latest',
], [], DockerAsync::FETCH_RESPONSE);
yield $response->getBody();
$containerCreate = yield $docker->containerCreate($containerConfig);
$containerStart = yield $docker->containerStart($containerCreate->getId());
$containerInfo = yield $docker->containerInspect($containerCreate->getId());
$this->assertSame($containerCreate->getId(), $containerInfo->getId());
});
}
public function testSystemEventsAllowTheConsumptionOfDockerEvents(): void
{
$matchedEvents = [];
Loop::run(function () use (&$matchedEvents) {
$docker = DockerAsync::create();
/** @var ArtaxCallbackStream $events */
$events = yield $docker->systemEvents([
'filters' => \json_encode(
[
'type' => ['container'],
'action' => ['create'],
]
),
]);
$events->onFrame(function ($event) use (&$matchedEvents): void {
if (\is_object($event)
&& $event instanceof EventsGetResponse200
&& 'create' === $event->getAction()
&& 'container' === $event->getType()
) {
$matchedEvents[] = $event;
}
});
$events->listen();
$containerConfig = new ContainersCreatePostBody();
$containerConfig->setImage('busybox:latest');
$containerConfig->setCmd(['echo', '-n', 'output']);
yield $docker->containerCreate($containerConfig);
Loop::delay(1000, function (): void {
Loop::stop();
});
});
$this->assertCount(1, $matchedEvents);
}
}