Passed
Push — add-command-list-modules ( fd1ae6 )
by Chema
11:55
created

MakeFileCommandTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Feature\Console\CodeGenerator;
6
7
use Gacela\Console\Infrastructure\ConsoleBootstrap;
8
use Gacela\Framework\Gacela;
9
use GacelaTest\Feature\Util\DirectoryUtil;
10
use PHPUnit\Framework\TestCase;
11
use Symfony\Component\Console\Input\StringInput;
12
use Symfony\Component\Console\Output\BufferedOutput;
13
14
final class MakeFileCommandTest extends TestCase
15
{
16
    public static function tearDownAfterClass(): void
17
    {
18
        DirectoryUtil::removeDir('./src/TestModule');
19
    }
20
21
    public function setUp(): void
22
    {
23
        Gacela::bootstrap(__DIR__);
24
        DirectoryUtil::removeDir('./src/TestModule');
25
    }
26
27
    /**
28
     * @dataProvider createFilesProvider
29
     */
30
    public function test_make_file(string $action, string $fileName, string $shortName): void
31
    {
32
        $input = new StringInput("make:file Psr4CodeGenerator/TestModule {$action} {$shortName}");
33
        $output = new BufferedOutput();
34
35
        $bootstrap = new ConsoleBootstrap();
36
        $bootstrap->setAutoExit(false);
37
        $bootstrap->run($input, $output);
38
39
        self::assertSame("> Path 'src/TestModule/{$fileName}.php' created successfully", trim($output->fetch()));
40
        self::assertFileExists("./src/TestModule/{$fileName}.php");
41
    }
42
43
    public function createFilesProvider(): iterable
44
    {
45
        yield 'facade' => ['facade', 'TestModuleFacade', ''];
46
        yield 'factory' => ['factory', 'TestModuleFactory', ''];
47
        yield 'config' => ['config', 'TestModuleConfig', ''];
48
        yield 'dependency provider' => ['dependency-provider', 'TestModuleDependencyProvider', ''];
49
50
        // Sort name flag
51
        yield 'facade -s' => ['facade', 'Facade', '-s'];
52
        yield 'factory -s' => ['factory', 'Factory', '-s'];
53
        yield 'config -s' => ['config', 'Config', '-s'];
54
        yield 'dependency provider -s' => ['dependency-provider', 'DependencyProvider', '-s'];
55
    }
56
}
57