ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Unit Testing with phpUnit (models+controllers+fixtures) - want it?

February 06, 2008 5:06pm

Subscribe [31]
  • #31 / Feb 09, 2009 5:23pm

    rafsoaken

    33 posts

    Hi Eric,

    You have to execute phpunit from within the tests directory, like so:

    system/application/tests> phpunit AllTests.php

    Hope this works now for you!
    cheers
    raf

  • #32 / Feb 10, 2009 9:05am

    Eric Saboia

    6 posts

    Ok, so i will need copy phpunit.bat to all directories of my tests? (Like tests/models)?

    Thanks very much!

  • #33 / Feb 10, 2009 12:14pm

    rafsoaken

    33 posts

    well first

    phpunit AllTests.php

    will run the tests in all the test subdirectories. If you want to run e.g. all the model tests you run

    phpunit ModelsAllTests.php

    from within the test/model directory.
    In your .bat file you could also just change the directory first, then execute the tests, then cd back.

    testmymodels.bat:

    cd test\models
    phpunit ModelsAllTests.php
    cd ..\..

    raf

  • #34 / Feb 15, 2009 9:04am

    rafsoaken

    33 posts

    Hi all,

    Your favourite unit testing tool fooStack/CIUnit for CodeIgniter just hit v0.14 !

    Some minor bugs have been fixed again, and the code was considerably cleaned up.
    Edit: Forgot to mention, that now CI v1.7.1 is supported, down to CI v1.6.0 !

    As usual, please get it here:
    http://www.foostack.com/foostack/

    enjoy
    raf

  • #35 / Feb 25, 2009 4:03pm

    stefanv

    9 posts

    Hi Raf,

    When i try to run the tests i get the following error message:

    Strict standards: Only variables should be passed by reference in /var/www/swapr/application/tests/CIUnit.php on line 69
    
    Call Stack:
        0.0003      53244   1. {main}() /usr/bin/phpunit:0
        0.0037     257516   2. require('/usr/share/php/PHPUnit/TextUI/Command.php') /usr/bin/phpunit:44
        0.1102    4552448   3. PHPUnit_TextUI_Command::main() /usr/share/php/PHPUnit/TextUI/Command.php:528
        0.1105    4560800   4. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/php/PHPUnit/TextUI/Command.php:90
        0.1105    4560876   5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:200
        0.1105    4561100   6. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:269
        0.1106    4561372   7. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/php/PHPUnit/Runner/StandardTestSuiteLoader.php:97
        0.1549    4564688   8. PHPUnit_Util_Fileloader::load() /usr/share/php/PHPUnit/Util/Fileloader.php:105
        0.1553    4576380   9. include_once('/var/www/swapr/application/tests/models/ModelsAllTests.php') /usr/share/php/PHPUnit/Util/Fileloader.php:129
        0.1562    4618880  10. require_once('/var/www/swapr/application/tests/CIUnit.php') /var/www/swapr/application/tests/models/ModelsAllTests.php:18
        0.1637    5165552  11. set_controller() /var/www/swapr/application/tests/CIUnit.php:221
        0.1637    5165676  12. CIUnit::set_controller() /var/www/swapr/application/tests/CIUnit.php:185

    Looks like PHP5 doenst like a call you are doing..

  • #36 / Feb 27, 2009 1:43am

    DPrevite

    9 posts

    Am I the only one having trouble running this under Linux? There seem to be case sensitivity problems. Some places expect “Spyc” to have a capital S. Others lowercase.

    I had to rename controller_fixt.php as Controller_fixt.php too.

  • #37 / Feb 27, 2009 8:27pm

    rafsoaken

    33 posts

    Hi,

    @stefanv,

    Strict standards: Only variables should be passed by reference in /var/www/swapr/application/tests/CIUnit.php on line 69

    I could not get this STRICT warning reproduced. What version of PHP are you using (I use v5.2.2 atm)?
    [edit] I added an ampersand in front of a function call in CIUnit.php, but could not check if it fixed the problem.

    @DPrevite,

    Am I the only one having trouble running this under Linux? There seem to be case sensitivity problems. Some places expect “Spyc” to have a capital S. Others lowercase.

    I had to rename controller_fixt.php as Controller_fixt.php too.

    Sorry for that, I am developing this indeed on Windows but should start running the tests on *nix machines too. Until then I only can rely on feedback such as your’s 😊

    I renamed the Controller fixture in the repository version, and fixed (hopefully all) case issues with the spyc directory.

    cheers
    raf

  • #38 / Mar 01, 2009 12:25am

    DPrevite

    9 posts

    Ok so I have it running the default tests that come with CIUnit. I’m getting an error, but it doesn’t seem to be causing any of the tests to fail.

    I think when CI tries to start the session it can’t because phpunit has already echoed something.

    This is the output. Any ideas on how I can prevent this error?

    
    									
  • #39 / Mar 01, 2009 5:46pm

    rafsoaken

    33 posts

    Ok so I have it running the default tests that come with CIUnit. I’m getting an error, but it doesn’t seem to be causing any of the tests to fail.

    I think when CI tries to start the session it can’t because phpunit has already echoed something.

    This is the output. Any ideas on how I can prevent this error?

    Hi DPrevite,

    As phpUnit already prints its signature when you run it, you will always get this warning when you set a header from anywhere in your code (and equally for setting cookies).
    The problem lies thus in how to prevent the CI Session class from setting these headers during testing. A simple solution is subclassing the Session class, and creating a custom _set_cookie() method. Then you can place an if statement around the offending statement:

    if (!defined('CIUnit_Version')) { setcookie(...); }

    The constant ‘CIUnit_Version’ is defined by CIUnit in your code when running in test mode. Therefore this would prevent to set headers at all.

    The second possibility also needs a subclassed Session class, where instead of the call setcookie(); within session->_set_cookie(), you call the set_cookie() method on the fooOutput class (available as $CI->output->set_cookie()). Thus:

    $CI = &get;_instance(); $CI->output->set_cookie(...);

    Using this fooOutput method has the effect that for normal web requests the headers are set at the last moment before rendering the content. For testing however, headers and rendered output strings stay in the output class as instance variables.

    I would recommend to try the second possibility and also anywhere in your code where you want to set headers / cookies use $CI->output->set_cookie(), or $CI->output->soft_set_headers(), instead of the PHP calls setcookie() and header().

    cheers
    raf

  • #40 / Mar 02, 2009 4:56am

    stefanv

    9 posts

    Hi,

    @stefanv,

    Strict standards: Only variables should be passed by reference in /var/www/swapr/application/tests/CIUnit.php on line 69

    I could not get this STRICT warning reproduced. What version of PHP are you using (I use v5.2.2 atm)?
    [edit] I added an ampersand in front of a function call in CIUnit.php, but could not check if it fixed the problem.

    cheers
    raf

    Raf i’m using PHP 5.2.6-2ubuntu4.1 with Suhosin-Patch 0.9.6.2 & Xdebug 2.0.3.
    I’ll check you repos version tonight and let you know if the problem is fixed.

    Thnx

  • #41 / Mar 09, 2009 10:55am

    jacobc

    42 posts

    rafsoaken.
    I’ve just started trying out CIUnit…

    I had to create an About controller in order to generate fixtures.

    Line 107 of generate. $this->CI = set_controller(‘About’);

    Is this intended?

  • #42 / Mar 09, 2009 10:58am

    stefanv

    9 posts

    Raf i’m using PHP 5.2.6-2ubuntu4.1 with Suhosin-Patch 0.9.6.2 & Xdebug 2.0.3.
    I’ll check you repos version tonight and let you know if the problem is fixed.

    Problem is fixed!
    All tests are running fine now..

    Thnx again..

  • #43 / Mar 09, 2009 10:08pm

    spyro

    89 posts

    I just gave the latest test version a run and after configuration all I get is the following.

    PHPUnit 2.3.6 by Sebastian Bergmann.

    Syntax error in CIUnitAllTests.php.

  • #44 / Mar 22, 2009 8:50am

    PHP Four

    5 posts

    Hi rafsoaken,

    Thanks for the work with this breeze between my fav CI and phpUnit. The installation steps of the CIUnit are self-explained, however I was looking for a Tutorial on how to use it properly. I’ve searched for that on the web but no luck.

    Can you point me somewhere ?

    Thanks

    Emran

  • #45 / Apr 02, 2009 9:04am

    MDomansky

    9 posts

    Thanks for good tool )


    Please, give me an example how to create database tests???

    I have about ten tables with connections and if I add one object I need add about 5 rows to database to diff tables.

    Can you explain me how to create accordingly tests?

    Thanks in advice

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases