Example code for my talks and workshops on unit testing.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.babelrc
.gitignore
LICENSE
README.md
composer.json
jest.config.js
package.json
phpunit.xml.dist
yarn.lock

README.md

Unit Test Examples

Example code for my talks and workshops on unit testing.

Getting Started

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.

Writing Tests

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.

PHP Tests

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

JavaScript Tests

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

License

Copyright (c) 2018 Thorsten Frommen

This code is licensed under the MIT License.