Skip to content

Commit 7c03d98

Browse files
committed
test: add more tests
1 parent 08f37a2 commit 7c03d98

1 file changed

Lines changed: 191 additions & 0 deletions

File tree

tests/Builders/CacheHeaderBuilderTest.php

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,149 @@ public function testMaxAge(): void
5858
);
5959
}
6060

61+
public function testResetMaxAge(): void
62+
{
63+
$builder = (new CacheHeaderBuilder())
64+
->withMaxAge(hours: 1);
65+
$this->assertNotSame([], $builder->toHeaders());
66+
$this->assertSame([], $builder->withoutMaxAge()->toHeaders());
67+
$this->assertNotSame([], $builder->toHeaders());
68+
$this->assertSame([], $builder->resetMaxAge()->toHeaders());
69+
$this->assertSame([], $builder->toHeaders());
70+
}
71+
72+
public function testResetSharedMaxAge(): void
73+
{
74+
$builder = (new CacheHeaderBuilder())
75+
->withSharedMaxAge(hours: 1);
76+
$this->assertNotSame([], $builder->toHeaders());
77+
$this->assertSame([], $builder->withoutSharedMaxAge()->toHeaders());
78+
$this->assertNotSame([], $builder->toHeaders());
79+
$this->assertSame([], $builder->resetSharedMaxAge()->toHeaders());
80+
$this->assertSame([], $builder->toHeaders());
81+
}
82+
83+
public function testResetMustRevalidate(): void
84+
{
85+
$builder = (new CacheHeaderBuilder())
86+
->withMustRevalidate();
87+
$this->assertNotSame([], $builder->toHeaders());
88+
$this->assertSame([], $builder->withoutMustRevalidate()->toHeaders());
89+
$this->assertNotSame([], $builder->toHeaders());
90+
$this->assertSame([], $builder->resetMustRevalidate()->toHeaders());
91+
$this->assertSame([], $builder->toHeaders());
92+
}
93+
94+
public function testResetProxyRevalidate(): void
95+
{
96+
$builder = (new CacheHeaderBuilder())
97+
->withProxyRevalidate();
98+
$this->assertNotSame([], $builder->toHeaders());
99+
$this->assertSame([], $builder->withoutProxyRevalidate()->toHeaders());
100+
$this->assertNotSame([], $builder->toHeaders());
101+
$this->assertSame([], $builder->resetProxyRevalidate()->toHeaders());
102+
$this->assertSame([], $builder->toHeaders());
103+
}
104+
105+
public function testResetNoStore(): void
106+
{
107+
$builder = (new CacheHeaderBuilder())
108+
->withNoStore();
109+
$this->assertNotSame([], $builder->toHeaders());
110+
$this->assertSame([], $builder->withoutNoStore()->toHeaders());
111+
$this->assertNotSame([], $builder->toHeaders());
112+
$this->assertSame([], $builder->resetNoStore()->toHeaders());
113+
$this->assertSame([], $builder->toHeaders());
114+
}
115+
116+
public function testResetPrivate(): void
117+
{
118+
$builder = (new CacheHeaderBuilder())
119+
->withPrivate();
120+
$this->assertNotSame([], $builder->toHeaders());
121+
$this->assertSame([], $builder->withoutPrivate()->toHeaders());
122+
$this->assertNotSame([], $builder->toHeaders());
123+
$this->assertSame([], $builder->resetPrivate()->toHeaders());
124+
$this->assertSame([], $builder->toHeaders());
125+
}
126+
127+
public function testResetPublic(): void
128+
{
129+
$builder = (new CacheHeaderBuilder())
130+
->withPublic();
131+
$this->assertNotSame([], $builder->toHeaders());
132+
$this->assertSame([], $builder->withoutPublic()->toHeaders());
133+
$this->assertNotSame([], $builder->toHeaders());
134+
$this->assertSame([], $builder->resetPublic()->toHeaders());
135+
$this->assertSame([], $builder->toHeaders());
136+
}
137+
138+
public function testResetMustUnderstand(): void
139+
{
140+
$builder = (new CacheHeaderBuilder())
141+
->withMustUnderstand();
142+
$this->assertNotSame([], $builder->toHeaders());
143+
$this->assertSame([], $builder->withoutMustUnderstand()->toHeaders());
144+
$this->assertNotSame([], $builder->toHeaders());
145+
$this->assertSame([], $builder->resetMustUnderstand()->toHeaders());
146+
$this->assertSame([], $builder->toHeaders());
147+
}
148+
149+
public function testResetNoTransform(): void
150+
{
151+
$builder = (new CacheHeaderBuilder())
152+
->withNoTransform();
153+
$this->assertNotSame([], $builder->toHeaders());
154+
$this->assertSame([], $builder->withoutNoTransform()->toHeaders());
155+
$this->assertNotSame([], $builder->toHeaders());
156+
$this->assertSame([], $builder->resetNoTransform()->toHeaders());
157+
$this->assertSame([], $builder->toHeaders());
158+
}
159+
160+
public function testResetImmutable(): void
161+
{
162+
$builder = (new CacheHeaderBuilder())
163+
->withImmutable();
164+
$this->assertNotSame([], $builder->toHeaders());
165+
$this->assertSame([], $builder->withoutImmutable()->toHeaders());
166+
$this->assertNotSame([], $builder->toHeaders());
167+
$this->assertSame([], $builder->resetImmutable()->toHeaders());
168+
$this->assertSame([], $builder->toHeaders());
169+
}
170+
171+
public function testResetStaleWhileRevalidate(): void
172+
{
173+
$builder = (new CacheHeaderBuilder())
174+
->withStaleWhileRevalidate(3600);
175+
$this->assertNotSame([], $builder->toHeaders());
176+
$this->assertSame([], $builder->withoutStaleWhileRevalidate()->toHeaders());
177+
$this->assertNotSame([], $builder->toHeaders());
178+
$this->assertSame([], $builder->resetStaleWhileRevalidate()->toHeaders());
179+
$this->assertSame([], $builder->toHeaders());
180+
}
181+
182+
public function testResetStaleIfError(): void
183+
{
184+
$builder = (new CacheHeaderBuilder())
185+
->withStaleIfError(3600);
186+
$this->assertNotSame([], $builder->toHeaders());
187+
$this->assertSame([], $builder->withoutStaleIfError()->toHeaders());
188+
$this->assertNotSame([], $builder->toHeaders());
189+
$this->assertSame([], $builder->resetStaleIfError()->toHeaders());
190+
$this->assertSame([], $builder->toHeaders());
191+
}
192+
193+
public function testResetETag(): void
194+
{
195+
$builder = (new CacheHeaderBuilder())
196+
->withETag((new ETagHeaderBuilder())->withETag('123456'));
197+
$this->assertNotSame([], $builder->toHeaders());
198+
$this->assertSame([], $builder->withoutETag()->toHeaders());
199+
$this->assertNotSame([], $builder->toHeaders());
200+
$this->assertSame([], $builder->resetETag()->toHeaders());
201+
$this->assertSame([], $builder->toHeaders());
202+
}
203+
61204
public function testMaxAgeWithNoStore(): void
62205
{
63206
$builder = (new CacheHeaderBuilder())
@@ -161,6 +304,44 @@ public function testNoTransform(): void
161304
$this->assertSame(['cache-control' => 'no-transform'], $builder->toHeaders());
162305
}
163306

307+
public function testLastModified(): void
308+
{
309+
$builder = new CacheHeaderBuilder();
310+
$this->assertSame(['last-modified' => 'Sun, 05 Sep 2021 00:00:00 GMT'], $builder->withLastModified(strtotime('Sun, 05 Sep 2021 00:00:00 GMT'))->toHeaders());
311+
$this->assertSame(['last-modified' => 'Sun, 05 Sep 2021 00:00:00 GMT'], $builder->withLastModified(new \DateTime('Sun, 05 Sep 2021 00:00:00 GMT'))->toHeaders());
312+
$this->assertSame(['last-modified' => 'Sun, 05 Sep 2021 00:00:00 GMT'], $builder->withLastModified('Sun, 05 Sep 2021 00:00:00 GMT')->toHeaders());
313+
314+
$builder = (new CacheHeaderBuilder())->lastModified(strtotime('Sun, 05 Sep 2021 00:00:00 GMT'));
315+
$this->assertSame(['last-modified' => 'Sun, 05 Sep 2021 00:00:00 GMT'], $builder->toHeaders());
316+
$builder = (new CacheHeaderBuilder())->lastModified(new \DateTime('Sun, 05 Sep 2021 00:00:00 GMT'));
317+
$this->assertSame(['last-modified' => 'Sun, 05 Sep 2021 00:00:00 GMT'], $builder->toHeaders());
318+
$builder = (new CacheHeaderBuilder())->lastModified('Sun, 05 Sep 2021 00:00:00 GMT');
319+
$this->assertSame(['last-modified' => 'Sun, 05 Sep 2021 00:00:00 GMT'], $builder->toHeaders());
320+
321+
$builder = new CacheHeaderBuilder();
322+
$this->assertSame(['last-modified' => 'Sun, 05 Sep 2021 00:00:00 GMT'], $builder->withLastModified(strtotime('Sun, 05 Sep 2021 00:00:00 GMT'))->toHeaders());
323+
$this->assertSame([], $builder->toHeaders());
324+
$this->assertSame(['last-modified' => 'Sun, 05 Sep 2021 00:00:00 GMT'], $builder->lastModified(strtotime('Sun, 05 Sep 2021 00:00:00 GMT'))->toHeaders());
325+
$this->assertSame(['last-modified' => 'Sun, 05 Sep 2021 00:00:00 GMT'], $builder->toHeaders());
326+
$this->assertSame([], $builder->withoutLastModified()->toHeaders());
327+
$this->assertNotSame([], $builder->toHeaders());
328+
$builder->resetLastModified();
329+
$this->assertSame([], $builder->toHeaders());
330+
}
331+
332+
public function testAge(): void
333+
{
334+
$builder = new CacheHeaderBuilder();
335+
$this->assertSame(['age' => '1'], $builder->withAge(1)->toHeaders());
336+
$this->assertSame([], $builder->toHeaders());
337+
$this->assertSame(['age' => '1'], $builder->age(1)->toHeaders());
338+
$this->assertSame(['age' => '1'], $builder->toHeaders());
339+
$this->assertSame([], $builder->withoutAge()->toHeaders());
340+
$this->assertNotSame([], $builder->toHeaders());
341+
$builder->resetAge();
342+
$this->assertSame([], $builder->toHeaders());
343+
}
344+
164345
public function testStaleWhileRevalidate(): void
165346
{
166347
$builder = (new CacheHeaderBuilder())
@@ -314,4 +495,14 @@ public function testReset(CacheHeaderBuilder $builder): void
314495
$builder->reset();
315496
$this->assertSame([], $builder->toHeaders());
316497
}
498+
499+
public function testResetExpires(): void
500+
{
501+
$builder = (new CacheHeaderBuilder())
502+
->withExpires('Sun, 05 Sep 2021 00:00:00 GMT');
503+
$this->assertNotSame([], $builder->toHeaders());
504+
$this->assertSame([], $builder->withoutExpires()->toHeaders());
505+
$builder->resetExpires();
506+
$this->assertSame([], $builder->toHeaders());
507+
}
317508
}

0 commit comments

Comments
 (0)