Completed
Push — master ( 9e29b7...c3d8ab )
by Yaroslav
19:31
created

BackUpContext::tearDown()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
use Behat\Behat\Context\Context;
4
use Utils\DataBaseDumpManager;
5
6
class BackUpContext implements Context
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    /**
9
     * @var string|null
10
     */
11
    private static $dumpFile;
12
13
    /**
14
     * @var DataBaseDumpManager
15
     */
16
    private static $dataBaseDumpManager;
17
18
    /**
19
     * @param string $rootDir
20
     */
21
    public function __construct($rootDir)
22
    {
23
        self::$dataBaseDumpManager = new DataBaseDumpManager($rootDir);
24
25
        if (!self::$dumpFile) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::$dumpFile of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
26
            self::$dumpFile = self::$dataBaseDumpManager->dump();
27
        }
28
    }
29
30
    /**
31
     * @AfterSuite
32
     */
33
    public static function tearDown()
34
    {
35
        self::$dataBaseDumpManager->load(self::$dumpFile);
36
37
        if (self::$dumpFile !== null) {
38
            unlink(self::$dumpFile);
39
        }
40
    }
41
42
    /**
43
     * @BeforeScenario
44
     */
45
    public function beforeScenario()
46
    {
47
        self::$dataBaseDumpManager->load(self::$dumpFile);
48
    }
49
}
50