diff --git a/test/Cached_Dir_PodcastTest.php b/test/Cached_Dir_PodcastTest.php index 3edd236..7d13d84 100644 --- a/test/Cached_Dir_PodcastTest.php +++ b/test/Cached_Dir_PodcastTest.php @@ -29,10 +29,10 @@ public function test_generate_saves_a_cache_file() $this->createTestItems(); age_dir_by('.', 3600); - $this->assertEmpty(glob('temp/*')); + $this->assertEmpty(glob('temp' . DIRECTORY_SEPARATOR . '*')); $mp = $this->newPodcast(); $content = $mp->generate(); - $this->assertNotEmpty(glob('temp/*')); + $this->assertNotEmpty(glob('temp' . DIRECTORY_SEPARATOR . '*')); } public function test_uses_generated_cache_file_if_min_time_not_elapsed_yet() @@ -99,7 +99,7 @@ public function test_renews_cache_if_old_but_not_stale() $this->assertEquals($content, $content2); clearstatcache(); - foreach(glob('temp/*.xml') as $filename) + foreach(glob(temp_xml_glob()) as $filename) { // cache file should have been refreshed $this->assertGreaterThan(time() - 3, filemtime($filename)); diff --git a/test/CachingTest.php b/test/CachingTest.php index 26da98b..65e37a9 100644 --- a/test/CachingTest.php +++ b/test/CachingTest.php @@ -22,7 +22,7 @@ public function test_default_empty_podcast_caches_output_in_default_folder(): vo { // caches the output in the default temp folder $this->assertTrue(is_dir('./temp')); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); $this->assertCount(1, $cached_output_files); // caches what was generated @@ -34,7 +34,7 @@ public function test_default_empty_podcast_caches_output_in_default_folder(): vo public function test_default_empty_podcast_doesnt_regenerate_in_first_MIN_CACHE_TIME(): void { - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); age_dir_by('.', 7); // bring cache within last 5 seconds @@ -46,7 +46,7 @@ public function test_default_empty_podcast_doesnt_regenerate_in_first_MIN_CACHE_ exec('php dir2cast.php --output=out.xml --dont-uncache --ignore-dir2cast-mtime', $new_output, $this->returncode); clearstatcache(); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); $cached_mtime_after = filemtime($cached_output_files[0]); $this->assertSame( @@ -63,7 +63,7 @@ public function test_default_empty_podcast_doesnt_regenerate_in_first_MIN_CACHE_ public function test_default_empty_podcast_renews_cache_file_mtime_after_MIN_CACHE_TIME(): void { - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); age_dir_by('.', 7); // leave cache file 7 seconds ago (default threshold is 5 seconds) @@ -74,7 +74,7 @@ public function test_default_empty_podcast_renews_cache_file_mtime_after_MIN_CAC exec('php dir2cast.php --output=out.xml --dont-uncache --ignore-dir2cast-mtime', $new_output, $this->returncode); clearstatcache(); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); $cached_mtime_after = filemtime($cached_output_files[0]); $this->assertGreaterThan( @@ -91,7 +91,7 @@ public function test_default_empty_podcast_renews_cache_file_mtime_after_MIN_CAC public function test_default_empty_podcast_doesnt_regenerate_before_MIN_CACHE_TIME_with_a_change(): void { - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); age_dir_by('.', 7); // bring cache within last 5 seconds @@ -107,7 +107,7 @@ public function test_default_empty_podcast_doesnt_regenerate_before_MIN_CACHE_TI exec('php dir2cast.php --output=out.xml --dont-uncache --ignore-dir2cast-mtime', $new_output, $this->returncode); clearstatcache(); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); $cached_mtime_after = filemtime($cached_output_files[0]); $this->assertSame( @@ -126,7 +126,7 @@ public function test_default_empty_podcast_doesnt_regenerate_before_MIN_CACHE_TI public function test_default_empty_podcast_regenerates_after_MIN_CACHE_TIME_with_a_change(): void { - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); age_dir_by('.', 90); // leave cache file 7 seconds ago (default threshold is 5 seconds) @@ -141,7 +141,7 @@ public function test_default_empty_podcast_regenerates_after_MIN_CACHE_TIME_with exec('php dir2cast.php --output=out.xml --dont-uncache --ignore-dir2cast-mtime', $new_output, $this->returncode); clearstatcache(); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); $cached_mtime_after = filemtime($cached_output_files[0]); $this->assertGreaterThan( @@ -209,7 +209,7 @@ public function test_expired_podcast_is_regenerated(): void { age_dir_by('.', 86400); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); clearstatcache(); $old_mtime = filemtime($cached_output_files[0]); @@ -223,7 +223,7 @@ public function test_expired_podcast_is_regenerated(): void $this->assertEquals(1, preg_match('/empty\.mp3/', $new_content)); clearstatcache(); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); $new_mtime = filemtime($cached_output_files[0]); // cache file should be refreshed @@ -234,7 +234,7 @@ public function test_too_new_file_not_included_in_podcast(): void { age_dir_by('.', 86400); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); clearstatcache(); $old_mtime = filemtime($cached_output_files[0]); @@ -254,7 +254,7 @@ public function test_too_new_file_not_included_in_podcast(): void $this->assertEquals(0, preg_match('/empty\.mp3/', $new_content)); clearstatcache(); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); $new_mtime = filemtime($cached_output_files[0]); // cache file should be refreshed diff --git a/test/Caching_updates_to_dir2castTest.php b/test/Caching_updates_to_dir2castTest.php index f052351..150ec69 100644 --- a/test/Caching_updates_to_dir2castTest.php +++ b/test/Caching_updates_to_dir2castTest.php @@ -10,6 +10,11 @@ class Caching_updates_to_dir2castTest extends TestCase public $content = ''; + public function temp_xml_glob() + { + return '.' . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . '*.xml'; + } + public function setUp(): void { prepare_testing_dir(); @@ -37,7 +42,7 @@ public function test_update_to_dir2cast_php_invalidates_cache(): void { file_put_contents('empty.mp3', 'test'); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); touch('dir2cast.php', time()-3600); // older than the minimum cache time, but newer than the cache files @@ -51,7 +56,7 @@ public function test_update_to_dir2cast_php_invalidates_cache(): void // passthru('ls -laR'); clearstatcache(); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); $new_mtime = filemtime($cached_output_files[0]); // cache file should be refreshed @@ -70,7 +75,7 @@ public function test_update_to_dir2cast_ini_invalidates_cache(): void copy('../../dir2cast.ini', 'dir2cast.ini'); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); touch('dir2cast.ini', time()-3600); // older than the minimum cache time, but newer than the cache files @@ -82,7 +87,7 @@ public function test_update_to_dir2cast_ini_invalidates_cache(): void // print(implode("\n", $debug_out)); clearstatcache(); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); $new_mtime = filemtime($cached_output_files[0]); // cache file should be refreshed diff --git a/test/Caching_updates_to_feed_metadataTest.php b/test/Caching_updates_to_feed_metadataTest.php index fd0b0f4..4c07f65 100644 --- a/test/Caching_updates_to_feed_metadataTest.php +++ b/test/Caching_updates_to_feed_metadataTest.php @@ -35,7 +35,7 @@ public function setUp(): void protected function _update_feed() { - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); clearstatcache(); $old_mtime = filemtime($cached_output_files[0]); @@ -44,7 +44,7 @@ protected function _update_feed() // print(implode("\n", $debug_out)); clearstatcache(); - $cached_output_files = glob('./temp/*.xml'); + $cached_output_files = glob(temp_xml_glob()); $new_mtime = filemtime($cached_output_files[0]); // cache file should be refreshed diff --git a/test/Locking_Cached_Dir_PodcastTest.php b/test/Locking_Cached_Dir_PodcastTest.php index 040a437..ca4edf1 100644 --- a/test/Locking_Cached_Dir_PodcastTest.php +++ b/test/Locking_Cached_Dir_PodcastTest.php @@ -25,7 +25,7 @@ public function test_cache_file_is_locked() $content = $mp->generate(); unset($mp); - foreach(glob('temp/*.xml') as $cachefile) + foreach(glob(temp_xml_glob()) as $cachefile) { $fh = fopen($cachefile, 'a'); $this->assertTrue(flock($fh, LOCK_NB | LOCK_EX)); @@ -35,7 +35,7 @@ public function test_cache_file_is_locked() $mp2 = $this->newPodcast(); $content2 = $mp2->generate(); - foreach(glob('temp/*.xml') as $cachefile) + foreach(glob(temp_xml_glob()) as $cachefile) { $fh = fopen($cachefile, 'a'); $this->assertFalse(flock($fh, LOCK_NB | LOCK_EX)); @@ -45,11 +45,11 @@ public function test_cache_file_is_locked() public function test_temporary_lockfile_is_deleted_if_not_used() { - $this->assertEmpty(glob('temp/*')); + $this->assertEmpty(glob('temp' . DIRECTORY_SEPARATOR . '*')); $mp = $this->newPodcast(); - $this->assertNotEmpty(glob('temp/*')); + $this->assertNotEmpty(glob('temp' . DIRECTORY_SEPARATOR . '*')); unset($mp); - $this->assertEmpty(glob('temp/*')); + $this->assertEmpty(glob('temp' . DIRECTORY_SEPARATOR . '*')); } public static function tearDownAfterClass(): void diff --git a/test/RSS_Item_Caching_getID3_Podcast_HelperTest.php b/test/RSS_Item_Caching_getID3_Podcast_HelperTest.php index 6af3740..2d88645 100644 --- a/test/RSS_Item_Caching_getID3_Podcast_HelperTest.php +++ b/test/RSS_Item_Caching_getID3_Podcast_HelperTest.php @@ -61,9 +61,9 @@ public function test_changed_file_is_rescanned() public function test_empty_rss_item() { - $this->assertCount(0, glob('temp/*')); + $this->assertCount(0, glob('temp' . DIRECTORY_SEPARATOR . '*')); parent::test_empty_rss_item(); - $this->assertCount(1, glob('temp/*')); + $this->assertCount(1, glob('temp' . DIRECTORY_SEPARATOR . '*')); // now do it again, from the cache $mp = new MyPodcast(); @@ -88,9 +88,9 @@ public function test_empty_rss_item() public function test_id3v1_artist_album_title() { - $this->assertCount(0, glob('temp/*')); + $this->assertCount(0, glob('temp' . DIRECTORY_SEPARATOR . '*')); parent::test_id3v1_artist_album_title(); - $this->assertCount(1, glob('temp/*')); + $this->assertCount(1, glob('temp' . DIRECTORY_SEPARATOR . '*')); $mp = new MyPodcast(); $mock = $this->getid3_helper_mock(); diff --git a/test/bootstrap.php b/test/bootstrap.php index 800d89f..e24b79e 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -79,6 +79,11 @@ function prepare_testing_dir() } } +function temp_xml_glob() +{ + return '.' . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . '*.xml'; +} + define('NO_DISPATCHER', true);