Skip to content

Commit

Permalink
Merge branch '7.x' into 8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Sep 11, 2023
2 parents 3e36b5b + 13ac05e commit 3ea21d0
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 @@ -19,7 +19,7 @@
*/
abstract class Generator extends Command implements GeneratesCodeListener, PromptsForMissingInput
{
use CodeGenerator;
use CodeGenerator, TestGenerator;

/**
* The filesystem instance.
Expand Down Expand Up @@ -202,7 +202,7 @@ public function afterCodeHasBeenGenerated(string $className, string $path): void
{
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 3ea21d0

Please sign in to comment.