2 years ago
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.