tfrommen / testable-code
Example code for the talk "How (Not) to Write Testable Code" at WordCamp Nuremberg, 2016.
Requires
- php: >=5.4.0
Requires (Dev)
- antecedent/patchwork: 1.3.*
- brain/monkey: ^1.4.0
- mockery/mockery: ^0.9.7
- phpunit/phpunit: ~4.8|~5.1
- dev-master
- dev-php/insane-complexity
- dev-js/eval-expressions
- dev-php/creating-intermediary-objects
- dev-js/incomplete-initialization
- dev-php/calling-static-methods
- dev-js/breaking-the-law-of-demeter
- dev-php/using-unresettable-singletons
- dev-js/global-state
- dev-php/creating-real-objects-2
- dev-php/creating-real-objects
- dev-js/leaving-the-context
- dev-php/terminating-the-execution
- dev-js/no-feedback
This package is auto-updated.
Last update: 2024-11-15 15:33:58 UTC
README
This repository contains example code for the according talk at WordCamp Nuremberg, 2016.
Unit Test Examples
The first part of the talk is about unit testing. After a short summary, you can see several unit test examples. This repository includes the complete and fully documented versions of the presented PHP unit tests as well as the respective JavaScript unit tests.
Running the Tests
You want to run the tests yourself? Here's how:
JavaScript
In order to run the JavaScript tests, you have to install the required npm packages first.
Using Yarn:
$ yarn && yarn run test
Using npm:
$ npm i && npm run test
PHP
In order to run the PHP tests, you have to install the required Composer packages first.
$ composer install && vendor/bin/phpunit
Bad Practices
The second and main part of the talk then is about code examples that are either hard to test, or not testable at all. As with the unit test examples, this repository also includes the bad practice PHP code and JavaScript code examples.
Since only presenting bad (i.e., hard-to-test) code doesn't do any good, this repository also includes improved versions of the code. For each of the code examples, you can find an according pull request. By means of the diff view, you can easily compare the original and the improved code.
Feel free to fork this repository, and work on possible tests, if you like.
Changelog
License
Copyright (c) 2016 Thorsten Frommen
This code is licensed under the MIT License.