Completed
Pull Request — master (#2)
by Саша
36:16 queued 06:11
created

HookContext::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
use Behat\Behat\Context\Context;
4
5
class HookContext extends BaseContext implements Context
6
{
7
    /**
8
     * @BeforeScenario
9
     */
10
    public function initialize()
11
    {
12
        self::$workingDirectory = sys_get_temp_dir().DIRECTORY_SEPARATOR.'etl'.DIRECTORY_SEPARATOR;
13
    }
14
15
    /**
16
     * @AfterScenario
17
     */
18
    public function cleanup()
19
    {
20
        $this->clearDirectory(self::$workingDirectory);
21
    }
22
23
    private function clearDirectory($path)
24
    {
25
        $files = scandir($path);
26
        array_shift($files);
27
        array_shift($files);
28
29
        foreach ($files as $file) {
30
            $file = $path.DIRECTORY_SEPARATOR.$file;
31
            if (is_dir($file)) {
32
                $this->clearDirectory($file);
33
            } else {
34
                unlink($file);
35
            }
36
        }
37
38
        rmdir($path);
39
    }
40
}
41