We are using the PHPUnit test for this article. PHPUnit Test in Laravel. The phpunit.xml file is already configured for our Laravel application. By default Laravel ships with two directories and two files.

  1. Feature Directory
  2. Unit Directory
  3. CreatesApplication.php
  4. TestCase.php

PHPUnit Environment

When we are running the tests via PHPUnit then Laravel will set the environment to test automatically. It configures the cache and session environment to the array driver. So while testing, no session or cache data is persisted. You can actually see it in the below code. Go to the phpunit.xml file.

<php>
     <env name="APP_ENV" value="testing"/>
     <env name="CACHE_DRIVER" value="array"/>
     <env name="SESSION_DRIVER" value="array"/>
     <env name="QUEUE_DRIVER" value="sync"/>
</php>

Laravel Testing: Creating and Running Tests

The first step would be to install a brand new Laravel Project.

#laravel #laravel application #phpunit.xml #phpunit

Laravel Testing: How to Test Laravel Application
3.25 GEEK