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\Attributes\DataProvider; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Symfony\Component\Console\Input\StringInput; |
13
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
14
|
|
|
|
15
|
|
|
use function sprintf; |
16
|
|
|
|
17
|
|
|
final class MakeModuleCommandTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
private const CACHE_DIR = '.' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'TestModule'; |
20
|
|
|
|
21
|
|
|
public static function tearDownAfterClass(): void |
22
|
|
|
{ |
23
|
|
|
DirectoryUtil::removeDir(self::CACHE_DIR); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
protected function setUp(): void |
27
|
|
|
{ |
28
|
|
|
Gacela::bootstrap(__DIR__); |
29
|
|
|
DirectoryUtil::removeDir(self::CACHE_DIR); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
#[DataProvider('createModulesProvider')] |
33
|
|
|
public function test_make_module(string $fileName, string $shortName): void |
34
|
|
|
{ |
35
|
|
|
$input = new StringInput('make:module Psr4CodeGeneratorData/TestModule ' . $shortName); |
36
|
|
|
$output = new BufferedOutput(); |
37
|
|
|
|
38
|
|
|
$bootstrap = new ConsoleBootstrap(); |
39
|
|
|
$bootstrap->setAutoExit(false); |
40
|
|
|
$bootstrap->run($input, $output); |
41
|
|
|
|
42
|
|
|
$expectedOutput = <<<OUT |
43
|
|
|
> Path 'data/TestModule/{$fileName}Facade.php' created successfully |
44
|
|
|
> Path 'data/TestModule/{$fileName}Factory.php' created successfully |
45
|
|
|
> Path 'data/TestModule/{$fileName}Config.php' created successfully |
46
|
|
|
> Path 'data/TestModule/{$fileName}Provider.php' created successfully |
47
|
|
|
Module 'TestModule' created successfully |
48
|
|
|
OUT; |
49
|
|
|
|
50
|
|
|
if (strcasecmp(substr(PHP_OS, 0, 3), 'WIN') == 0) { |
51
|
|
|
$expectedOutput = str_replace("\n", PHP_EOL, $expectedOutput); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
self::assertSame($expectedOutput, trim($output->fetch())); |
55
|
|
|
|
56
|
|
|
self::assertFileExists(sprintf('./data/TestModule/%sFacade.php', $fileName)); |
57
|
|
|
self::assertFileExists(sprintf('./data/TestModule/%sFactory.php', $fileName)); |
58
|
|
|
self::assertFileExists(sprintf('./data/TestModule/%sConfig.php', $fileName)); |
59
|
|
|
self::assertFileExists(sprintf('./data/TestModule/%sProvider.php', $fileName)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public static function createModulesProvider(): iterable |
63
|
|
|
{ |
64
|
|
|
yield 'module' => ['TestModule', '']; |
65
|
|
|
yield 'module -s' => ['', '-s']; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|