In this recipe, if we already have the PHPUnit installed and working, we can write a test case and use PHPUnit to check if it is valid or not.
To run a test case, we'll need a working installation of Laravel. We'll also need to have installed PHPUnit from the previous recipe, Setting up and configuring PHPUnit.
To complete this recipe, follow the given steps:
In the
app/tests
directory, create a file namedMyAppTest.php
with the following code:<?php class MyAppTest extends TestCase { /** * Testing the MyApp route * * @return void */ public function testMyAppRoute() { $response = $this->call('GET', 'myapp'); $this->assertResponseOk(); $this->assertEquals('This is my app', $response >getContent()); } }
Run the tests in the command line window, and we should get failing tests on entering the following command:
vendor/bin/phpunit
In our
routes.php
file, add a new route with the following code:...