I have a laravel project which has some unit tests written in them.
When i run those tests with php vendor/bin/phpunit
the results look like this:
Now when i run the tests with php artisan test
the results look like this:
Is it possible to run the phpunit command with the styling of the artisan test command?
I like the extra information about the duration of my tests but I need to run the phpunit command for some extra logging etc.
EDIT:
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
<directory suffix="Test.php">./Modules/**/Tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
<directory suffix="Test.php">./Modules/**/Tests/Feature</directory>
</testsuite>
</testsuites>
<coverage/>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="TELESCOPE_ENABLED" value="false"/>
</php>
<source>
<include>
<directory suffix=".php">./app</directory>
</include>
</source>
</phpunit>
2
Answers
Edit: I had misunderstood your question. It is done by the Composer package nunomaduro/collision. Instead of using the
phpunit
command, using thephp artisan
command with additional parameters for PHPUnit will result in running PHPUnit with the desired logging and console output.It is implemented by the
TestCommand
class that is registered by theCollisionServiceProvider
class for a Laravel project. In the composer.json file of the project there is a extra.laravel.providers property that will register the class with a Laravel project. So it looks like it is for now only possible to use in a Laravel project.Parameters for PHPUnit can be added to the command. They will be send to PHPUnit. Some parameters are reserved for the artisan test command. They can be seen with the command:
So if you want to use for instance the –log-junit parameter it can be append to the command like:
You can’t make them look exactly the same without doing some hacky stuff.
Funnily enough, the command to run laravel’s tests is declared in another package (
nunomaduro/collision
‘s TestCommand). That package also has a dedicated phpunit adapter but I don’t really know how to use it.You could pass the
--testdox
option to phpunit. It’s not quite the same but it’s the closest you can get without any pain involved.There’s also the
--color
option that you can configure in your phpunit.xml file.Or just add it in the command.