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

[5.6] Execute an Artisan command using either its name or class #23764

Merged
merged 3 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions src/Illuminate/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,17 @@ public static function forgetBootstrappers()
*/
public function call($command, array $parameters = [], $outputBuffer = null)
{
$parameters = collect($parameters)->prepend($command);
if (is_subclass_of($command, SymfonyCommand::class)) {
$command = $this->laravel->make($command)->getName();
}

array_unshift($parameters, $command);

$this->lastOutput = $outputBuffer ?: new BufferedOutput;

$this->setCatchExceptions(false);

$result = $this->run(new ArrayInput($parameters->toArray()), $this->lastOutput);
$result = $this->run(new ArrayInput($parameters), $this->lastOutput);

$this->setCatchExceptions(true);

Expand Down
53 changes: 53 additions & 0 deletions tests/Integration/Console/ConsoleApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Illuminate\Tests\Integration\Console;

use Illuminate\Console\Command;
use Orchestra\Testbench\TestCase;
use Illuminate\Contracts\Console\Kernel;

class ConsoleApplicationTest extends TestCase
{
protected function setUp()
{
parent::setUp();

$this->app[Kernel::class]->registerCommand(new FooCommandStub);
}

public function test_artisan_call_using_command_name()
{
$exitCode = $this->artisan('foo:bar', [
'id' => 1,
]);

$this->assertEquals($exitCode, 0);
}

public function test_artisan_call_using_command_class()
{
$exitCode = $this->artisan(FooCommandStub::class, [
'id' => 1,
]);

$this->assertEquals($exitCode, 0);
}

/**
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
*/
public function test_artisan_call_invalid_command_name()
{
$this->artisan('foo:bars');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KennedyTedesco this test freezes entirely on master branch. Can you fix it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taylorotwell We would need to look a bit more carefully, because wasn't caused by my implementation. Actually, looks like a problem of symfony. On the dependencies of the 5.6 branch when we execute a command that doesn't exist it throws a CommandNotFoundException, but on master branch it just gets stuck.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taylorotwell We can fix on our side by evaluating if the command really exists. What you think about it?

KennedyTedesco@bc20aaa

I can send a pull request if it's fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

}
}

class FooCommandStub extends Command
{
protected $signature = 'foo:bar {id}';

public function handle()
{
//
}
}