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.7] Call Pending artisan command immediately #25574

Merged
merged 3 commits into from
Sep 11, 2018
Merged

[5.7] Call Pending artisan command immediately #25574

merged 3 commits into from
Sep 11, 2018

Conversation

antonkomarev
Copy link
Contributor

@antonkomarev antonkomarev commented Sep 11, 2018

Related to: orchestral/testbench#229

This is alternative solution for PR #25573

Sometimes there is requirement to check what has happened in application after the artisan command call. When we don't care about output, but about exact job results. We are not able to do the checks since Laravel 5.7 artisan command executing in __destruct method.

With this change we can call pending artisan command immediately.

$exitCode = $this->artisan('foo:bar')->callNow();

Before:

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

    // We have no way to call artisan with mocking for this test anymore
}

After:

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

    $this->artisan('baz:bar', [
        'id' => 1,
    ])->assertExitCode(0);
}

Inspired from notifications sendNow() and dispatcher dispatchNow() methods.

@antonkomarev
Copy link
Contributor Author

antonkomarev commented Sep 11, 2018

Hmmm... it will call command 2 times in this way. First time on callNow method and second time on __destruct method 😢

Edit: Fixed.

@taylorotwell
Copy link
Member

Renamed the method to run.

@taylorotwell taylorotwell merged commit 2a72a44 into laravel:5.7 Sep 11, 2018
@antonkomarev antonkomarev deleted the feature/artisan-pending-command-call-now branch September 11, 2018 13:34
@antonkomarev
Copy link
Contributor Author

antonkomarev commented Sep 11, 2018

Its fine. The only one question I've got: why do we need method names duplication?

public function execute()
{
return $this->run();
}

Leaving just execute() or run() will be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants