automica
4 weeks ago
154
3
Testing

Testing Artisan Commands when developing vendor packages

Posted 4 weeks ago by automica

I am working on adding some tests to a vendor package that provides 6 artisan commands.

I'm working with it in a repo separate to my Laravel 8 installation and have updated composer so it knows to use the local development version, and this is working.

What I'm looking to do is to run the command via artisan and test some assertions.

eg

$this->artisan('commandName:subcommand')
->expectsOutput('some output')

when I run the commands test, I get the following:

Error: Call to undefined method Tests\Unit\ListCommandTest::artisan()

I've found https://laracasts.com/discuss/channels/laravel/test-laravel-console-command-from-package?#reply=459443 which is similar'ish to my issue.

Has anyone any advice on best way to proceed here, and what I would need to do to call artisan?

Please sign in or create an account to participate in this conversation.