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\Bootstrap\GacelaConfig; |
9
|
|
|
use Gacela\Framework\Gacela; |
10
|
|
|
use GacelaTest\Feature\Util\DirectoryUtil; |
11
|
|
|
use PHPUnit\Framework\Attributes\DataProvider; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Symfony\Component\Console\Input\StringInput; |
14
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
15
|
|
|
|
16
|
|
|
use function sprintf; |
17
|
|
|
|
18
|
|
|
final class MakeFileCommandTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
private const CACHE_DIR = '.' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'TestModule'; |
21
|
|
|
|
22
|
|
|
public static function tearDownAfterClass(): void |
23
|
|
|
{ |
24
|
|
|
DirectoryUtil::removeDir(self::CACHE_DIR); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function setUp(): void |
28
|
|
|
{ |
29
|
|
|
Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void { |
30
|
|
|
$config->resetInMemoryCache(); |
31
|
|
|
}); |
32
|
|
|
DirectoryUtil::removeDir(self::CACHE_DIR); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
#[DataProvider('createFilesProvider')] |
36
|
|
|
public function test_make_file(string $action, string $fileName, bool $shortName): void |
37
|
|
|
{ |
38
|
|
|
$shortNameFlag = $shortName ? '--short-name' : ''; |
39
|
|
|
$input = new StringInput(sprintf('make:file Psr4CodeGenerator/TestModule %s %s', $action, $shortNameFlag)); |
40
|
|
|
$output = new BufferedOutput(); |
41
|
|
|
|
42
|
|
|
$bootstrap = new ConsoleBootstrap(); |
43
|
|
|
$bootstrap->setAutoExit(false); |
44
|
|
|
$bootstrap->run($input, $output); |
45
|
|
|
|
46
|
|
|
self::assertSame(sprintf("> Path 'src/TestModule/%s.php' created successfully", $fileName), trim($output->fetch())); |
47
|
|
|
self::assertFileExists(sprintf('./src/TestModule/%s.php', $fileName)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public static function createFilesProvider(): iterable |
51
|
|
|
{ |
52
|
|
|
yield 'facade' => ['facade', 'TestModuleFacade', false]; |
53
|
|
|
yield 'factory' => ['factory', 'TestModuleFactory', false]; |
54
|
|
|
yield 'config' => ['config', 'TestModuleConfig', false]; |
55
|
|
|
yield 'dependency provider' => ['dependency-provider', 'TestModuleProvider', false]; |
56
|
|
|
|
57
|
|
|
// Short name flag |
58
|
|
|
yield 'facade -s' => ['facade', 'Facade', true]; |
59
|
|
|
yield 'factory -s' => ['factory', 'Factory', true]; |
60
|
|
|
yield 'config -s' => ['config', 'Config', true]; |
61
|
|
|
yield 'dependency provider -s' => ['dependency-provider', 'Provider', true]; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|