|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Created by PhpStorm. |
|
7
|
|
|
* User: danchukas |
|
8
|
|
|
* Date: 2017-06-22 18:10 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace DanchukAS\DenyMultiplyRunTest; |
|
12
|
|
|
|
|
13
|
|
|
use DanchukAS\DenyMultiplyRun\DenyMultiplyRun; |
|
14
|
|
|
use DanchukAS\DenyMultiplyRun\PidFileTestCase; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class SurprisingTest |
|
18
|
|
|
* поглиблені тести на "всі найбільш можливі ситуації" |
|
19
|
|
|
* @package DanchukAS\DenyMultiplyRunTest |
|
20
|
|
|
*/ |
|
21
|
|
|
class SurprisingTest extends PidFileTestCase |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @expectedException \DanchukAS\DenyMultiplyRun\Exception\ProcessExisted |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testDoubleCall() |
|
28
|
|
|
{ |
|
29
|
|
|
$file_name = self::$noExistFileName; |
|
30
|
|
|
DenyMultiplyRun::setPidFile($file_name); |
|
31
|
|
|
DenyMultiplyRun::setPidFile($file_name); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** @noinspection PhpMethodNamingConventionInspection */ |
|
35
|
|
|
/** |
|
36
|
|
|
* Delete if no exist pid file. |
|
37
|
|
|
* @dataProvider deletePidFileParam |
|
38
|
|
|
*/ |
|
39
|
|
|
public function testDeletePidFile($param, $message = null) |
|
40
|
|
|
{ |
|
41
|
|
|
if (!is_null($message)) { |
|
42
|
|
|
self::markTestSkipped($message); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$this->expectException("DanchukAS\DenyMultiplyRun\Exception\DeleteFileFail"); |
|
46
|
|
|
DenyMultiplyRun::deletePidFile($param); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @dataProvider notFileNameProvider |
|
51
|
|
|
* @param mixed $no_valid_file_name |
|
52
|
|
|
* @param string $throwable_type |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testWrongParam($no_valid_file_name, string $throwable_type) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->expectException($throwable_type); |
|
57
|
|
|
DenyMultiplyRun::setPidFile($no_valid_file_name); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** @noinspection PhpMethodNamingConventionInspection */ |
|
62
|
|
|
/** |
|
63
|
|
|
* @dataProvider notStringProvider |
|
64
|
|
|
* @param mixed $badResource from dataProvider |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testLockedFileBeforeClose($badResource) |
|
67
|
|
|
{ |
|
68
|
|
|
$method = new \ReflectionMethod("DanchukAS\DenyMultiplyRun\DenyMultiplyRun", "closePidFile"); |
|
69
|
|
|
|
|
70
|
|
|
$method->setAccessible(true); |
|
71
|
|
|
$this->expectException("DanchukAS\DenyMultiplyRun\Exception\CloseFileFail"); |
|
72
|
|
|
$method->invoke(null, $badResource); |
|
73
|
|
|
$method->setAccessible(false); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|