Skip to content

Commit

Permalink
Add more tests for when files are already in the folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-xo committed Dec 29, 2021
1 parent 45ade36 commit 5311fc8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
32 changes: 32 additions & 0 deletions test/AgeDirTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

use PHPUnit\Framework\TestCase;

final class AgeDirTest extends TestCase
{
public function setUp(): void
{
prepare_testing_dir();
exec('php dir2cast.php --output=out.xml --dont-uncache --ignore-dir2cast-mtime');
}

public function test_age_dir()
{
$mtime1 = filemtime('dir2cast.php');
$mtime2 = filemtime('temp');
$mtime3 = filemtime('.');
$mtime4 = filemtime('out.xml');

age_dir_by('.', 10);

$this->assertEquals($mtime1 - 10, filemtime('dir2cast.php'));
$this->assertEquals($mtime2 - 10, filemtime('temp'));
$this->assertEquals($mtime3 - 10, filemtime('.'));
$this->assertEquals($mtime4 - 10, filemtime('out.xml'));
}

public function tearDown(): void
{
chdir('..');
}
}
17 changes: 1 addition & 16 deletions test/CachingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use PHPUnit\Framework\TestCase;

final class CachingTest extends TestCase
class CachingTest extends TestCase
{
public $file = 'out.xml';
public $output = '';
Expand All @@ -18,21 +18,6 @@ public function setUp(): void
clearstatcache();
}

public function test_age_dir()
{
$mtime1 = filemtime('dir2cast.php');
$mtime2 = filemtime('temp');
$mtime3 = filemtime('.');
$mtime4 = filemtime('out.xml');

age_dir_by('.', 10);

$this->assertEquals($mtime1 - 10, filemtime('dir2cast.php'));
$this->assertEquals($mtime2 - 10, filemtime('temp'));
$this->assertEquals($mtime3 - 10, filemtime('.'));
$this->assertEquals($mtime4 - 10, filemtime('out.xml'));
}

public function test_default_empty_podcast_caches_output_in_default_folder(): void
{
// caches the output in the default temp folder
Expand Down
22 changes: 22 additions & 0 deletions test/CachingTest_prepopulatedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types=1);

use PHPUnit\Framework\TestCase;

class CachingTest_prepopulatedTest extends CachingTest
{
public function setUp(): void
{
prepare_testing_dir();
file_put_contents('pre-existing.mp3', 'test');
touch('pre-existing.mp3', time()-86400);
exec('php dir2cast.php --output=out.xml --dont-uncache --ignore-dir2cast-mtime', $this->output, $this->returncode);
$this->content = file_get_contents($this->file);
clearstatcache();
}

public function tearDown(): void
{
$this->assertEquals(1, preg_match('/pre-existing\.mp3/', file_get_contents($this->file)));
parent::tearDown();
}
}

0 comments on commit 5311fc8

Please sign in to comment.