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.

How to use PHPUnit (CIUnit) with CodeIgniter 2.1.0

January 16, 2012 8:38pm

Subscribe [10]
  • #16 / Sep 03, 2012 1:56pm

    nilacseruet

    1 posts

    I am trying to integrate ciunit, I followed the kenjis tutorials from http://d.hatena.ne.jp/Kenji_s/20120117/1326763908.

    But I got following error:
    Fatal error: Class ‘CIUnit_TestCase’ not found


    Here I show how I run test file in my command line(in windows pc).

    D:\xampp\php>phpunit D:\xampp\htdocs\programmerz\tests\models\PhoneCarrierModelTest.php

    I don’t understand where i am wrong. I guess PhoneCarrierModelTest.php file failed to loaded phpunit.xml file in tests folder. For that, it failed to include ../application/third_party/CIUnit/bootstrap_phpunit.php file.


    Please help me. Where I left some settings.

  • #17 / Sep 30, 2012 5:27am

    SPeed_FANat1c

    260 posts

    I am getting errors when updating pear. I don’t understand.

    C:\Users\Darius>pear channel-update pear.phpunit.de
    Updating channel “pear.phpunit.de”
    PEAR_Config::writeConfigFile fopen(‘C:\Windows\pear.ini’,‘w’) failed (fopen(C:\W
    indows\pear.ini): failed to open stream: Permission denied)

    C:\Users\Darius>pear channel-update pear.phpunit.de
    ERROR: The default config file is not a valid config file or is corrupted.

    At first it says that it failed to open streatm. I go to windows directory - there is no such file so I create it.

    After creating, it is empty, and it says it is corrupted.

    Isn’t there more normal way to install update of pear, wihtout manually creating files and without knowing how the file should look?

  • #18 / Oct 06, 2012 8:45am

    jmadsen

    438 posts

    There is an unofficial composer package:

    https://packagist.org/packages/EHER/PHPUnit

    I agree - PEAR on Windows is not any fun

  • #19 / Oct 11, 2012 12:11pm

    SPeed_FANat1c

    260 posts

    @jmadsen - thanks, somehow next day I tried again and upgrading pear worked 😊 don’t know what I did wrong before.

    Now another question - how to download CIUNIT for CI 2.1.0? I downloaded but it is for older versions - 1.7 and so on. 2.0.3 version is ok.

    When I go to Download > branches 2.1.0

    https://bitbucket.org/kenjis/my-ciunit/changeset/f8b91aeed768

    there is nothing to download.

    I also tried Downloads > Tags > v0.16

    but from there as I said I download old version.

    I see in the page:

    “default” branch is for CodeIgniter 2.1.0.
    To CodeIgniter 2.0.3 users, please use “CI 2.0.3” branch. You can get the latest code from https://bitbucket.org/kenjis/my-ciunit/get/CI 2.0.3.zip

    So for 2.0.3 there is a link. But where is for 2.1.0????????

    I also tried clone:


    C:\Users\Darius\Desktop\siuksles>hg clone https://bitbucket.org/kenjis/my-ciunit

    ‘hg’ is not recognized as an internal or external command,
    operable program or batch file.

    I don’t know what is hg, maybe windows does not support it or what. Anyway there should be normal link to download I think.

  • #20 / Oct 12, 2012 12:47am

    jmadsen

    438 posts

    “hg” is Mercurial, similar to svn or git

    http://mercurial.selenic.com/downloads/

    should get you a client so you can clone; I don’t use it much & am not sure if there’s a quicker way

  • #21 / Oct 14, 2012 3:54am

    SPeed_FANat1c

    260 posts

    thanks 😊

    BTW there was another command

    $ wget https://bitbucket.org/kenjis/my-ciunit/get/default.zip

    again wget does not work in my system, but I copied the url into browser and download worked, so Mercurial is not needed I guess.

    Now I will try to execute them and will check if the instalation will work 😊

    Edit:
    btw in case someone iinterested, I installed gow to execute linux commands on windows

    http://ashu-geek.blogspot.com/2012/01/how-to-run-various-linux-commands-on.html

    but still I cannot find how to execute .sh file with that program.

  • #22 / Oct 17, 2012 12:07pm

    SPeed_FANat1c

    260 posts

    Hello again,

    I still have problems with running the first test 😊

    Darius@Darius-PC /cygdrive/e/projektai/php projektai/htdocs/ci_unit/tests
    $ phpunit models/PhoneCarrierModelTest.php
    Could not open input file: /cygdrive/e/other/xampp/php/phpunit

    why it cannot open the file, I don’t get?

    the same is when I don’t specify the file

    Darius@Darius-PC /cygdrive/e/projektai/php projektai/htdocs/ci_unit/tests
    $ phpunit
    Could not open input file: /cygdrive/e/other/xampp/php/phpunit

     

    Oh, btw I tried it with windows native cmd and it did not throw this error, it told that cannot connect to database and so on, so I will fix the connection settings and will check.

  • #23 / Oct 20, 2012 3:37am

    SPeed_FANat1c

    260 posts

    So I fixed the connection settings, but still getting error:

    E:\projektai\php projektai\htdocs\ci_unit\tests>phpunit
    PHPUnit 3.5.14 by Sebastian Bergmann.
    
    ....[CIUnit] PHP Error: Warning - include(E:\projektai\php projektai\htdocs\ci_u
    nit\application\config\testing\database.php): failed to open stream: Permission
    denied File Path: database/DB.php (line: 41)
    [CIUnit] PHP Error: Warning - include(): Failed opening 'E:\projektai\php projek
    tai\htdocs\ci_unit\application/config/testing/database.php' for inclusion (inclu
    de_path='.;E:\\\\\\\\\\\\\\\\other\\\\\\\\\\\\\\\\xampp\\\\\\\\\\\\\\\\php\\\\\\\\\\\\\\\\PEAR\\\\\\\\\\\\\\\\pear;C:\\\\\\\\\\\\\\\\Users\\\\\\\\\\\\\\\\Darius\\\\\\\\\\\\\\\\Desktop\\\\\\\\\\\\\\\\siuksles\\\\\\\\\\\\\\\\pear;E:
    \\\\\\\\\\\\\\\\other\\\\\\\\\\\\\\\\xampp\\\\\\\\\\\\\\\\php\\\\\\\\\\\\\\\\PEAR') File Path: database/DB.php (line: 41)
    [CIUnit] Error: 500 Message: No database connection settings were found in the d
    atabase config file.

    Then I open the file

    E:\projektai\php projektai\htdocs\ci_u
    nit\application\config\testing\database.php

    to see whats on 41 line, and I see empty file. But it takes 4 KB. So it should not be empty. What is wrong there?

    Edit:
    tired opening it with few other editrods, and when opening with notepad then it shows acces s denied message. So its somehow locked and phpunit also probably cannot open it or something like that. What is going on 😊


    I also tried running cmd as administrator:
    http://www.howtogeek.com/howto/windows-vista/run-a-command-as-administrator-from-the-windows-vista-run-box/

    but still the same..

  • #24 / Oct 22, 2012 12:56pm

    SPeed_FANat1c

    260 posts

    I replaced the database.php in application/config/testing with the file application/config/database.php and it started working.

    E:\projektai\php projektai\htdocs\ci_unit\tests>phpunit
    PHPUnit 3.5.14 by Sebastian Bergmann.
    
    ........
    
    Time: 3 seconds, Memory: 5.75Mb
    
    ←[30;42m←[2KOK (8 tests, 4 assertions)
    ←[0m←[2K
    E:\projektai\php projektai\htdocs\ci_unit\tests>

    So cool, I will be able now experiment with php unit. I hope I will not get those nonsenses anymore with this ciunit 😊

  • #25 / Oct 23, 2012 1:27pm

    SPeed_FANat1c

    260 posts

    Btw, I assume this

    ←[30;42m←[2K

    had to mean color coding for command line. But I am not seeing colors. How to make that it would show colors instead of code on windows cmd?

  • #26 / Oct 27, 2012 3:56am

    SPeed_FANat1c

    260 posts

    Accidentally found maybe an easier way to install PHP unit - its Composer.

    http://net.tutsplus.com/tutorials/php/test-driven-development-in-php-first-steps/

    Composer is “Dependency Manager for PHP”. I did not tried it but watched video, maybe someone will have less headache when installing PEAR 😊

  • #27 / Mar 11, 2013 2:10pm

    jamshed

    1 posts

    The way to truncate the tables in CIUnit is not good.
    Any contributions is welcome. 😊

    Is there way to have “Unit tests do not connect to the database” instead mock out the database layer entirely
    with CIUnit?.

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

ExpressionEngine News!

#eecms, #events, #releases