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]
  • #61 / Jul 21, 2010 3:38am

    sidhartha

    10 posts

    To integrate codeigniter with phpunit i use CIUnit from http://www.knollet.com/foostack/


    after following all the steps mentioned in the site http://www.knollet.com/foostack/ i ran

    ‘phpunit AllTests.php’ in the tests folder from the command prompt. it runs well.


    but when i want to run a test for a controller it produces the following error though my phpunit for general programmes(without mvc) works well.

    PHP Fatal error:  Class ‘Controller’ not found in /opt/lampp/htdocs/mytask/system/application/controllers/country.php on line 9


    some one please help me. i have stopped here for more than 3 days

  • #62 / Jul 29, 2010 3:09am

    sidhartha

    10 posts

    if i run ‘phpunit AllTests.php’ in tests directory (system/application/tests) it works fine. but the time when i run’phpunit ModelsAllTests.php’ inside the subdirectory of test i.e(system/application/tests/models) it shows some error. inmy case it is

    PHP Warning:  require(/opt/lampp/htdocs/calculator/system/application/libraries/fooStack/fooBase/../../../../../../application/libraries/fooStack/fooBase/Common.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/calculator/system/application/libraries/fooStack/fooBase/CodeIgniter.php on line 39
    PHP Fatal error:  require(): Failed opening required ‘/opt/lampp/htdocs/calculator/system/application/libraries/fooStack/fooBase/../../../../../../application/libraries/fooStack/fooBase/Common.php’ (include_path=’.:/opt/lampp/lib/php/PEAR:/root/PEAR’) in /opt/lampp/htdocs/calculator/system/application/libraries/fooStack/fooBase/CodeIgniter.php on line 39


    what r the changes i need to do to overcome this?


    i also want to know where should i write the test cases for a controller and a model respectively.

    Finally I got it working. this problem was due to the wrong path setting in the

          application/libraries/fooStack/fooBase/index.php for $system_folder at line# 26 and for $application_folder at line # 43.


    I am using fooStack v0.17 - for CI 1.7.2. in my case

    $system_folder = “../../../../../system”; and

    $application_folder = “application”;

    This may save some hours for somebody who gets this problem.

    sidhartha

  • #63 / Jul 29, 2010 3:25am

    sidhartha

    10 posts

    To integrate codeigniter with phpunit i use CIUnit from http://www.knollet.com/foostack/


    after following all the steps mentioned in the site http://www.knollet.com/foostack/ i ran

    ‘phpunit AllTests.php’ in the tests folder from the command prompt. it runs well.


    but when i want to run a test for a controller it produces the following error though my phpunit for general programmes(without mvc) works well.

    PHP Fatal error:  Class ‘Controller’ not found in /opt/lampp/htdocs/mytask/system/application/controllers/country.php on line 9


    some one please help me. i have stopped here for more than 3 days

    This problem was due to a wrong folder setting. Actually I auto generated the skeleton for a test class using netbean IDE. The generated test file CountryTest.php resided in system/application/tests/system/application/controllers as per PHPUnit.

    However for CIUnit point of view it should have been placed in system/application/tests/controllers as country.php is a controller.

    similarly for all the test files for models must be placed in system/application/tests/models folder and test files for libraries must be placed in system/application/tests/libs folder and so on in CIUnit.


    To have it working, copy/cut the auto generated skeleton file for test and paste it in required folder.

  • #64 / Oct 21, 2010 11:13am

    George Tavas

    5 posts

    Hello guys,

    has someone tried the CIUnit with MatchBox?

    I’m facing some problems regarding DB Class initialization and other libraries that are loading from the autoload config file.

    Any ideas?

  • #65 / Oct 21, 2010 4:58pm

    Buso

    297 posts

    CI is not designed to be unit-testable, so don’t waste your time trying.. If you need this you should try Symfony or Zend

  • #66 / Dec 31, 2010 8:43pm

    sp2hari

    2 posts

    Hi,

    I’m not sure if I’m the only one facing this issue. But how did you guys manage to modify the uri you are testing.

    Let me explain it with an example.

    I have profile pages,

    http://example.com/profile/show/1/ => Shows profile of user_id 1
    http://example.com/profile/show/2/ => Shows profile of user_id 2

    Now, I need to test the profile pages. I was able to set up foostack, set the controller as profile and call the function show. But it looks like the uri functions return 0 and because of which, my phpunit tests are failing.

    I tried to set the $_SERVER like

    $_SERVER[‘PATH_INFO’] = $_SERVER[‘REQUEST_URI’] = “profile/show/1/”;

    But that also didn’t help much..

    Any help in this direction is greatly appreciated.

  • #67 / Apr 04, 2011 5:08am

    Tibor Katelbach

    14 posts

    Hi everyone
    I’m quite freshly new to TDD’s
    I’m about to install Foostack
    and was wondering if anyone had experience adding code coverage over it ?
    and with which set up may I ask ?
    is it truly added value to TDD’s ?

    Regards
    Tibor

  • #68 / Apr 05, 2011 11:07am

    Tibor Katelbach

    14 posts

    Hi
    I’ve installed fooStack with latest phpunit 3.5
    there were some small changes easily repairable when following the logs
    but I get this now , and can’t find a solution

    Fatal error: Class 'foostack/fixture' not found in X:\X_Dev\ipm\www\system\application\libraries\Loader.php on line 1065

    if anyone has ever encountered this
    I’d love an enlightment
    Regards
    Tibor

  • #69 / Apr 05, 2011 3:28pm

    Tibor Katelbach

    14 posts

    After numerous trial and fail
    I gave and started moving files around

    Fatal error: Class 'foostack/fixture' not found in X:\X_Dev\ipm\www\system\application\libraries\Loader.php on line 1065

     

    so I moved Fixture.php one folder up inlibraries directly
    which solved the error

    I’m suspecting this might be linked to MatchBox (used on BEP) having changed the CI Loader

    now, next issue :

    Call to undefined method CI_Loader::viewfile(

    any ideas ?
    I’d love to understand how the fooLoader.php works ?
    since that’s where this file is

    I feel like I’m redoing to whole process since 2 days :(
    first was PEAR issue, then phpUnit, integration with CI
    if anybody experienced this , I’d be glad to hear how it ended
    I don’t really know if it’s goign to end somewhere

  • #70 / Apr 06, 2011 4:34am

    Tibor Katelbach

    14 posts

    Matchbox doesn’t work with foostack

    After a hard fight with my initial set up (containing Matchbox)
    I felt like a monkey jumping from error to error
    and hidding them under the carpet hoping it’ll pass
    This was not the right solution

    I ended up , reinstalling a fresh CI, copied foostack in there
    and it just worked

    so now my question to the authors ,
    would they feel the energy to help me get it working with MatchBox ?

    Regards
    Tibor

  • #71 / Jun 06, 2011 10:41am

    Tibor, did you ever get things running? I went through the same process of getting CIUnit linked up with CI2.0 and my project. Was not a pleasant experience. Once I got it running I decided I needed to implement an HMVC structure so I’m not about to get back to fixing the CIUnit/PHPUnit link to get my tests working again. I was wondering if you might have any pointers.

  • #72 / Oct 31, 2011 2:57am

    zechdc

    11 posts

    It looks like the main repo for this project has stopped active development.

    I found a few resources which everyone may find useful.

    Good news! Looks like the next release of CI might include a PHPunit class
    http://stackoverflow.com/questions/5791156/has-codeigniter-2-0-phpunit-happened-yet

    An active fork of the orignal repo:
    https://bitbucket.org/kenjis/my-ciunit

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

ExpressionEngine News!

#eecms, #events, #releases