PHPackages                             tfrommen/testable-code - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. tfrommen/testable-code

ActiveLibrary[Testing &amp; Quality](/categories/testing)

tfrommen/testable-code
======================

Example code for the talk "How (Not) to Write Testable Code" at WordCamp Nuremberg, 2016.

952[13 PRs](https://github.com/tfrommen/testable-code/pulls)PHP

Since Mar 26Pushed 9y ago1 watchersCompare

[ Source](https://github.com/tfrommen/testable-code)[ Packagist](https://packagist.org/packages/tfrommen/testable-code)[ RSS](/packages/tfrommen-testable-code/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (14)Used By (0)

How (Not) to Write Testable Code
================================

[](#how-not-to-write-testable-code)

This repository contains example code for the according talk at WordCamp Nuremberg, 2016.

Unit Test Examples
------------------

[](#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](php/0-unit-test-examples) as well as the respective [JavaScript unit tests](js/0-unit-test-examples).

### Running the Tests

[](#running-the-tests)

You want to run the tests yourself? Here's how:

#### JavaScript

[](#javascript)

In order to run the JavaScript tests, you have to install the required [npm](https://www.npmjs.com/) packages first.

Using [Yarn](https://www.npmjs.com/package/yarn):

```
$ yarn && yarn run test
```

Using [npm](https://www.npmjs.com/package/npm):

```
$ npm i && npm run test
```

#### PHP

[](#php)

In order to run the PHP tests, you have to install the required [Composer](https://getcomposer.org/) packages first.

```
$ composer install && vendor/bin/phpunit
```

Bad Practices
-------------

[](#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](php/1-bad-practices/src) and [JavaScript code](js/1-bad-practices/src) 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](https://github.com/tfrommen/testable-code/pulls). By means of the diff view, you can easily compare the original and the improved code.

Feel free to [fork this repository](https://github.com/tfrommen/testable-code/fork), and work on possible tests, if you like.

Changelog
---------

[](#changelog)

[Changelog](CHANGELOG.md).

License
-------

[](#license)

Copyright (c) 2016 Thorsten Frommen

This code is licensed under the [MIT License](LICENSE).

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6049306?v=4)[Thorsten Frommen](/maintainers/tfrommen)[@tfrommen](https://github.com/tfrommen)

---

Top Contributors

[![tfrommen](https://avatars.githubusercontent.com/u/6049306?v=4)](https://github.com/tfrommen "tfrommen (10 commits)")

---

Tags

testabilityunit-testing

### Embed Badge

![Health badge](/badges/tfrommen-testable-code/health.svg)

```
[![Health](https://phpackages.com/badges/tfrommen-testable-code/health.svg)](https://phpackages.com/packages/tfrommen-testable-code)
```

###  Alternatives

[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14429.2M352](/packages/dms-phpunit-arraysubset-asserts)[phpbenchmark/phpbenchmark

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

8011.5k2](/packages/phpbenchmark-phpbenchmark)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
