Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
I want an acceptance test for an Artisan command that generates some files with boilerplate. However, this command is part of a Composer package. I'm trying to figure out the best way to actually call Artisan from the package. Right now, I'm just assuming the framework and doing ../../../artisan. Is there an alternative/better way that you'd sug…
$saveDir = './tests/acceptance/tmp';
$stubDir = './tests/acceptance/stubs';
$commandToGenerate = 'FooCommand';
$I = new AcceptanceTester($scenario);
$I->wantTo('generate a command and handler class');
// Is there a better way to call the Artisan command? Without having to expect the framework and do ../../../?
$I->runShellCommand("php ../../../artisan commander:generate $commandToGenerate --properties='bar, baz' --base='$saveDir'");
$I->seeInShellOutput('All done!');
// My Command stub should match the generated class.
// And my CommandHandler stub should match its generated counterpart, as well.

This comment has been minimized.

Copy link

hoopyfrood commented Jul 31, 2014

It won't be long: laravel/laravel#2218. I'd wait, if you can't, I'm afraid the ../../../ is the best way. Good luck!


This comment has been minimized.

Copy link

DavertMik commented Aug 1, 2014

I'd create a runArtisanCommand method in AcceptanceHelper to execute artisan commands.
To match root directory you can use codecept_root_dir function

      enabled: ArtisanHelper
class ArtisanHelper extends \Codeception\Module
     function runArtisanCommand($command)
          $this->getModule('Cli')->runShellCommand("php artisan $command");     

If codecept_root_dir is not what you need you can use ../../../ inside of runArtisanCommand
Abyway that would be less ugly than using ../../ inside of tests


This comment has been minimized.

Copy link

umang-ranium commented Aug 6, 2015

@DavertMik codeception already has a function callArtisan how to check out put of it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.