Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Adds --test and --pest options to various make commands #38997

Merged
merged 24 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/Illuminate/Console/Concerns/CreatesMatchingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Illuminate\Console\Concerns;

use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputOption;

trait CreatesMatchingTest
{
/**
* Add the standard command options for generating matching tests.
*
* @return void
*/
protected function addTestOptions()
{
foreach (['test' => 'PhpUnit', 'pest' => 'Pest'] as $option => $name) {
lukeraymonddowning marked this conversation as resolved.
Show resolved Hide resolved
$this->getDefinition()->addOption(new InputOption(
$option,
null,
InputOption::VALUE_NONE,
"Generate an accompanying {$name} test for the {$this->type}"
));
}
}

/**
* Create the matching test case if requested.
*
* @param string $path
* @return void
*/
protected function handleTestCreation($path)
{
if (! $this->option('test') && ! $this->option('pest')) {
return;
}

$this->call('make:test', [
'name' => Str::of($path)->after($this->laravel['path'])->beforeLast('.php')->append('Test'),
lukeraymonddowning marked this conversation as resolved.
Show resolved Hide resolved
'--pest' => $this->option('pest'),
]);
}
}
9 changes: 9 additions & 0 deletions src/Illuminate/Console/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Console;

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -108,6 +109,10 @@ public function __construct(Filesystem $files)
{
parent::__construct();

if (in_array(CreatesMatchingTest::class, class_uses_recursive($this))) {
$this->addTestOptions();
}

$this->files = $files;
}

Expand Down Expand Up @@ -159,6 +164,10 @@ public function handle()
$this->files->put($path, $this->sortImports($this->buildClass($name)));

$this->info($this->type.' created successfully.');

if (in_array(CreatesMatchingTest::class, class_uses_recursive($this))) {
$this->handleTestCreation($path);
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Illuminate/Foundation/Console/ConsoleMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace Illuminate\Foundation\Console;

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

class ConsoleMakeCommand extends GeneratorCommand
{
use CreatesMatchingTest;

/**
* The console command name.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Illuminate/Foundation/Console/JobMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Illuminate\Foundation\Console;

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;

class JobMakeCommand extends GeneratorCommand
{
use CreatesMatchingTest;

/**
* The console command name.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Illuminate/Foundation/Console/ListenerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace Illuminate\Foundation\Console;

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Console\GeneratorCommand;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputOption;

class ListenerMakeCommand extends GeneratorCommand
{
use CreatesMatchingTest;

/**
* The console command name.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Illuminate/Foundation/Console/MailMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Illuminate\Foundation\Console;

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;

class MailMakeCommand extends GeneratorCommand
{
use CreatesMatchingTest;

/**
* The console command name.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Illuminate/Foundation/Console/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace Illuminate\Foundation\Console;

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Console\GeneratorCommand;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputOption;

class ModelMakeCommand extends GeneratorCommand
{
use CreatesMatchingTest;

/**
* The console command name.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Illuminate/Foundation/Console/NotificationMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Illuminate\Foundation\Console;

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;

class NotificationMakeCommand extends GeneratorCommand
{
use CreatesMatchingTest;

/**
* The console command name.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Illuminate/Routing/Console/ControllerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace Illuminate\Routing\Console;

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Console\GeneratorCommand;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputOption;

class ControllerMakeCommand extends GeneratorCommand
{
use CreatesMatchingTest;

/**
* The console command name.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Illuminate/Routing/Console/MiddlewareMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace Illuminate\Routing\Console;

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Console\GeneratorCommand;

class MiddlewareMakeCommand extends GeneratorCommand
{
use CreatesMatchingTest;

/**
* The console command name.
*
Expand Down