forked from docker-php/docker-php-api
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathHealthcheckResultNormalizerTest.php
More file actions
66 lines (53 loc) · 2.1 KB
/
HealthcheckResultNormalizerTest.php
File metadata and controls
66 lines (53 loc) · 2.1 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
<?php
declare(strict_types=1);
namespace Docker\API\Tests\Normalizer;
use Docker\API\Model\HealthcheckResult;
use Docker\API\Normalizer\HealthcheckResultNormalizer;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class HealthcheckResultNormalizerTest extends TestCase
{
private HealthcheckResultNormalizer $normalizer;
protected function setUp(): void
{
$this->normalizer = new HealthcheckResultNormalizer();
}
public static function parsedStartProvider(): iterable
{
yield 'nanosecond precision with Z timezone (localstack format)' => [
'2019-12-22T10:59:05.6385933Z',
'2019-12-22',
'10:59:05',
];
yield 'microsecond precision with numeric offset' => [
'2019-12-22T10:59:05.638593+00:00',
'2019-12-22',
'10:59:05',
];
}
#[DataProvider('parsedStartProvider')]
public function testDenormalizeStartParsesDateTime(string $input, string $expectedDate, string $expectedTime): void
{
$result = $this->normalizer->denormalize(['Start' => $input], HealthcheckResult::class);
self::assertInstanceOf(\DateTimeInterface::class, $result->getStart());
self::assertSame($expectedDate, $result->getStart()->format('Y-m-d'));
self::assertSame($expectedTime, $result->getStart()->format('H:i:s'));
}
public static function nullStartProvider(): iterable
{
yield 'explicit null' => [['Start' => null]];
yield 'unparsable string' => [['Start' => 'not-a-date']];
yield 'non-string value' => [['Start' => 12345]];
}
#[DataProvider('nullStartProvider')]
public function testDenormalizeStartReturnsNull(array $data): void
{
$result = $this->normalizer->denormalize($data, HealthcheckResult::class);
self::assertNull($result->getStart());
}
public function testDenormalizeStartNotInitializedWhenKeyMissing(): void
{
$result = $this->normalizer->denormalize([], HealthcheckResult::class);
self::assertFalse($result->isInitialized('start'));
}
}