Example code for my talks and workshops on unit testing.
Clone this repository, or download the ZIP file.
There is both PHP and JavaScript example code waiting for you at src/php/
and src/js/
, respectively.
The repository is set up for you to write PHP tests with PHPUnit, and JavaScript tests with Jest.
If you would rather use something else instead, feel free to adapt composer.json
and package.json
, respectively.
In order to run the PHP tests, you have to install the required PHP packages first.
Install with Composer:
$ composer install
By default, this will install PHPUnit as well as Mockery, Patchwork and Brain Monkey.
Then, execute PHPUnit, which will use the configuration provided in phpunit.xml.dist
:
$ ./vendor/bin/phpunit
In order to run the JavaScript tests, you have to install the required JavaScript packages first.
Install with Yarn:
$ yarn
By default, this will install Jest (inlcuding jest-each
), react-test-renderer
and Enzyme (including enzyme-adapter-react-16
), as well as the babel-preset-env
and babel-preset-react
packages.
Then, run the test
script, defined in package.json
:
$ yarn test
In case you want to use npm instead, do it like so:
$ npm i && npm run test
Copyright (c) 2018 Thorsten Frommen
This code is licensed under the MIT License.