Who is this article for?
Most likely for those who have not yet begun to test, but has such a desire. Experienced developers in this case will not be able to surprise, but those who have not yet moved to the side of the world, I will try to push on this step.
Prehistory
I decided to deal with automatic testing. Previously, this was not necessary, and even then it was not particularly necessary. But there was free time, which I decided to spend with benefit for the future.
After reading the theory, I began to look for a tool for this. Predictably
PhpUnit appeared first on the horizon. But he seemed somehow cumbersome, or something.
Codeception seemed more convenient - different types of tests, expressive syntax. But, after looking at the dependencies, I realized that I did not need so much.
Moving towards simplicity, I found
atoum , and then generally a cool thing called
Testify.php . It was then that I thought that I had finally found what I needed.
But I was happy early. Testify.php did not match when writing the first test. A caching class was tested, which, depending on whether debugging is enabled or not, could process or ignore calls. Since the debugging mode assumed the presence of a
DEBUG constant with a value of
true /
false , it will not be possible to redefine it in one process.
Requirements
After these searches, I realized that I needed a simple tool that:
- It will test in different processes to determine the necessary constants, to mock the same classes for different tests in different ways, etc.
- It will be as easy to use
- It can work both through the browser and from the command line
- It can be used together with Travis CI (console version - should return status 0 in case of successful testing)
Implementation
A small script was written that opened the tests for http, collected the results, and issued it in presentable HTML. In order to make the testing process similar for the console version, it was decided to use the built-in PHP 5.4+ web server. It starts like this:
')
And it worked as it should. So, I did not find a similar tool - I decided to arrange it in the form of an independent composer package, added interactivity (the progress of test sets execution is displayed in real time both in HTML and in the console version).
Running tests:
Now this file can be opened either in the browser or in the console.
php test.php
The tests themselves are not much harder:
return 5 != 3 ? 0 : 'Strange PHP';
That is, each individual test is a file that returns
0 after a successful test or an
error text , if any.
Example of the result of the console version:

It is possible to execute general commands both before all test suites, and before all tests of one test kit.
I am sure that it can be done even better, therefore I am waiting for constructive criticism and suggestions.
No dependencies, bare PHP 5.4+ will do.
GitHub repository:
github.com/nazar-pc/CSTesterComposer package:
packagist.org/packages/nazar-pc/cstester