From the course: Building a Website with Laravel, React.js, and Inertia
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Challenge: Testing API Endpoints with PHPUnit - Laravel Tutorial
From the course: Building a Website with Laravel, React.js, and Inertia
Challenge: Testing API Endpoints with PHPUnit
(futuristic music) - [Instructor] We have been using Postman to test our endpoints, but the easier and more automated way to test our code is by using testing framework. For this challenge, I'm going to ask you to write some basic tests to cover our existing functionality. You could use PHP unit or Pest, whichever you prefer. I would suggest to test the basic functionality of the post controller. No need to go very complex. I would test if the index method is display of posts, if the user can create a new post, if they can update it and delete it. You can also test that the title is required. To help you get started, let's set up the testing environment together. I'll use SQLite. So in the phpunit.xml file, I will anchor augment these two lines. I'll also create SQL database, so in the terminal I'm going to run touch database forward slash sq light database. We are ready to create our test by running PHP Artisan Make test, post control test in the terminal. And now the that's done…
Contents
-
-
-
(Locked)
Getting started: Creating a new Laravel project1m 59s
-
(Locked)
Creating a Post resource1m 51s
-
Creating a seeder and a factory1m 15s
-
(Locked)
Creating Post API resource1m 27s
-
(Locked)
Creating PostController index and store methods4m 25s
-
(Locked)
Creating PostController show, update, and destroy methods2m 14s
-
(Locked)
Challenge: Testing API Endpoints with PHPUnit1m 55s
-
(Locked)
Solution: Testing API Endpoints with PHPUnit3m 57s
-
(Locked)
-
-
-