Skip to content

Instantly share code, notes, and snippets.

@rajeshtva
Last active January 23, 2022 04:06
Show Gist options
  • Save rajeshtva/53586bfb56ededb28f9a84e5c4ba388c to your computer and use it in GitHub Desktop.
Save rajeshtva/53586bfb56ededb28f9a84e5c4ba388c to your computer and use it in GitHub Desktop.
# use mysql in testing environment in laravel 8 +

use mysql as your testing environment in laravel

  • just create a testdb database
  • then in the phpunit.xml file, put these lines and configure as you want. This config works with default laravel configurations.
<?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"
>
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">./app</directory>
        </include>
    </coverage>
    <php>
        <server name="APP_ENV" value="testing"/>
        <server name="BCRYPT_ROUNDS" value="4"/>
        <server name="CACHE_DRIVER" value="array"/>
        <server name="DB_CONNECTION" value="mysql"/>
        <server name="DB_HOST" value="localhost" />
        <server name="DB_PORT" value="3306" />
        <server name="DB_USERNAME" value="root" />
        <server name="DB_PASSWORD" value="root" />
        <server name="DB_DATABASE" value="testdb"/>
        <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>
</phpunit>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment