A
A
AlxMrz2017-01-24 23:35:12
PHP
AlxMrz, 2017-01-24 23:35:12

How to add unit testing to an old project?

Hello!
A question. I am currently working on a project that has not been upgraded for 7 years. The current version of php is 5.2.17 . There was a need to add unit testing, but I ran into a problem: almost all testing tools require a new version of php (at least 5.3). There is no option to update the system now. In the process of searching, I found several solutions, but each with its own problems:
1) The most working one is to use SimpleTest. Concerning the php version - just right. The tests are running. However, the problem is that the project is very dimly maintained and will probably close soon, and sooner or later we will still have an update, we will want to use PHPUnit. Do not rewrite the same tests? I don't remember any other tools for Unit tests, but when I was looking, they also seemed to require something from PHP 5.3.3
2) Use PHPUnit version 3.4 (works from php 5.1+). The only problem is that it is not clear how to install. If you just download files from Github, then the problem arises with the paths, since there is something like this in each standard class file:

require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Framework/MockObject/Generator.php';
require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php';
require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedAtIndex.php';
require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedCount.php';
require_once 'PHPUnit/Framework/MockObject/Stub.php';
require_once 'PHPUnit/Runner/BaseTestRunner.php';
Of course, I can't download them. If there is a manual, I will be glad to link.
If I tried to download using pear, I found only this advice:
$ pear config-set auto_discover 1
$ pear install --alldeps phpunit
The problem here is that PHPUnit 3.7 is being installed, which is already very late. Need 3.4. What to write is not clear.
3) Use PHPUnit 5.7 on the local machine and test locally, but the question is how to test the code locally when you need to load various files (from a recent: yii1.1. The model inherits the standard class, and since I don’t take all the files from the server, but only a module, then there is nowhere for me to load the necessary files, and all sorts of stubs are too dreary, if at all possible, in my opinion
? There is a better solution, please write more about it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
index0h, 2017-01-24
@index0h

If I were you, I would update the environment first. Places with deprecated code - worth rewriting. As for the tests: in a developing project, they are constantly rewritten, this is quite normal.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question