custom-post-type-ui icon indicating copy to clipboard operation
custom-post-type-ui copied to clipboard

Make phpunit (or Brain Monkey) a dependency

Open GaryJones opened this issue 8 years ago • 1 comments

One of the good practices of software development is that dependencies are explicit and isolated.

This project contains some unit / integration tests, but phpunit is not listed in require-dev in composer.json. That means it's assuming that developers have it installed, but that means it's then making assumptions about which version is installed, and therefore what features can be used / not used in tests.

Note: The Travis config file actually already includes different versions of PHPUnit depending on which version of PHP is available.


Before just including phpunit as a require-dev dependency though, I want to put forward an extension of this idea:

A quick scan of the tests suggest that at least some of them are unit tests - that is, testing one function or method, without the need to bootstrap WP first. Even some of the other tests could easily have certain WP functions mocked, without needing to be full integration tests involving a database.

My preference, and suggestion, would be to use Brain Monkey, which includes phpunit as a dependency, but already has support for testing actions and filters, and monkey-patches PHP / WP functions.

This then allows there to be a distinction between unit tests (quick, standalone tests), and integration (requires WP to be bootstrapped), which can make running test suites much quicker. An example of the tests/ layout can be seen here, and you can see that the bootstrap.php only conditionally loads WP depending on which --testsuite is run.

GaryJones avatar Nov 13 '17 04:11 GaryJones

Color me interested :D

tw2113 avatar Nov 13 '17 17:11 tw2113