Ad

Laravel Testing Migrating Pollutes Assertions

- 1 answer

While writing tests for my Laravel package I came across something strange. My empty tests were passing instead of marked as "Risky".

Further investigation led me to the PendingCommand class that has a run() method which makes an assertion on the exit code of the command. This PendingCommand was instantiated by calling $this->astisan('migrate:fresh')->run(). I was able to skip this assertion by calling assertExitCode(null) before running the command. It worked but there is still an assertion happening.

Anybody had this problem before and/or was able to prevent assertions from happening before the actual test is executed?

It would be nice to see which assertions are being made, but I was unable to find this. The only thing I could find was that the Assert class keeps a $count of all the assertions done, not which one.

I will continue my search for a solution and post my findings to this question.

Ad

Answer

Found out that InteractsWithConsole has a withoutMockingConsoleOutput method that will prevent a mock to be created with assertions.

Final code:

$this->withoutMockingConsoleOutput()
    ->artisan('migrate:fresh');
Ad
source: stackoverflow.com
Ad