Repository navigation
Expand file tree
/
Copy pathCacheStateTest.php
More file actions
61 lines (52 loc) · 1.82 KB
/
Copy pathCacheStateTest.php
File metadata and controls
61 lines (52 loc) · 1.82 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
<?php
declare(strict_types=1);
namespace Deviantintegral\Har\Tests\Unit;
use Deviantintegral\Har\CacheState;
use Deviantintegral\NullDateTime\ConcreteDateTime;
/**
* @covers \Deviantintegral\Har\CacheState
*/
class CacheStateTest extends HarTestBase
{
public function testSerialize()
{
$serializer = $this->getSerializer();
$expires = new ConcreteDateTime(
new \DateTime('2024-12-31T23:59:59Z')
);
$cacheState = (new CacheState())
->setLastAccess('2024-01-01T12:00:00Z')
->setETag('abc123')
->setHitCount(5)
->setExpires($expires)
->setComment('Test cache state');
$serialized = $serializer->serialize($cacheState, 'json');
$decoded = json_decode($serialized, true);
$this->assertEquals('2024-01-01T12:00:00Z', $decoded['lastAccess']);
$this->assertEquals('abc123', $decoded['eTag']);
$this->assertEquals(5, $decoded['hitCount']);
$this->assertArrayHasKey('expires', $decoded);
$this->assertEquals('Test cache state', $decoded['comment']);
$deserialized = $serializer->deserialize(
$serialized,
CacheState::class,
'json'
);
$this->assertEquals($cacheState, $deserialized);
}
public function testGet()
{
$cacheState = (new CacheState())
->setLastAccess('2024-01-01T12:00:00Z')
->setETag('abc123')
->setHitCount(10);
$this->assertEquals('2024-01-01T12:00:00Z', $cacheState->getLastAccess());
$this->assertEquals('abc123', $cacheState->getETag());
$this->assertEquals(10, $cacheState->getHitCount());
}
public function testDefaultHitCount()
{
$cacheState = new CacheState();
$this->assertEquals(0, $cacheState->getHitCount());
}
}