From 13ac05e610d5e4810a944b41736467af55256273 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 11 Sep 2023 21:03:33 +0800 Subject: [PATCH] wip Signed-off-by: Mior Muhammad Zaki --- src/Commands/Generator.php | 4 ++-- src/TestGenerator.php | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/TestGenerator.php diff --git a/src/Commands/Generator.php b/src/Commands/Generator.php index 44b3b17..d335fd7 100644 --- a/src/Commands/Generator.php +++ b/src/Commands/Generator.php @@ -18,7 +18,7 @@ */ abstract class Generator extends Command implements GeneratesCodeListener, PromptsForMissingInput { - use CodeGenerator; + use CodeGenerator, TestGenerator; /** * The filesystem instance. @@ -203,7 +203,7 @@ public function afterCodeHasBeenGenerated(string $className, string $path) { if (\in_array(CreatesMatchingTest::class, class_uses_recursive($this))) { /** @phpstan-ignore-next-line */ - $this->handleTestCreation($path); + $this->handleTestCreationUsingCanvas($path); } } diff --git a/src/TestGenerator.php b/src/TestGenerator.php new file mode 100644 index 0000000..6b7184e --- /dev/null +++ b/src/TestGenerator.php @@ -0,0 +1,24 @@ +option('test') && ! $this->option('pest')) { + return false; + } + + return $this->callSilent('make:test', [ + 'name' => Str::of($path)->after($this->preset->sourcePath())->beforeLast('.php')->append('Test')->replace('\\', '/'), + '--pest' => $this->option('pest'), + ]) == 0; + } +}