---
title: 'PHP Testing - 1 Setup with Composer - phpunit - php test tutorial'
source: 'https://youtube.com/watch?v=ko3tMiG-IB4'
video_id: 'ko3tMiG-IB4'
date: 2026-07-28
duration_sec: 217
---

# PHP Testing - 1 Setup with Composer - phpunit - php test tutorial

> Source: [PHP Testing - 1 Setup with Composer - phpunit - php test tutorial](https://youtube.com/watch?v=ko3tMiG-IB4)

## Summary

This video demonstrates how to set up PHPUnit testing with Composer for a simple date format conversion service. The tutorial covers project initialization, installing PHPUnit, writing a basic test, and running tests via both the command line and Composer scripts.

### Key Points

- **Project Setup** [0:00] — Initialize a Composer project with autoload mapping for the src directory.
- **Namespace Correction** [0:54] — Ensure the service namespace matches the autoload configuration in composer.json.
- **Install PHPUnit** [1:06] — Install phpunit/phpunit as a dev dependency using Composer.
- **Test Namespace and Class Creation** [1:17] — Create a test namespace and a test class extending PHPUnit\Framework\TestCase.
- **Writing a Failing Test** [2:08] — Write a test method that intentionally fails to verify PHPUnit is working.
- **Running Tests** [2:21] — Run the test using php vendor/bin/phpunit tests and confirm the failure message.
- **Composer Script Shortcut** [2:47] — Add a 'test' script in composer.json to simplify running tests with phpunit and --testdox flag.

### Conclusion

The video successfully demonstrates setting up PHPUnit with Composer, writing a basic test, and running it efficiently. Future videos will cover IDE integration.

## Transcript

Today I will walk you through writing Unittest,
to test a simple service that converts a
date format to a different format.
So let's start the setup by opening the terminal
and initializing a composer project,
I will put the quite flag and let's name our project
date service
and we add the autoload flag with a and we write the src.
This will allows us to import our service
using the PHP use keyword, and we wrote src
because our service is in the src directory.
This command will create a vendor directory
and the composer.json file that will contain
our dependencies and project configuration.
it wrote the name as we wrote in our command
and the autoload Date/Service is mapped to
the src directory, now let's navigate to our
Service to insure that it has the correct
namespace.
let's correct the namespace like it is defined
in the composer.json file.
Let's navigate back to our composer.json to
install phpunit that is used for the unit
testing, we can use the terminal composer
require phpunit/phpunit --dev because this
dependency is only required in development
environment.
successfully installed.
let's create a namespace for our test by copying
the entry and changing it to the Date/Test
and the directory should be the "src" a non
existente directory that we will create using
our IDE. and let us create a class into it
that is called FormatDateTest.
As a naming convention the test class should
have the method or the class name you would
like to test and test with uppercase T.
let's extend the PHPunit TestCase and let's
create the class.
First let me clean up the import.
and then I will write a test method, as a
naming convention test method should start
with lower case test and the name of our test.
The purpose of this video is to successfully
install phpunit and to insure that it works,
therefor lets purposly fail our test and write
a message: " a message from our test" now
let's open the terminal and run the test using
php vendor/bin/phpunit tests.
and as you see our test failed successfully,
I will expend the terminal to insure that
our message that we provided is here.
And there is our message.
very nice our test seams to be working, one
thing we can improve here and that is minimizing
our test command because it is long!.
we can do that in the composer.json using
the script key: "test" and let's assign it
to the value that will be executed when the
key "test" is called, for us now this is "php
vendor/bin/phpunit" then let's add our directory
"tests" and to better format the output of
the test in the console we add the --testdox.
And that's it, let's run now our new command
using the composer test.
our command seams to call the correct value
and finally our test failed successfully.
Ladies and Gentleman this was how to setup
composer and phpunit and test using the native
phpunit command and the composer test, next
we will setup the PHPStorm so that we can
run out test in the IDE, I hope you enjoyed
watching and see you next time
