Passed
Push — master ( 8f2c7f...261aac )
by Anatoliy
01:58
created

UseTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: danchukas
6
 * Date: 2017-06-22 18:10
7
 */
8
9
namespace DanchukAS\DenyMultiplyRunTest;
10
11
use DanchukAS\DenyMultiplyRun\DenyMultiplyRun;
12
use PHPUnit\Framework\TestCase;
13
14
/**
15
 * Class UseTest
16
 * test base usage DenyMultiplyRun
17
 *
18
 * @package DanchukAS\DenyMultiplyRunTest
19
 */
20
class UseTest extends TestCase
21
{
22
23
    private static $randomFileName;
24
25
    function setUp()
0 ignored issues
show
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for setUp.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
26
    {
27
        self::$randomFileName = sys_get_temp_dir() . '/' . uniqid('vd_', true);
28
    }
29
30
    function tearDown()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for tearDown.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
31
    {
32
        /** @noinspection PhpUsageOfSilenceOperatorInspection */
33
        @unlink(self::$randomFileName);
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

33
        /** @scrutinizer ignore-unhandled */ @unlink(self::$randomFileName);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
34
    }
35
36
37
    function testUsualUse()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for testUsualUse.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
38
    {
39
        $file_name = self::$randomFileName;
40
41
        $count_try = 2;
42
        while (--$count_try) {
43
            DenyMultiplyRun::setPidFile($file_name);
44
            self::assertStringEqualsFile($file_name, getmypid());
45
46
            DenyMultiplyRun::deletePidFile($file_name);
47
            self::assertFileNotExists($file_name);
48
        }
49
    }
50
51
52
}
53