forked from docker-php/docker-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerClientFactoryTest.php
More file actions
72 lines (58 loc) · 2.37 KB
/
Copy pathDockerClientFactoryTest.php
File metadata and controls
72 lines (58 loc) · 2.37 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
<?php
declare(strict_types=1);
namespace Docker\Tests;
use Docker\DockerClientFactory;
use Http\Client\HttpClient;
class DockerClientFactoryTest extends TestCase
{
protected function tearDown(): void
{
parent::tearDown();
\putenv('DOCKER_TLS_VERIFY');
}
public function testStaticConstructor(): void
{
$this->assertInstanceOf(HttpClient::class, DockerClientFactory::create());
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Connection to docker has been set to use TLS, but no PATH is defined for certificate in DOCKER_CERT_PATH docker environment variable
*/
public function testCreateFromEnvWithoutCertPath(): void
{
\putenv('DOCKER_TLS_VERIFY=1');
DockerClientFactory::createFromEnv();
}
public function testCreateCustomCa(): void
{
\putenv('DOCKER_TLS_VERIFY=1');
\putenv('DOCKER_CERT_PATH=/tmp');
$count = \count(\get_resources('stream-context'));
$client = DockerClientFactory::createFromEnv();
$this->assertInstanceOf(HttpClient::class, $client);
$contexts = \get_resources('stream-context');
$this->assertCount($count + 1, $contexts);
// Get the last stream context.
$context = \stream_context_get_options(\end($contexts));
$this->assertSame('/tmp/ca.pem', $context['ssl']['cafile']);
$this->assertSame('/tmp/cert.pem', $context['ssl']['local_cert']);
$this->assertSame('/tmp/key.pem', $context['ssl']['local_pk']);
}
public function testCreateCustomPeerName(): void
{
\putenv('DOCKER_TLS_VERIFY=1');
\putenv('DOCKER_CERT_PATH=/abc');
\putenv('DOCKER_PEER_NAME=test');
$count = \count(\get_resources('stream-context'));
$client = DockerClientFactory::createFromEnv();
$this->assertInstanceOf(HttpClient::class, $client);
$contexts = \get_resources('stream-context');
$this->assertCount($count + 1, $contexts);
// Get the last stream context.
$context = \stream_context_get_options(\end($contexts));
$this->assertSame('/abc/ca.pem', $context['ssl']['cafile']);
$this->assertSame('/abc/cert.pem', $context['ssl']['local_cert']);
$this->assertSame('/abc/key.pem', $context['ssl']['local_pk']);
$this->assertSame('test', $context['ssl']['peer_name']);
}
}