diff --git a/test/CachingTest.php b/test/CachingTest.php index 1c48437..26da98b 100644 --- a/test/CachingTest.php +++ b/test/CachingTest.php @@ -227,7 +227,7 @@ public function test_expired_podcast_is_regenerated(): void $new_mtime = filemtime($cached_output_files[0]); // cache file should be refreshed - $this->assertNotEquals($old_mtime, $new_mtime); + $this->assertGreaterThan($old_mtime, $new_mtime); } public function test_too_new_file_not_included_in_podcast(): void @@ -258,72 +258,12 @@ public function test_too_new_file_not_included_in_podcast(): void $new_mtime = filemtime($cached_output_files[0]); // cache file should be refreshed - $this->assertNotEquals($old_mtime, $new_mtime); - } - - public function test_update_to_dir2cast_php_invalidates_cache(): void - { - file_put_contents('empty.mp3', 'test'); - - $source_file = readlink('dir2cast.php'); - unlink('dir2cast.php'); - copy($source_file, 'dir2cast.php'); - - age_dir_by('.', 86400); - - $cached_output_files = glob('./temp/*.xml'); - - touch('dir2cast.php', time()-3600); // older than the minimum cache time, but newer than the cache files - - clearstatcache(); - $old_mtime = filemtime($cached_output_files[0]); - - exec('php dir2cast.php --output=out.xml --dont-uncache --min-file-age=30'); - $new_content = file_get_contents($this->file); // should have empty.mp3 - $this->assertNotEquals($this->content, $new_content); - $this->assertEquals(1, preg_match('/empty\.mp3/', $new_content)); - - clearstatcache(); - $cached_output_files = glob('./temp/*.xml'); - $new_mtime = filemtime($cached_output_files[0]); - - // cache file should be refreshed - $this->assertNotEquals($old_mtime, $new_mtime); - } - - public function test_update_to_dir2cast_ini_invalidates_cache(): void - { - file_put_contents('empty.mp3', 'test'); - - $source_file = readlink('dir2cast.php'); - unlink('dir2cast.php'); - copy($source_file, 'dir2cast.php'); - copy('../../dir2cast.ini', 'dir2cast.ini'); - - age_dir_by('.', 86400); - - $cached_output_files = glob('./temp/*.xml'); - - touch('dir2cast.ini', time()-3600); // older than the minimum cache time, but newer than the cache files - - clearstatcache(); - $old_mtime = filemtime($cached_output_files[0]); - - exec('php dir2cast.php --output=out.xml --dont-uncache --min-file-age=30'); - $new_content = file_get_contents($this->file); // should have empty.mp3 - $this->assertNotEquals($this->content, $new_content); - $this->assertEquals(1, preg_match('/empty\.mp3/', $new_content)); - - clearstatcache(); - $cached_output_files = glob('./temp/*.xml'); - $new_mtime = filemtime($cached_output_files[0]); - - // cache file should be refreshed - $this->assertNotEquals($old_mtime, $new_mtime); + $this->assertGreaterThan($old_mtime, $new_mtime); } public function tearDown(): void { + unlink($this->file); chdir('..'); } } diff --git a/test/Caching_updates_to_dir2castTest.php b/test/Caching_updates_to_dir2castTest.php new file mode 100644 index 0000000..f052351 --- /dev/null +++ b/test/Caching_updates_to_dir2castTest.php @@ -0,0 +1,103 @@ +output, $this->returncode); + $this->content = file_get_contents($this->file); + + age_dir_by('.', 86400); + } + + public function test_update_to_dir2cast_php_invalidates_cache(): void + { + file_put_contents('empty.mp3', 'test'); + + $cached_output_files = glob('./temp/*.xml'); + + touch('dir2cast.php', time()-3600); // older than the minimum cache time, but newer than the cache files + + clearstatcache(); + $old_mtime = filemtime($cached_output_files[0]); + + sleep(1); + exec('php dir2cast.php --output=out.xml --dont-uncache --min-file-age=30 --debug', $debug_out); + // print(implode("\n", $debug_out)); + + // passthru('ls -laR'); + + clearstatcache(); + $cached_output_files = glob('./temp/*.xml'); + $new_mtime = filemtime($cached_output_files[0]); + + // cache file should be refreshed + $this->assertGreaterThan($old_mtime, $new_mtime); + + $new_content = file_get_contents($this->file); + $this->assertNotEquals($this->content, $new_content); + + // empty.mp3 still too new + $this->assertEquals(0, preg_match('/empty\.mp3/', $new_content)); + } + + public function test_update_to_dir2cast_ini_invalidates_cache(): void + { + file_put_contents('empty.mp3', 'test'); + + copy('../../dir2cast.ini', 'dir2cast.ini'); + + $cached_output_files = glob('./temp/*.xml'); + + touch('dir2cast.ini', time()-3600); // older than the minimum cache time, but newer than the cache files + + clearstatcache(); + $old_mtime = filemtime($cached_output_files[0]); + + sleep(1); + exec('php dir2cast.php --output=out.xml --dont-uncache --min-file-age=30 --debug', $debug_out); + // print(implode("\n", $debug_out)); + + clearstatcache(); + $cached_output_files = glob('./temp/*.xml'); + $new_mtime = filemtime($cached_output_files[0]); + + // cache file should be refreshed + $this->assertGreaterThan($old_mtime, $new_mtime); + + $new_content = file_get_contents($this->file); + $this->assertNotEquals($this->content, $new_content); + + // empty.mp3 still too new + $this->assertEquals(0, preg_match('/empty\.mp3/', $new_content)); + } + + public function tearDown(): void + { + unlink($this->file); + chdir('..'); + } +} diff --git a/test/Caching_updates_to_dir2cast_prepopulatedTest.php b/test/Caching_updates_to_dir2cast_prepopulatedTest.php new file mode 100644 index 0000000..31035b0 --- /dev/null +++ b/test/Caching_updates_to_dir2cast_prepopulatedTest.php @@ -0,0 +1,37 @@ +output, $this->returncode); + $this->content = file_get_contents($this->file); + + age_dir_by('.', 86400); + } + + public function tearDown(): void + { + $this->assertEquals(1, preg_match('/pre-existing\.mp3/', file_get_contents($this->file))); + parent::tearDown(); + } +}