fmalk / codeigniter-phpunit

Hack to make CodeIgniter work with PHPUnit.
234 stars 61 forks source link

CI 3 hacks #21

Closed sylouuu closed 9 years ago

sylouuu commented 9 years ago

Hi,

CI 3 RC is out, I'd like to use PHPUnit with it. Then we need another hack documentation for this version...

Bests

fmalk commented 9 years ago

@sylouuu thanks for bringing this up. Stock unit testing seems to be a minor improvement from 2.x, so I guess this project is still needed...

feryardiant commented 9 years ago

Hi! All, after workaround I found.

In CI 3.0rc, the only system/core file need to overwrite is CodeIgniter.php#L531 which is:

if ($EXT->call_hook('display_override') === FALSE)

must become

if ($EXT->call_hook('display_override') === FALSE && !defined('PHPUNIT_TEST'))

As you can see, you can simply use display_override hooks as well. :wink:

Then, add is_cli() function overwrite in you application/tests/bootstrap.php

function is_cli()
{
    return;
}
fmalk commented 9 years ago

@feryardiant I've put your pull request on a CI3 branch, tagged 3.0. @sylouuu does that work for you? I haven't tested it myself yet.

sylouuu commented 9 years ago

Hi,

I've added this:

CodeIgniter.php:525

if ($EXT->call_hook('display_override') === FALSE && !defined('PHPUNIT_TEST'))

URI.php:110

if (is_cli() OR ($protocol = strtoupper($this->config->item('uri_protocol'))) === 'CLI' || defined('PHPUNIT_TEST')) 

And it works, I don't have the "very latest" CI version, so don't check my line numbers.

Bests :)

fmalk commented 9 years ago

@sylouuu You did this yourself, before seeing @feryardiant 's code? Because it seems to me that @feryardiant replaced is_cli() at bootstrap to do the same as you in URI.php hack.

sylouuu commented 9 years ago

Yes I did it before.

fmalk commented 9 years ago

I'll close the issue then.