Welcome Guest, Not a member yet? Register   Sign In
I'd really like to get PHPUnit working with CI
#1

[eluser]techguy101[/eluser]
Hi Guys,

I haven't really been posting here much but i've been using CI a bit over the last year or two.

I'm working on a project at the moment that I would love to be able to test with PHPUnit. I'm aware of the problems surrounding this and would really like to overcome them.

I know you probably can't test the controllers, which is fine by me. I really just want to test my libraries and models.

So, has anybody successfully gotten PHPUnit to test models, I think libraries are probably ok?

I have searched the forum etc and read about the solutions for CI 1.7.2 but there doesn't seem to be much available for 2.0?

Would anybody be interested in working with me to develop a nice bridge between CI 2.0 and PHPunit to make testing easier.. Ideally I want to be able to script my tests with various chunks of test data..

Thanks for any input guys.

techguy
#2

[eluser]kilishan[/eluser]
I know the Reactor team is working on Unit Tests for CI using PHPUnit. I believe the latest code in BitBucket contains everything needed to use it, though I haven't tried the code yet.
#3

[eluser]techguy101[/eluser]
Cool, I just had a look and spotted the unit test branch.

I wonder where i'll find docs on it, I'm not used to BitBucket.

Thanks for that.
#4

[eluser]kilishan[/eluser]
As for docs... good question Smile You might stalk @gaker or @pkriete on Twitter to see if they can give you any pointers. Smile
#5

[eluser]techguy101[/eluser]
Cool, thanks.

I just tweeted @gaker, he says they are testing the core now, so it should be out soon.

Great stuff.

Thanks again Smile
#6

[eluser]kilishan[/eluser]
No problem! I'm just excited the core is actually going to have good test coverage. Will make keeping things stable much easier for the Reactor team.
#7

[eluser]CarloGl[/eluser]
Hi,

I'm working at a project using CI and I'm testing controllers with PHPUnit.
I'm using 1.7.3 since it needs to work with PHP 4, but updating to 2.x is straightforward.
It requires a little tweaking of the bootstrapping sequence and some fixing extending a couple of core classes. I have flagged one of the issues in Bug Tracker.

I'd like to share my approach. You might find a better way of doing things and maybe our work might be of interest to others in the CI community.

Let me know if you'd like me to expand on this.

Regards

Carlo
#8

[eluser]Zair[/eluser]
Hello Carlo, I would like to know more about this, can you please help me on this. I am using CI 2.0, how can I bridge the PHPUnit and FooStack or is there any other way doing it.. please help.

thanks,
#9

[eluser]CarloGl[/eluser]
Hi Zair,
I'm not using FooStack. I plug in PHPUnit directly.
The way I go about this is by providing an alternative entry point that uses the same bootstrapping sequence provided by core/CodeIgniter.php, but stops before routing kicks in.

This requires:
- extracting the variable definitions in the index page into a config/settings.php file
- providing a bootstrap.php file included in test classes

I also use a sub class of PHPUnit_Framework_TestCase ( CITestCaseExtension ) to provide some basic common functionality to the test classes, including some rudimentary functions to set up fixtures.

The test classes are organized in an application/tests directory that mirrors the controllers' so that by pointing the phpunit script to that directory all the tests wherein are run together.

We have:
index.php
application
|__ config
| |__ settings.php
|__ controllers
| |__ myController.php
|__ tests
|__ bootstrap.php
|__ CITestCaseExtension.php
|__ myControllerTest.php

In this case changing to application and running:
phpunit --include-path /application tests

phpunit automatically runs myControllerTest instantiating myController

I'm attaching sample files to clarify.
#10

[eluser]pmoroom[/eluser]
Any updated news on this?




Theme © iAndrew 2016 - Forum software by © MyBB