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
|
|
|
|