ExistWrongPidFileTest::testBiggerPid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * Created by PhpStorm.
5
 * User: danchukas
6
 * Date: 2017-07-15 00:56
7
 */
8
9
namespace DanchukAS\DenyMultiplyRunTest;
10
11
use DanchukAS\DenyMultiplyRun\DenyMultiplyRun;
12
use DanchukAS\DenyMultiplyRun\Exception\OpenFileFail;
13
use DanchukAS\DenyMultiplyRun\Exception\PidBiggerMax;
14
use DanchukAS\DenyMultiplyRun\PidFileTestCase;
15
16
/** @noinspection PhpClassNamingConventionInspection */
17
18
/**
19
 * Class ExistWrongPidFileTest
20
 * Тести на невірний під файл
21
 * @package DanchukAS\DenyMultiplyRunTest
22
 */
23
class ExistWrongPidFileTest extends PidFileTestCase
24
{
25
26
    public function testBiggerPid()
27
    {
28
        file_put_contents(self::$existFileName, PHP_INT_MAX);
29
30
        $this->expectException(PidBiggerMax::class);
31
        DenyMultiplyRun::setPidFile(self::$existFileName);
32
    }
33
34
    public function testNoAccessFile()
35
    {
36
        // existed file without write access for current user.
37
        // for Ubuntu is /etc/hosts.
38
        $file_name = '/etc/hosts';
39
40
        if (!file_exists($file_name)) {
41
            self::markTestSkipped('test only for *nix.');
42
        }
43
44
        if (is_writable($file_name)) {
45
            self::markTestSkipped('test runned under super/admin user. Change user.');
46
        }
47
48
        $this->expectException(OpenFileFail::class);
49
        DenyMultiplyRun::setPidFile($file_name);
50
    }
51
}
52