---
title: 'Video aTS7nA_0YOg'
source: 'https://youtube.com/watch?v=aTS7nA_0YOg'
video_id: 'aTS7nA_0YOg'
date: 2026-06-14
duration_sec: 0
---

# Video aTS7nA_0YOg

> Source: [Video aTS7nA_0YOg](https://youtube.com/watch?v=aTS7nA_0YOg)

## Summary

This tutorial demonstrates how to create and run a unit test in Laravel using PHPUnit. It covers checking for PHPUnit installation, creating a test file with Artisan, writing a test for a Customer model's full name method, and running the test.

### Key Points

- **Introduction** [00:00] — Welcome to a Laravel unit test tutorial using PHPUnit.
- **Check PHPUnit Installation** [00:10] — Open composer.json to verify phpunit/phpunit is listed.
- **Model Method to Test** [00:22] — Customer model has a fullName() method that concatenates first and last name.
- **Create Test File** [00:44] — Run 'php artisan make:test CustomerTest --unit' to generate the test file.
- **Test File Structure** [01:35] — CustomerTest extends TestCase from PHPUnit; write test method with docblock description.
- **Write the Test** [02:16] — Instantiate Customer model directly (no factory), set first and last name, then use assertEquals to check fullName() returns 'John Smith'.
- **Run Tests** [03:24] — Use 'php artisan test' to run all tests or 'php artisan test --filter=CustomerTest' for a specific test.

### Conclusion

Unit testing in Laravel is straightforward with PHPUnit. By creating a test file, writing assertions, and running tests via Artisan, you can ensure your model methods work correctly.

## Transcript

welcome to another develop and design
tutorial in this video we will explore
how to create a unit test in laravel
using PHP unit first we need to check
that we have the PHP unit package
installed by opening up the Project's
composer. Json file the package name we
should see is phpunit phpunit now we
know this is installed I am going to
open up the customer model class to
write a function for our unit test this
is just a simple function called full
name which returns a string
concatenating the customer's first name
and last name to create our unit test we
need to open our terminal or command
prompt then navigate to our laravel
project directory Now to create the
customer unit test file itself we need
to type the command PHP artisan make
colon test customer test-- unit then hit
enter now the command has run
successfully we should now see the file
path to our unit test displayed in the
terminal just a quick breakdown of the
command itself PHP artisan make colon
test creates the test file customer test
in Pascal case names the test file for
the customer class's unit tests only the
customer class's unit tests will go in
this file-- unit specifies that the
tests are unit tests and will place the
file under the unit test directory now
if we navigate to the test directory in
our code editor then into the unit
directory we should see our customer
test file let's click on it to open it
we can tell the test is a PHP unit test
as the customer test class extends the
test case class from the PHP unit
library now to write the test we'll
first add a description in the doc block
above the test function explaining what
it
covers let's put Test the full name
method of the customer model Returns the
correct
format it's good to put clear
descriptions as it helps other
developers understand the tests now
let's give the test function a name
let's call it Test full name Returns the
correct
format now let's delete everything that
was pre-generated inside the example
function then begin writing the test by
creating a variable called customer
which will be an instance of the
customer model
class we need to give the customer a
first name and last name to test the
function I'll assign the first name John
and the last name Smith to the customer
for unit tests we do not use model
Factory calls instead we instantiate the
class using the new
operator now let's add a call to a
method called assert
equals this method takes two variables
and asserts whether they are equal or
not if they are equal then the unit test
has passed if they are not equal then it
has failed
for this method's first parameter we
want to put the string value we expect
the customer full name method to return
which is John
Smith the second parameter we want to
pass is the full name method call from
our customer variable as this should
concatenate the customer's first name
and last name to equal John
Smith now to run the test we want to
open up the terminal and ensure we are
in our laravel project
directory then type the command PHP
Artisan test and hit enter Then in the
terminal we can see that our unit test
has passed successfully the command we
just ran on its own runs all the
tests if we have lots of tests it could
take a while to run them all if we just
want to see the outcome of one test file
then we can run the command with a
filter let's try the filter command in
the
terminal type PHP Artisan test-- filter
equals customer test
where customer test is the name of the
test then hit enter to run it and there
we have the customer test which has run
successfully if you have any questions
about this then please leave a comment
below and I will get back to you as soon
as I
can if you found this video useful then
please give it a like and hit the
Subscribe button
