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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners