Repository navigation
Expand file tree
/
Copy pathAddressTest.php
More file actions
60 lines (49 loc) · 2.12 KB
/
Copy pathAddressTest.php
File metadata and controls
60 lines (49 loc) · 2.12 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
<?php
declare(strict_types=1);
namespace Test\Unit\Internal\Containers\Address;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;
use TinyBlocks\Collection\Collection;
use TinyBlocks\DockerContainer\Internal\Containers\Address\Address;
use TinyBlocks\DockerContainer\Internal\Containers\Address\Hostname;
use TinyBlocks\DockerContainer\Internal\Containers\Address\IP;
use TinyBlocks\DockerContainer\Internal\Containers\Address\Ports;
final class AddressTest extends TestCase
{
#[RunInSeparateProcess]
public function testGetHostForConnectionReturnsLocalhostWhenOutsideDocker(): void
{
require_once __DIR__ . '/../Overrides/file_exists_outside_docker.php';
/** @Given an Address with a known hostname */
$address = Address::from(
ip: IP::from(value: '172.17.0.2'),
ports: Ports::from(
exposedPorts: Collection::createFrom(elements: [3306]),
hostMappedPorts: Collection::createFrom(elements: [49153])
),
hostname: Hostname::from(value: 'my-container')
);
/** @When getHostForConnection is called outside Docker */
$host = $address->getHostForConnection();
/** @Then it should return 127.0.0.1 */
self::assertSame('127.0.0.1', $host);
}
#[RunInSeparateProcess]
public function testGetHostForConnectionReturnsHostnameWhenInsideDocker(): void
{
require_once __DIR__ . '/../Overrides/file_exists_inside_docker.php';
/** @Given an Address with a known hostname */
$address = Address::from(
ip: IP::from(value: '172.17.0.2'),
ports: Ports::from(
exposedPorts: Collection::createFrom(elements: [3306]),
hostMappedPorts: Collection::createFrom(elements: [49153])
),
hostname: Hostname::from(value: 'my-container')
);
/** @When getHostForConnection is called inside Docker */
$host = $address->getHostForConnection();
/** @Then it should return the container hostname */
self::assertSame('my-container', $host);
}
}