Hi and welcome for another article 👋 This one will be a rapid-fire oriented post so that you can both see how easy it is to test your Laravel app, and you can refer to it whenever you want to remember how to test something. Everytime you want to create a test, and the test class do not exist yet, just run this command.

your-app/ ├── app/ │ ├── Http/ │ │ └── Controllers/ │ │ ├── LoginController.php │ │ └── PostController.php │ ├── Models/ │ │ ├── Post.php │ │ └── User.php │ ├── Rules/ │ │ └── BarCodeValid.php │ └── Helpers/ │ └── Color.php └── tests/ ├── Feature/ │ ├── Http/ │ │ └── Controllers/ │ │ ├── LoginControllerTest.php │ │ └── PostControllerTest.php │ ├── Models/ │ │ ├── PostTest.php │ │ └── UserTest.php │ └── Rules/ │ └── BarCodeValidTest.php └── Unit/ └── Helpers/ └── ColorTest.php #1-assert-a-route-returns-response-without-errors 1. Assert a route returns response without errors namespace Tests\Feature; use Illuminate\Foundation\Testing\WithFaker; use Tests\TestCase; class ContactUsControllerTest extends TestCase { use WithFaker; public function testContactUsPageRendersWell() { $this ->get(route("contact-us.index")) ->assertOk(); }} #1-assert-a-user-is-logged 1.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners