Last active
July 10, 2020 01:42
-
-
Save agm1984/4f73c83f6c47cd1f1759d481edcd25a8 to your computer and use it in GitHub Desktop.
phpunit.xml for Laravel unit testing with database transactions. DB_CONNECTION and DB_DATABASE are omitted which implicitly instructs Laravel to use the database information in the currently-loaded .env file (note: we are testing against the current environment and the <php> section in this file overwrites specific env variables)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | |
bootstrap="vendor/autoload.php" | |
colors="true" | |
convertErrorsToExceptions="true" | |
convertNoticesToExceptions="true" | |
convertWarningsToExceptions="true" | |
processIsolation="false" | |
stopOnFailure="false"> | |
<testsuites> | |
<testsuite name="AppLayout"> | |
<directory suffix="Test.php">./tests/AppLayout</directory> | |
</testsuite> | |
<testsuite name="Auth"> | |
<directory suffix="Test.php">./tests/Auth</directory> | |
</testsuite> | |
<testsuite name="Unit"> | |
<directory suffix="Test.php">./tests/Unit</directory> | |
</testsuite> | |
<testsuite name="Feature"> | |
<directory suffix="Test.php">./tests/Feature</directory> | |
</testsuite> | |
</testsuites> | |
<listeners> | |
<listener class="\Mockery\Adapter\Phpunit\TestListener" | |
file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php"> | |
</listener> | |
</listeners> | |
<filter> | |
<whitelist processUncoveredFilesFromWhitelist="true"> | |
<directory suffix=".php">./app</directory> | |
</whitelist> | |
</filter> | |
<php> | |
<server name="APP_ENV" value="testing"/> | |
<server name="BCRYPT_ROUNDS" value="4"/> | |
<server name="CACHE_DRIVER" value="array"/> | |
<!-- <server name="DB_CONNECTION" value="sqlite"/> | |
<server name="DB_DATABASE" value=":memory:"/> --> | |
<server name="MAIL_MAILER" value="array"/> | |
<server name="QUEUE_CONNECTION" value="sync"/> | |
<server name="SESSION_DRIVER" value="array"/> | |
</php> | |
</phpunit> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If
DB_CONNECTION
andDB_DATABASE
are omitted, PHPUnit will respect the values from the currently-loaded.env
file.Then, in each test, you can use this pattern: