|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BasicTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_semaphore\Interfaces\ISemaphore; |
|
7
|
|
|
use kalanis\kw_semaphore\Semaphore; |
|
8
|
|
|
use kalanis\kw_semaphore\SemaphoreException; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class VolumeTest extends \CommonTestClass |
|
12
|
|
|
{ |
|
13
|
|
|
public function tearDown(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'dummy' . ISemaphore::EXT_SEMAPHORE; |
|
16
|
|
|
if (is_file($path)) { |
|
17
|
|
|
unlink($path); |
|
18
|
|
|
} |
|
19
|
|
|
if (is_dir($path)) { |
|
20
|
|
|
rmdir($path); |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @throws SemaphoreException |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testVolumeCorrect(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$lib = $this->getSemaphore(); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertFalse($lib->has()); |
|
32
|
|
|
$this->assertTrue($lib->want()); |
|
33
|
|
|
$this->assertTrue($lib->has()); |
|
34
|
|
|
$this->assertTrue($lib->remove()); |
|
35
|
|
|
$this->assertFalse($lib->has()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @throws SemaphoreException |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testVolumeFails1(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$lib = $this->getSemaphore(); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertFalse($lib->has()); |
|
46
|
|
|
$this->assertTrue($lib->want()); |
|
47
|
|
|
$this->assertTrue($lib->has()); |
|
48
|
|
|
chmod($lib->getPath(), 0444); |
|
49
|
|
|
$this->expectException(SemaphoreException::class); |
|
50
|
|
|
$lib->want(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @throws SemaphoreException |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testVolumeFails2(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$lib = $this->getSemaphore(); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertFalse($lib->has()); |
|
61
|
|
|
mkdir($lib->getPath()); |
|
62
|
|
|
$this->expectException(SemaphoreException::class); |
|
63
|
|
|
$lib->remove(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected function getSemaphore(): ISemaphore |
|
67
|
|
|
{ |
|
68
|
|
|
$path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'dummy'; |
|
69
|
|
|
return new Vol($path); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
class Vol extends Semaphore\Volume |
|
75
|
|
|
{ |
|
76
|
|
|
public function getPath(): string |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->rootPath; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|