Testing

    Laravel is built with testing in mind. In fact, support for testing with PHPUnit is included out of the box and a file is already setup for your application. The framework also ships with convenient helper methods that allow you to expressively test your applications.

    An ExampleTest.php file is provided in the tests directory. After installing a new Laravel application, simply run phpunit on the command line to run your tests.

    When running tests, Laravel will automatically set the configuration environment to testing. Laravel automatically configures the session and cache to the array driver while testing, meaning no session or cache data will be persisted while testing.

    You are free to define other testing environment configuration values as necessary. The testing environment variables may be configured in the phpunit.xml file, but make sure to clear your configuration cache using the config:clear Artisan command before running your tests!

    To create a new test case, use the make:test Artisan command:

    This command will place a new UserTest class within your directory. You may then define test methods as you normally would using PHPUnit. To run your tests, simply execute the phpunit command from your terminal:

    1. <?php
    2. use Illuminate\Foundation\Testing\WithoutMiddleware;
    3. use Illuminate\Foundation\Testing\DatabaseMigrations;
    4. use Illuminate\Foundation\Testing\DatabaseTransactions;
    5. class UserTest extends TestCase
    6. {
    7. /**
    8. *
    9. * @return void
    10. */
    11. public function testExample()
    12. {
    13. $this->assertTrue(true);
    14. }