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]
  • #16 / Nov 10, 2008 6:31pm

    rafsoaken

    33 posts

    Hi Anurat,
    sorry for the late reply - I did try to figure out what went wrong with your setup, but can’t quite reproduce it. Your version numbers (at least the ones that matter.. we don’t use Apache and XAMP when testing) are fine and I upgraded phpunit to 3.3 to have a look at that version too (I ran it under 3.2 previously).
    Although I now get one test failure, running phpunit 3.3.4, the CIUnit runs fine. Maybe you did not use the right folder structure, did not copy Codeigniter.php over or similar?
    I’ll update CIUnit in any case, so it will work with the latest CI 1.7, phpunit 3.3.4.
    Let me know if you got any further in the meantime.

  • #17 / Nov 12, 2008 4:54am

    Dr.Dan

    18 posts

    Hi,

    I want to implement phpunit for CI, but I am not getting the setting up process

    First of all, can I run the tests in the browser? I don’t want to use a command line interface, I would prefer calling the test functions through the browser

    I am also not getting the setting up process on this link http://www.foostack.com/foostack/ specially the 5th one

    Create a new database setting that will act as the test database (it will always be cleared when you run tests!), that is named like your development setting but with a trailing ‘_test’. Note: CIUnit fixtures will ask for the trailing ‘_test’ to prevent accidental data loss.

    What do they meant by’ Create a new database setting’?

    Congratulations you are done with installing fooStack!

    Oh, wait, do you have phpUnit already installed?

    http://www.phpunit.de/pocket_guide/3.2/en/installation.html

    How can I install the phpunit on localhost?

    I am totally confused about these issues and any help will be appreciated.

    Thanks

  • #18 / Nov 12, 2008 6:49pm

    Verber

    1 posts

    First of all thank you for good tool. Just set it up, seems all works, but…
    When I run “phpunit—verbose AllTests.php” in console I see series of warnings like this:

    
    
    

    I try to fix it replacing

    //$path = str_replace("\\", "/", $system_folder);
    $path = str_replace("\\", "/", $path);

    (line 136, CIUnit.php)
    In this case I get all html output to console and

    Fatal error: Call to a member function append_output() on a non-object in /var/www/vhosts/ciphpunit/htdocs/system/libraries/Loader.php on line 708

    Looks like in Loader we have NULL instead of $OUT
    Now trying to fix this bug. Any ideas about it?

  • #19 / Dec 22, 2008 11:04pm

    spyro

    89 posts

    I setup foostack 0.12 and received the following error.

    A PHP Error was encountered

    Severity: Notice
    Message:  Undefined index:  spyc
    Filename: libraries/Controller.php
    Line Number: 300

    </div>
    Fatal error: Cannot access empty property in C:\xampp\htdocs\\system
    \application\libraries\Controller.php on line 301


    My environment is running in XAMPP and I am using the HMVC extension. The HMVC part might be what is effecting foostack.

    Any ideas on how to fix this?

  • #20 / Dec 22, 2008 11:08pm

    spyro

    89 posts

    Hi,

    I want to implement phpunit for CI, but I am not getting the setting up process

    First of all, can I run the tests in the browser? I don’t want to use a command line interface, I would prefer calling the test functions through the browser

    I am also not getting the setting up process on this link http://www.foostack.com/foostack/ specially the 5th one

    Create a new database setting that will act as the test database (it will always be cleared when you run tests!), that is named like your development setting but with a trailing ‘_test’. Note: CIUnit fixtures will ask for the trailing ‘_test’ to prevent accidental data loss.

    What do they meant by’ Create a new database setting’?

    Congratulations you are done with installing fooStack!

    Oh, wait, do you have phpUnit already installed?

    http://www.phpunit.de/pocket_guide/3.2/en/installation.html

    How can I install the phpunit on localhost?

    I am totally confused about these issues and any help will be appreciated.

    Thanks

    It took me a moment to figure this one out also.

    Here are the steps that I took to make it work.
    1. Go to database.php
    2. Copy all of the $db[‘default’] lines
    3. Paste them below
    4. Everywhere it says [‘default’] change it to [‘default_test’]
    5. Use a different db on this line $db[‘default_test’][‘database’] =

    Hope that helps.

  • #21 / Dec 23, 2008 8:10pm

    rafsoaken

    33 posts

    I setup foostack 0.12 and received the following error.

    A PHP Error was encountered

    Severity: Notice
    Message:  Undefined index:  spyc
    Filename: libraries/Controller.php
    Line Number: 300

    </div>
    Fatal error: Cannot access empty property in C:\xampp\htdocs\\system
    \application\libraries\Controller.php on line 301


    My environment is running in XAMPP and I am using the HMVC extension. The HMVC part might be what is effecting foostack.

    Any ideas on how to fix this?

    hi spyro,
    CIUnit was not tested against HMVC. As far as I know affects HMVC the way controllers are loaded, breaking the load mechanism of CodeIgniter that CIUnit is assuming.
    I don’t know how much effort it would require to reconcile the two - but if anyone makes the effort, I’d be more than happy to add this change to CIUnit.
    cheers
    raf

  • #22 / Dec 23, 2008 8:42pm

    spyro

    89 posts

    hi spyro,
    CIUnit was not tested against HMVC. As far as I know affects HMVC the way controllers are loaded, breaking the load mechanism of CodeIgniter that CIUnit is assuming.
    I don’t know how much effort it would require to reconcile the two - but if anyone makes the effort, I’d be more than happy to add this change to CIUnit.
    cheers
    raf

    I am going to see what I can figure out. Unfortunately I am still new to CI and haven’t messed around with extending core functionality. This is why I posted, to see if someone could start me in the right direction to begin figuring out how to get the two to work together.

  • #23 / Jan 11, 2009 2:16pm

    bhogg

    42 posts

    For some reason the result of output() is always an empty string.  The output is not being displayed on screen so it is likely being captured somewhere.

    I can capture the output from an individual view, but would be nice to test the output from a call to a controller function too.

    Anyone else had this issue?

    Cheers,
    Brian

  • #24 / Feb 03, 2009 5:28pm

    Eric Saboia

    6 posts

    I need to do all steps (replace Codeigniter.php, add lines in my database.php, etc) every time to make my tests? and after i will need return this steps to get my normal work aplication again?

    Sorry for my bad english, and thanks for share this project!

  • #25 / Feb 03, 2009 6:43pm

    bhogg

    42 posts

    You do it just once - those changes become part of the core of the application you’re building.  I don’t think it will be a noticable difference in performance, but you can always strip it out again in the release version.

  • #26 / Feb 04, 2009 10:09am

    Eric Saboia

    6 posts

    When i run my test, i receive this message:
    Strict Standards: Only variables should be passed by reference in C:\xampp\htdoc
    s\frameworks\ci\system\application\libraries\tests\CIUnit.php on line 66

    My test is:

    include_once dirname(__FILE__).'/../CIUnit.php';
    
    class Cliente_modelTest extends CIUnit_TestCase
    {
        protected $cliente;
    
        protected function setUp()
        {
            $this->CI->load->model('Cliente_model', 'pm');
            $this->cliente = $this->CI->pm;
        }
    
    
        public function testInserir()
        {
            try {
                $this->cliente->insert();
            } catch (Exception $e) {
                return;
            }
            
            $this->fail();
        }
    }

    What can be wrong? Thanks!

  • #27 / Feb 05, 2009 10:23am

    Eric Saboia

    6 posts

    Oh… i was trying to put “tests” into /libraries/ directory, now i have put on application/ directory and my problem has changed:

    C:\xampp\php>phpunit C:\xampp\htdocs\frameworks\ci\system\application\tests\mode
    ls\Cliente_modelTest.php

    Strict Standards: Assigning the return value of new by reference is deprecated i
    n C:\xampp\htdocs\frameworks\ci\system\application\libraries\fooStack\fooBase\Co
    mmon.php on line 170

    Strict Standards: Assigning the return value of new by reference is deprecated i
    n C:\xampp\htdocs\frameworks\ci\system\application\libraries\fooStack\fooBase\Co
    mmon.php on line 179

    Strict Standards: Assigning the return value of new by reference is deprecated i
    n C:\xampp\htdocs\frameworks\ci\system\application\libraries\fooStack\fooBase\Co
    mmon.php on line 279

    Strict Standards: Assigning the return value of new by reference is deprecated i
    n C:\xampp\htdocs\frameworks\ci\system\application\libraries\fooStack\fooBase\Co
    mmon.php on line 288

    Strict Standards: Assigning the return value of new by reference is deprecated i
    n C:\xampp\php\PEAR\Config.php on line 80

    Strict Standards: Assigning the return value of new by reference is deprecated i
    n C:\xampp\php\PEAR\Config.php on line 166

    Strict Standards: Assigning the return value of new by reference is deprecated i
    n C:\xampp\php\PEAR\Config\Container.php on line 111

    Any idea? Thanks!

  • #28 / Feb 06, 2009 5:04am

    bwuk

    6 posts

    Hi,

    I’ve installed CIUnit and PHPUnit. However, when I run:

    phpunit --verbose AllTests.php

    I get the following error:

    Fatal error: Call to undefined function foo_config() in ${my_wwwroot}\system\application\libraries\fooStack\fooBase\Common.php on line 98

    I’ve looked at the file, and I can see that it’s including the config.php which defines the function ‘foo_config’, but still it errors.

    Any advice anyone?


    Thanks


    bwuk

  • #29 / Feb 08, 2009 5:12pm

    rafsoaken

    33 posts

    Hi everyone,
    A new version (v0.13) of CIUnit is released! Get it here!

    Thanks for the very positive feedback to CIUnit! A couple of bugs have been fixed (like the one from the previous post) and testing your CodeIgniter application should now be more fun than ever!

    cheers
    raf

    PS: Thanks to everyone who helped hunting down bugs and gave feedback!

  • #30 / Feb 09, 2009 9:42am

    Eric Saboia

    6 posts

    I downloaded the new version and now i have this error:
    Class CIUnit_TestCase could not be found in C:\xampp\htdocs\frameworks\ci\system
    \application\tests\AllTests.php.

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

ExpressionEngine News!

#eecms, #events, #releases