Video: PHPUnit Introduction
Published: , Updated:
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
Size: 44.41 MB
YouTube: 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.
composer req --dev phpunit/phpunit
./vendor/bin/phpunit --version
./vendor/bin/phpunit Tests
./vendor/bin/phpunit Tests --color --testdox
composer req --dev phpspec/prophecy-phpunit
./vendor/bin/phpunit Tests --color --testdox --coverage-html report --coverage-filter Classes
Further reading ¶
You can find further information here:
- Official page of composer https://getcomposer.org/. Provides documentation on how to install and use composer.
- PHPUnit on packagist https://packagist.org/packages/phpunit/phpunit. Provides information about available versions and dependencies.
- Official page of PHPunit https://phpunit.de/. Provided documentation about all aspects of the library.
- https://xdebug.org/ PHP CodeCoverage, debugging and profiling module.
- https://github.com/krakjoe/pcov PHP CodeCoverage module.