Passed
Push — master ( 321221...bff5d9 )
by Dmitry
03:28 queued 12s
created

ConsoleHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 54
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setDefaultConfig() 0 4 1
A getCli() 0 3 1
A runSprykerCommand() 0 4 1
A _after() 0 6 2
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace PyzTest\Zed\Console\Helper;
9
10
use Codeception\Module;
11
use Codeception\TestInterface;
12
use Codeception\Util\FileSystem;
13
use SprykerTest\Shared\Testify\Helper\ModuleHelperConfigTrait;
14
15
class ConsoleHelper extends Module
16
{
17
    use ModuleHelperConfigTrait;
18
19
    /**
20
     * @var string
21
     */
22
    public const RUNNER = 'console_runner.php';
23
    /**
24
     * @var string
25
     */
26
    public const SANDBOX_DIR = 'cli_sandbox/';
27
28
    /**
29
     * @param \Codeception\TestInterface $test
30
     *
31
     * @return void
32
     */
33
    public function _after(TestInterface $test)
34
    {
35
        foreach ($this->config['cleanup_dirs'] as $dir) {
36
            $dir = codecept_data_dir() . self::SANDBOX_DIR . $dir;
0 ignored issues
show
Bug introduced by
The function codecept_data_dir was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

36
            $dir = /** @scrutinizer ignore-call */ codecept_data_dir() . self::SANDBOX_DIR . $dir;
Loading history...
37
            $this->debugSection('Cleanup', $dir);
38
            FileSystem::deleteDir($dir);
39
        }
40
    }
41
42
    /**
43
     * @param string $command
44
     *
45
     * @return void
46
     */
47
    public function runSprykerCommand($command)
48
    {
49
        $command = 'php ' . codecept_data_dir() . self::RUNNER . " $command";
0 ignored issues
show
Bug introduced by
The function codecept_data_dir was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

49
        $command = 'php ' . /** @scrutinizer ignore-call */ codecept_data_dir() . self::RUNNER . " $command";
Loading history...
50
        $this->getCli()->runShellCommand($command);
51
    }
52
53
    /**
54
     * @return void
55
     */
56
    protected function setDefaultConfig(): void
57
    {
58
        $this->config = [
0 ignored issues
show
Bug Best Practice introduced by
The property config does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
59
            'cleanup_dirs' => ['data', 'src'],
60
        ];
61
    }
62
63
    /**
64
     * @return \Codeception\Module\Cli|\Codeception\Module
65
     */
66
    protected function getCli()
67
    {
68
        return $this->getModule('Cli');
69
    }
70
}
71