Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Sep 11, 2023
1 parent afb9592 commit 13ac05e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Commands/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
abstract class Generator extends Command implements GeneratesCodeListener, PromptsForMissingInput
{
use CodeGenerator;
use CodeGenerator, TestGenerator;

/**
* The filesystem instance.
Expand Down Expand Up @@ -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);
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/TestGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Orchestra\Canvas\Core;

trait TestGenerator
{
/**
* Create the matching test case if requested.
*
* @param string $path
* @return bool
*/
protected function handleTestCreationUsingCanvas($path)
{
if (! $this->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;
}
}

0 comments on commit 13ac05e

Please sign in to comment.