Uploaded August 2016 | Updated December 2026, 32 minutes ago
In this video I explain how you can use PHPUnit and Laravel to apply TDD concepts. This is the first half of this video which goes through the theory. The second part of this has the code demonstration.
Reval Govender
LinkedIn: uk.linkedin.com/in/reval-govender-0ba14860
Twitter: twitter.com/RevalGovender
My site: revgov.co.uk
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelB
PHP Developer Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0Fy93MCcC1Co0BuccJk6QqX
A Journey To TDD the tutorial series:
youtube.com/playlist?list=PLrIm-p2rpV0EWSkkE6Llxaw7sxnsxdVWB
1. Prerequisite - 00:25
2. Introduction - 00:52
3. The Example Test - 01:09
4. What level do we test - 01:46
5. Workflow of writing a test - 02:07
In this video I explain how you can use PHPUnit and Laravel to apply TDD concepts. This is the first half of this video which goes through the theory. The second part of this has the code demonstration.
Reval Govender
LinkedIn: uk.linkedin.com/in/reval-govender-0ba14860
Twitter: twitter.com/RevalGovender
My site: revgov.co.uk
Laravel Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelB
PHP Developer Tutorials:
youtube.com/playlist?list=PLrIm-p2rpV0Fy93MCcC1Co0BuccJk6QqX
A Journey To TDD the tutorial series:
youtube.com/playlist?list=PLrIm-p2rpV0EWSkkE6Llxaw7sxnsxdVWB
1. Prerequisite - 00:25
2. Introduction - 00:52
3. The Example Test - 01:09
4. What level do we test - 01:46
5. Workflow of writing a test - 02:07



![Part 18-Handle failure gracefully Create endpoint [How to use TDD to build a REST API in Laravel 6]
We have some endpoints, but they aren’t the best. They don’t fail gracefully. Let’s take the Create endpoint for example. What happens if we provide a blank value for a required attribute?
The code will fail and throw an error but we don’t handle that error.
So let’s write a test in our StoreCest test file. When we have an invalid parameter in our request, the server must respond with a 400 error. So let’s write a test for that.
A good name for this test can be, “itWillReturn400WhenMissingRequiredParameter()”.
Our test should fail, because we are not handling any errors in the controller. Let’s change that.
Open your controller and navigate to the store method. Let’s use Laravel’s manual validator to make the Title field required. We know without this field, we cannot save a record to the database.
So what we need to do next is wrap most of this method in a try/catch block. So if there are any failures, we can handle it. The Laravel validator, will let us know if the validation has failed. If it has failed, we need to throw an exception. We can declare the message and the http status code.
Our catch block, will then return a response using the same http status code as well as the message. Now our test should pass. Run your tests. Great it passes. Good work.
Watch the next video in this series here:
https://youtu.be/iIrrrUCAM1w
Watch this course in full here:
https://www.youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr
Laravel Tutorials:
https://www.youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
https://www.youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
https://www.youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr Part 18-Handle failure gracefully Create endpoint [How to use TDD to build a REST API in Laravel 6]](https://i.ytimg.com/vi/ugy6MEeeVWI/mqdefault.jpg)

![Part 27 - Install tymon/jwt-auth into Laravel 6 [How to use TDD to build a REST API in Laravel]
So we are now ready to start implementing JWT Authentication. We will be installing a package to help us with this. Please forgive me if I am pronounce this incorrectly. The package is called jwt-auth by Sean Tymon. The latest version of this package is required for Laravel 6. Let’s install it.
Open your terminal and type the following command:
composer require tymon/jwt-auth:1.0.0-rc.5
I am not sure how stable this package is as of recording this video, but it will be fine for the purposes of this project. So be aware when using it in production.
To complete the installation, we need to run the following artisan command which comes with the package.
php artisan vendor:publish provider=TymonJWTAuthProvidersLaravelServiceProvider
The command will have copied the configuration file. In this configuration file, we have access to various settings. For now, we are interested in the secret which will be used for signing our tokens. Notice it is referencing an env variable that does not exist.
We need to run the following
php artisan jwt:secret
This command will generate a key and add it to our env file. We now have the package installed. In the next video, we will use.
Laravel Tutorials:
https://www.youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
https://www.youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelBWatch this course in full here:
https://www.youtube.com/playlist?list=PLrIm-p2rpV0F-rl4NPjNslEmW-D83AHOr Part 27 - Install tymon/jwt-auth into Laravel 6 [How to use TDD to build a REST API in Laravel]](https://i.ytimg.com/vi/wO31xRxVMxk/mqdefault.jpg)
![Codeception Actors, Modules and Helpers - Tutorial [2/6]
In this video tutorial I introduce you to Codeception Actors, Modules and Helpers. The purpose of is to dive deeper into Codeception. In this series we will be using Codeception with Laravel.
Reval Govender
LinkedIn: https://uk.linkedin.com/in/reval-govender-0ba14860
Twitter: https://twitter.com/RevalGovender
My site: http://revgov.co.uk/
1. Prerequisite - 00:17
2. Introduction - 00:30
3. Actors - 01:58
4. Modules - 01:07
5. Adding Modules - 02:27
6. Helpers - 03:05
Laravel Tutorials:
https://www.youtube.com/playlist?list=PLrIm-p2rpV0FmbeNsYYh_4Fcb4Ibq29tJ
2 - 3 min Developer Quick Tips Series:
https://www.youtube.com/playlist?list=PLrIm-p2rpV0F6yyK99B9TU6yVhnPdzelB
PHP Developer Tutorials:
https://www.youtube.com/playlist?list=PLrIm-p2rpV0Fy93MCcC1Co0BuccJk6QqX
A Journey To TDD the tutorial series:
https://www.youtube.com/playlist?list=PLrIm-p2rpV0EWSkkE6Llxaw7sxnsxdVWB Codeception Actors, Modules and Helpers - Tutorial [2/6]](https://i.ytimg.com/vi/wXEQWPrBnyU/mqdefault.jpg)



