AndrewMcLagan
AndrewMcLagan

Reputation: 13987

Laravel: Disable Artisan console output when running tests

When running PHPUnit tests that are testing an Artisan command PHPUnit outputs any console ->info() or ->writeln() function calls.

Tests to not fail due to this although its ugly.

Example:

enter image description here

see the progress bar? How can we disable output during testing?

Upvotes: 2

Views: 4499

Answers (1)

Kyslik
Kyslik

Reputation: 8385

Some options come in mind all operate with verbosity of the command:

  • use --quiet|-q flag within call()
  • use callSilent() instead of call() (from test itself)
  • resolve command out of container and set verbosity to quiet before using it: $cmd = resolve(Command::class); $cmd->setVerbosity('quiet'); $cmd->doWork();
  • make dummy command that extends your tested one and set verbosity to quiet $this->setVerbosity('quiet'); and obviously resolve/new up the dummy command instead

Example of the latest (yes in one file):

class TestCommand extends TestCase {

    ...

}

class DummyCommand extends RealCommand {

    function __constructor() {
        parent::__construct();
        $this->setVerbosity('quiet');
    }

}

Upvotes: 4

Related Questions