0

I currently test my CodeIgniter app with phpunit by using CIUnit (https://bitbucket.org/kenjis/my-ciunit). The problem is that I have multiple controllers with the same name. I have a controller in the root controller directory named "Blog" and I have a controller called "Blog" in the controller/ajax/ directory. The reason is to seperate all ajax requests from the main controller.

When I am running tests on both files, I get the following error:

PHP Fatal error: Cannot redeclare class Blog in ...

Well, I am not suprised I am getting this error.

What are my options to resolve this?

  1. Prefix controllers in ajax directory with "ajax" (looks only a bit stupid url/ajax/ajax_blog)
  2. Use namespaces (I guess I need to namespace codeigniter too then)
  3. Create 3 seperate phpunit.xml files

This aren't really solutions I am looking for. Do I have any other options? Is it somehow possible to run each testsuite seperatly, but still in one command? Can I "clean" objects between testsuites? Anything else?

P.T.
  • 3,130
  • 4
  • 19
  • 24

1 Answers1

1

There are no other options except those you mentioned, as it is impossible to "unload" class definitions in PHP.

Naming two controllers the same is not a problem when you run CI normally, since only one controller is instantiated per request, but something that should be avoided.

If it is just the ajax-url you don't like, maybe override it in a route (in config/routes.php):

$routes['ajax/blog'] = 'ajax/ajax_blog';
cschorn
  • 1,191
  • 10
  • 11