EllisLab text mark
Advanced Search
1 of 2
1
   
How to use PHPUnit (CIUnit) with CodeIgniter 2.1.0
Posted: 13 February 2012 01:20 PM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2012-02-08
3 posts

Hi!

I have another (probably) newbie question ^^

I’m trying to test models with a test database using fixtures, but I have tables with Foreign Keys and I receive errors about I can’t truncate tables referenced in a foreign key

I read about it and it seems a standard restriction, I could delete all rows but I can’t truncate a table with FK’s unless I disable the FK first.

Any advice? :(

 
Posted: 08 March 2012 10:26 PM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2007-12-02
134 posts

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

 
Posted: 05 May 2012 09:48 PM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Joined: 2012-03-13
3 posts
PHP Warning:  require_once(PHP/CodeCoverage/Autoload.php): failed to open streamNo such file or directory in /usr/lib/php/PHPUnit/Autoload.php on line 46
PHP Fatal error
:  require_once(): Failed opening required 'PHP/CodeCoverage/Autoload.php' (include_path='.:'in /usr/lib/php/PHPUnit/Autoload.php on line 46 

I keep getting this error. Does anyone know how to fix it? It happens when i run phpunit

 

 
Posted: 25 May 2012 09:25 AM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Joined: 2012-05-25
16 posts
public function testRepeat()
    
{
        $yell 
"Hello, any one out there?";
        
$returned $this->CI->repeat($yell);
        
$this->assertEquals($returned$yell);
    

..PHP Fatal error:  Call to undefined method Welcome::repeat() in /opt/bitnami/frameworks/codeigniter/tests/controllers/WelcomeControllerTest.php on line 20

 

 
Posted: 03 September 2012 01:56 PM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Joined: 2012-05-28
2 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.

 
Posted: 30 September 2012 05:27 AM   [ Ignore ]   [ # 16 ]   [ Rating: 0 ]
Joined: 2010-03-19
329 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?

 
Posted: 06 October 2012 08:45 AM   [ Ignore ]   [ # 17 ]   [ Rating: 0 ]
Joined: 2009-04-15
454 posts

There is an unofficial composer package:

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

I agree - PEAR on Windows is not any fun

 Signature 

Code By Jeff

Mahana Messaging Library

Problem with your query? Did you run

$this->db->last_query(); 

before you came to the forums for help?

 
Posted: 11 October 2012 12:11 PM   [ Ignore ]   [ # 18 ]   [ Rating: 0 ]
Joined: 2010-03-19
329 posts

@jmadsen - thanks, somehow next day I tried again and upgrading pear worked smile 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.

 
Posted: 12 October 2012 12:47 AM   [ Ignore ]   [ # 19 ]   [ Rating: 0 ]
Joined: 2009-04-15
454 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

 Signature 

Code By Jeff

Mahana Messaging Library

Problem with your query? Did you run

$this->db->last_query(); 

before you came to the forums for help?

 
Posted: 14 October 2012 03:54 AM   [ Ignore ]   [ # 20 ]   [ Rating: 0 ]
Joined: 2010-03-19
329 posts

thanks smile

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 smile

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.

 
Posted: 17 October 2012 12:07 PM   [ Ignore ]   [ # 21 ]   [ Rating: 0 ]
Joined: 2010-03-19
329 posts

Hello again,

I still have problems with running the first test smile

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.

 
Posted: 20 October 2012 03:37 AM   [ Ignore ]   [ # 22 ]   [ Rating: 0 ]
Joined: 2010-03-19
329 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 ErrorWarning - include(E:\projektai\php projektai\htdocs\ci_u
nit\application\config\testing\database
.php): failed to open streamPermission
denied File Path
database/DB.php (line41)
[CIUnit] PHP ErrorWarning - 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 Pathdatabase/DB.php (line41)
[CIUnit] Error500 MessageNo 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 smile


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..

 
Posted: 22 October 2012 12:56 PM   [ Ignore ]   [ # 23 ]   [ Rating: 0 ]
Joined: 2010-03-19
329 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
.

........

Time3 secondsMemory5.75Mb

←[30
;42m←[2KOK (8 tests4 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 smile

 
Posted: 23 October 2012 01:27 PM   [ Ignore ]   [ # 24 ]   [ Rating: 0 ]
Joined: 2010-03-19
329 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?

 
Posted: 27 October 2012 03:56 AM   [ Ignore ]   [ # 25 ]   [ Rating: 0 ]
Joined: 2010-03-19
329 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 smile

 
1 of 2
1