Jonas Schreiber
Jonas Schreiber

Reputation: 457

Unit Testing CodeIgniter

We have two CodeIgniter instances in production which I've just finished migrating to CodeIgniter 3. A large gap has been left in our code base since it was not designed with testability in mind. As the applications have evolved over 4 years throwing a test harness around it is not so simple.

There is code in controllers that just render views and code in views that just post to controllers and getting between the two is maddening.

I've tried to use PHPUnit to achieve testing as well as the CodeIgniter Unit Test class, but I always wind up back at this conundrum. Is there any advice people in similar situations can offer?

Upvotes: 0

Views: 626

Answers (1)

Federico J.
Federico J.

Reputation: 15902

Well, it's quite hard to achieve testing in a legacy application in Codeigniter... What I ended up doing is:

  • Libraries and classes that can be isolated, are tested via PHPUnit
  • Controllers and rendering are tested via BDD. I use Codeception and Selenium (with Mozilla browser) to perform Acceptance tests, that at least makes sure that all is working alright (rendering, placing of elements and so on).

I would also like hearing from others experience. I personally use Codeception all the time even for Unit test (at the end, is built over PHPUnit). Main page: http://codeception.com/

Upvotes: 2

Related Questions