forked from ben-xo/dir2cast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocking_Cached_Dir_PodcastTest.php
60 lines (49 loc) · 1.58 KB
/
Locking_Cached_Dir_PodcastTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
class Locking_Cached_Dir_PodcastTest extends Cached_Dir_PodcastTest
{
public static function setUpBeforeClass(): void
{
Cached_Dir_PodcastTest::setUpBeforeClass();
}
public function newPodcast($offset=0)
{
$podcast = new Locking_Cached_Dir_Podcast('.', './temp');
$podcast->setClockOffset($offset);
$podcast->init();
return $podcast;
}
public function test_cache_file_is_locked()
{
$filemtime = $this->createTestItems();
$mp = $this->newPodcast();
$content = $mp->generate();
unset($mp);
foreach(glob(temp_xml_glob()) as $cachefile)
{
$fh = fopen($cachefile, 'a');
$this->assertTrue(flock($fh, LOCK_NB | LOCK_EX));
fclose($fh);
}
$mp2 = $this->newPodcast();
$content2 = $mp2->generate();
foreach(glob(temp_xml_glob()) as $cachefile)
{
$fh = fopen($cachefile, 'a');
$this->assertFalse(flock($fh, LOCK_NB | LOCK_EX));
fclose($fh);
}
}
public function test_temporary_lockfile_is_deleted_if_not_used()
{
$this->assertEmpty(glob('temp' . DIRECTORY_SEPARATOR . '*'));
$mp = $this->newPodcast();
$this->assertNotEmpty(glob('temp' . DIRECTORY_SEPARATOR . '*'));
unset($mp);
$this->assertEmpty(glob('temp' . DIRECTORY_SEPARATOR . '*'));
}
public static function tearDownAfterClass(): void
{
Cached_Dir_PodcastTest::tearDownAfterClass();
}
}