File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \StaticCaching ;
4+
5+ use PHPUnit \Framework \Attributes \Test ;
6+ use Statamic \StaticCaching \Cachers \Writer ;
7+ use Tests \TestCase ;
8+
9+ class WriterTest extends TestCase
10+ {
11+ private string $ path ;
12+
13+ public function setUp (): void
14+ {
15+ parent ::setUp ();
16+
17+ $ this ->path = storage_path ('framework/testing/static-cache-writer/page.html ' );
18+
19+ @unlink ($ this ->path );
20+ }
21+
22+ public function tearDown (): void
23+ {
24+ @unlink ($ this ->path );
25+
26+ parent ::tearDown ();
27+ }
28+
29+ #[Test]
30+ public function it_writes_the_content_to_disk ()
31+ {
32+ $ written = (new Writer )->write ($ this ->path , '<html>hello</html> ' );
33+
34+ $ this ->assertTrue ($ written );
35+ $ this ->assertSame ('<html>hello</html> ' , file_get_contents ($ this ->path ));
36+ }
37+
38+ #[Test]
39+ public function it_truncates_stale_bytes_when_overwriting_with_shorter_content ()
40+ {
41+ $ writer = new Writer ;
42+
43+ $ writer ->write ($ this ->path , '<html>this is a much longer page</html> ' );
44+ $ writer ->write ($ this ->path , '<html>short</html> ' );
45+
46+ $ this ->assertSame ('<html>short</html> ' , file_get_contents ($ this ->path ));
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments