Suggestion to do less changes in the system files
al-villalba opened this issue · 2 comments
First of all, thanks for your post and so let others know it's possible to perform unit testing with phpunit with little effort.
As you mentioned, CI is not test-friendly and so system files need to be hacked. I got phpunit running only changing the file Utf8.php
because all other changes affect or are related to the bootstrap.
Instead of setting <phpunit bootstrap="index.php">
in phpunit.xml
I created a bespoke tests/bootstrap.php
made up by concatenating index.php
and CodeIgniter.php
, the latter up to the line where the controller action is called, and replacing it as <phpunit bootstrap="bootstrap.php">
.
Moreover, in the bootstrap I've defined new functions:
function show_404($page = '', $log_error = TRUE)
{
throw new PHPUnit_Framework_Exception('404 Page Not Found --> '.$page, 404);
}
function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
{
throw new PHPUnit_Framework_Exception($message, $status_code);
}
so that they are not loaded in Common.php
.
Doing so, changes of system files is reduced at a minimum.
I hope this helps.
Cheers.
Hi @al-villalba, thanks for your suggestion! I'll review it and do some tests, sounds promising. Reducing changes in system files is a good goal and could improve compatibility with future versions.
@al-villalba I've used your suggestion on 186c84e
Project now has a custom bootstrap like you suggested, creating show_*
functions like you did. However, I chose to keep CodeIgniter.php
hacks, because IMO copying two source files would degrate compatibility. It's easier to show where core files should be hacked than making sure a copied bootstrap is kept current with future files.
Also, I used your insight to look for other places to do the hacking and released an improved version, you should check out.
Thanks!