Calling PHPUnit from Artisan command will ignore the XML File

Posted 2 years ago by ludo237

Greetings everyone.

I have what I think is an uncommon issue but I'll try to explain as clear as I can. I have created a simple artisan command that does this

     * Execute the console command.
    public function handle()
        $this->info("==> Cleaning up reports and docs...");

        $command = new Process("rm -f tests/docs/* && rm -rf test/reports/*");

        $this->warn("==> Reports and docs are clean");

        $this->info("==> Executing Tests Suite...");
        $command = new Process("vendor/bin/phpunit --coverage-html tests/reports --testdox-html tests/docs/reports.html -v --debug");

        $this->warn("==> report generated >> test/reports. Documentation generated >> test/docs/reports.html");

This could seems kinda odd but it is actually pretty useful, it launch the PHPUnit with the coverage support and other stuff. The problem is that if I run this command like php artisan ludo237:full-test it will completely ignore the phpunit.xml in fact it will display and error saying that the MySQL database does not exists, even though I've set the sqlite connection inside my phpunit.xml speaking of which you can clearly see that is correct:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
        <testsuite name="Application Test Suite">
            <directory suffix="Test.php">./tests</directory>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        <env name="APP_ENV" value="testing"/>
        <env name="APP_DEBUG" value="true"/>
        <env name="APP_URL" value="http://localhost:8000"/>
        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:" />
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
        <env name="MAIL_DRIVER" value="log"/>
        <env name="MAIL_PRETEND" value="true"/>

I know that I can simply create a bash alias for that command line, in fact this is my current hot fix, but at this point I'm just curious to understand why when I launch the phpunit command from the artisan command it ignores the XML file.

Does anyone have a clue about this? Thank you!

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

Reply to

Use Markdown with GitHub-flavored code blocks.