T
T
TheHorse2012-10-05 16:11:50
CodeIgniter
TheHorse, 2012-10-05 16:11:50

CodeIgniter and Unit Tests. What to use?

There is a project on CodeIgniter (4 Controllers (3 of them are inherited from the main one), 4 models (3 of them are inherited from the main one), about 40 views, 8 helpers ~ 5,000 written code).
The goal is to cover the whole thing with unit tests, so that you can run all the tests once and see the full report .
In this connection questions:
1. What to use ? The Unit Test Class from CodeIgniter is more like an assert than anything normal. With it, I will not be able to test everything in one run. With PHPUnit, everything is aggravated by the fact that it is not related to the CodeIgniter structure and I cannot simply include some class because all autoload, dependencies, and others will not be pulled up.
Context :
I can’t do mocking, because everything is strongly tied to the database and it is important to know about errors in the database, as well as about errors in the incoming data.
There are also functions for sending mila, sms-ok. And all this is involved in the business logic, which I also want to automatically test.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
TheHorse, 2012-10-05
@TheHorse

The question was not about what to do with the database and so on, but about access levels and how to get access to the method under test, or rather, to all the methods under test.
I came up with this:
For each model and controller, inside the class I make a test method , and a separate helper with a set of tests. In this test , I simply run all the methods of the corresponding helper (I still need to think about the syntax), so that the test method is minimal, and all tests are defined exclusively in helpers.
Then, I make one method, for site.com/test , which will launch all tests for the necessary controllers, even through ajax , which will launch all tests of the corresponding models.
Eventually:
1. Having opened the page, I will get the results of all unit-tests.
2. Minimal impact on the code under test (+1 method in all classes)
3. No need for any additional tools.
PS I beg your pardon, the question is rather stupid than not stupid.

P
pletinsky, 2012-10-05
@pletinsky

If you can’t make mocks, then it’s not about unit tests at all, and regular unit test frameworks may not help you. Unit tests are tests on individual modules - usually on class methods in isolation from the external environment.
Not only from the database, but from all other classes in general.
And if you approach the matter this way, then you should not give a damn about the fact that unit tests do not pull something up there.
Unit tests assume the architectural readiness of the system and are usually written before the code within TDD.
If you want to make the application stable, in your case you need behavior tests. Just deploy the application as if you were doing it in production - and test all its behavior as a whole by emulating user actions on the web.

V
Vladimir Chernyshev, 2012-10-05
@VolCh

Try to tie Codeception from Davert as far as I remember CI should be easy to tie. There are examples for Kohana, ZF, Symfony, by analogy it should be easy to do for CI.

P
pletinsky, 2012-10-05
@pletinsky

That is, you can, of course, bind to different levels of the application in tests - but in this case, as I understand it, you cannot bind to anything - so I propose to bind to the highest possible level, considering the insides of the application as a black box.
Everything else depends very much on the work of the project itself - why you can’t organize something like integration tests there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question