Passed
Pull Request — master (#69)
by Jesús
02:44
created

MakeFileCommandTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 1
b 0
f 0
dl 0
loc 38
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_make_file() 0 7 1
A createFilesProvider() 0 12 1
A setUp() 0 3 1
A tearDownAfterClass() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Feature\CodeGenerator;
6
7
use GacelaTest\Feature\Util\DirectoryUtil;
8
use PHPUnit\Framework\TestCase;
9
10
final class MakeFileCommandTest extends TestCase
11
{
12
    private const ENTRY_POINT = __DIR__ . '/../../../';
13
14
    public function setUp(): void
15
    {
16
        DirectoryUtil::removeDir(self::ENTRY_POINT . 'src/TestModule');
17
    }
18
19
    public static function tearDownAfterClass(): void
20
    {
21
        DirectoryUtil::removeDir(self::ENTRY_POINT . 'src/TestModule');
22
    }
23
24
    /**
25
     * @dataProvider createFilesProvider
26
     */
27
    public function test_make_file(string $action, string $fileName, string $shortName): void
28
    {
29
        $command = sprintf('%sgacela make:file %s Gacela/TestModule %s', self::ENTRY_POINT, $shortName, $action);
30
        exec($command, $output);
31
32
        self::assertSame("> Path 'src/TestModule/{$fileName}.php' created successfully", $output[0]);
33
        self::assertFileExists(self::ENTRY_POINT . "src/TestModule/{$fileName}.php");
34
    }
35
36
    public function createFilesProvider(): iterable
37
    {
38
        yield 'facade' => ['facade', 'TestModuleFacade', ''];
39
        yield 'factory' => ['factory', 'TestModuleFactory', ''];
40
        yield 'config' => ['config', 'TestModuleConfig', ''];
41
        yield 'dependency provider' => ['dependency-provider', 'TestModuleDependencyProvider', ''];
42
43
        // Sort name flag
44
        yield 'facade -s' => ['facade', 'Facade', '-s'];
45
        yield 'factory -s' => ['factory', 'Factory', '-s'];
46
        yield 'config -s' => ['config', 'Config', '-s'];
47
        yield 'dependency provider -s' => ['dependency-provider', 'DependencyProvider', '-s'];
48
    }
49
}
50