Daniel Siepmann - Coding is Art

Blog Post

Video: PHPUnit Introduction

Published: , Updated:

Tested with TYPO3: 10 LTS, 9 LTS, 8 LTS

Topics: testing, tutorial, video

Introduction

This is my very first video. It will introduce you to the beginning of PHPUnit to create unit tests for PHP Code.

The video includes instructions on how to install dependencies via composer, as well as how to write and execute first tests.

Execution is done on command line, as this should be the same on all environments.

The video is intended for real beginners. You should have zero experience with testing. Yet you should know how to execute commands on command line and how to use composer to install dependencies. Also object orientated programming and PHP knowledge is expected.

As this video covers the very basics, there is nothing special to TYPO3 in the video. Even if an TYPO3 extension is used as an example.

The Video

Video v25: Introduction into PHPUnit testing

The Video is available on YouTube: https://www.youtube.com/watch?v=MZqb164tVYw.

This video explains the very first steps for beginners to get started.
This includes installing phpunit via composer.
A first test is created and executed.

That's it.

I've given talks about getting started quite often in recent years. Poorly they were all in German. Some of them are already on YouTube.

This video should be the beginning of a small series of multiple short videos. The series should introduce everyone with no prior knowledge about testing.

Even if I'm using a pure command line setup, you can adapt to your needs. Probably you already use composer on command line, as no UI is available yet. In case you use a different editor, which you probably do, you still can execute the commands on command line. There should be no difference.

Some editors and IDEs provide some integration for testing execution. In such cases I recommend to get familiar with your tooling and check whether the integration provides benefits to you.

I'll stick to the command line approach, as this should for work everyone using MacOS, Linux, and Windows WSL.

Versions

The following versions are used inside the video:

PHPUnit: 9.3.7
PHP: 7.3.21
Composer: 1.10.10
PCOV: 1.0.6

Commands for Copy & Paste

The following commands are used inside the video. In order to get used to them, it is always a good idea to type them. But maybe there is an issue you can't find, in such situations it might be a good thing to compare them.

  1. composer req --dev phpunit/phpunit
  2. ./vendor/bin/phpunit --version
  3. ./vendor/bin/phpunit Tests
  4. ./vendor/bin/phpunit Tests --color --testdox
  5. composer req --dev phpspec/prophecy-phpunit
  6. ./vendor/bin/phpunit Tests --color --testdox --coverage-html report --coverage-filter Classes

Further reading

You can find further information here: