SurprisingTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 55
rs 10
c 0
b 0
f 0

4 Methods

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