Skip to content

Commit

Permalink
Use glob that might work on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-xo committed Dec 29, 2021
1 parent a0a05a1 commit 63cef45
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 31 deletions.
6 changes: 3 additions & 3 deletions test/Cached_Dir_PodcastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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));
Expand Down
26 changes: 13 additions & 13 deletions test/CachingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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]);
Expand All @@ -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
Expand All @@ -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]);
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions test/Caching_updates_to_dir2castTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/Caching_updates_to_feed_metadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/Locking_Cached_Dir_PodcastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/RSS_Item_Caching_getID3_Podcast_HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ function prepare_testing_dir()
}
}

function temp_xml_glob()
{
return '.' . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . '*.xml';
}


define('NO_DISPATCHER', true);

Expand Down

0 comments on commit 63cef45

Please sign in to comment.