EllisLab text mark
Advanced Search
1 of 2
1
   
How to use PHPUnit (CIUnit) with CodeIgniter 2.1.0
Posted: 16 January 2012 09:38 PM   [ Ignore ]
Avatar
Joined: 2007-12-02
134 posts

I wrote a tutorial about how to install and use PHPUnit/CIUnit with CodeIgniter 2.1.0.

http://d.hatena.ne.jp/Kenji_s/20120117/1326763908

 
Posted: 17 January 2012 09:06 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-12-02
134 posts

I added:

Database Testing of CodeIgniter Application with PHPUnit (CIUnit)
http://d.hatena.ne.jp/Kenji_s/20120118/1326848578

 
Posted: 18 January 2012 11:51 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-01-18
3 posts

Kenji,

I’m pretty new to PHPUnit. I’ve followed the instructions at this URL http://d.hatena.ne.jp/Kenji_s/20120117/1326763908—and I’m getting an error.

I didn’t download a fresh copy of CodeIgniter, like in your tutorial, because I already have my project built.

I’m hoping you can advise me. I keep getting this error:

controllers  fixtures  generate  generate.php  getops.php  helpers  libs  models  phpunit.xml  system
bob
@dev1:~/zbb-dev/zbb/trunk/testsphpunit
[CIUnit] PHP Error
Warning - require_once(PHPUnit/Autoload.php): failed to open streamNo such file or directory File PathCIUnit/bootstrap_phpunit.php (line259)

Fatal error: require_once(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.:/usr/share/php:/usr/share/pear'in /home/bob/zbb-dev/zbb/trunk/application/third_party/CIUnit/bootstrap_phpunit.php on line 259
bob
@dev1:~/zbb-dev/zbb/trunk/tests

Thinking I had the PHPUnit files in the wrong place, I made a symlink in my CI web root:

bob@dev1:~/zbb-dev/zbbls
dbunit
.bat  dbunit.php  default.zip  kenjis-my-ciunit-27a0665997a8  PHPUnit-3.4.15  phpunit.bat  phpunit.php  PHPUnit.tar  test  trunk

bob
@dev1:~/zbb-dev/zbbcd trunk/

bob@dev1:~/zbb-dev/zbb/trunkls
application  css  default_schema
.sql  downloads  images  index.php  js  license.txt  system  tests

bob
@dev1:~/zbb-dev/zbb/trunkln -s PHPUnit ../PHPUnit-3.4.15/
bob@dev1:~/zbb-dev/zbb/trunkcd tests/

bob@dev1:~/zbb-dev/zbb/trunk/testsphpunit
[CIUnit] PHP Error
Warning - require_once(PHPUnit/Autoload.php): failed to open streamNo such file or directory File PathCIUnit/bootstrap_phpunit.php (line259)

Fatal error: require_once(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.:/usr/share/php:/usr/share/pear'in /home/bob/zbb-dev/zbb/trunk/application/third_party/CIUnit/bootstrap_phpunit.php on line 259
bob
@dev1:~/zbb-dev/zbb/trunk/tests

But I’m still having the same problem.

Maybe my PHPUnit install is just bad?

 
Posted: 18 January 2012 12:12 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2012-01-18
3 posts

It looks like I’m using an older version of PHPUnit that doesn’t include Autoload.php . It has Framework.php instead.

That’s disappointing because the newer version of PHPUnit requires a newer version of PHP—and, I can’t upgrade PHP on this server.

 
Posted: 18 January 2012 01:04 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2012-01-18
3 posts

I couldn’t upgrade to a newer version of PHP on that server, but I got access to a server that I could upgrade PHP on smile

I got it working! Woohoo!

 
Posted: 22 January 2012 10:18 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2011-09-02
6 posts

Hey, Keinji—I think I know your cousin in MX (Kenji S.).

In any event, I’m on a Mac OS X + XAMPP + Eclipse Helios + CodeIgniter v2.0.3.

I got everything running well via command terminal and really digg CIUnit. I’m so happy you spent valuable time creating this.

Man, I cannot tell you how many hours I have spent tryting to get Makegood plugin for Eclipse working with CIUnit on my Mac. I keep getting this “CIUnit_TestCase_Selenium class is not available. Fix…” error that I can’t get rid of.

My checklist of things I ensured:
* I Have PHP 5.3.x installed
* I have latest PHPUnit 3.7 installed via PEAR
* I have PHPUnit Selenium installed via PEAR
* I have the PEAR path in my Eclipse project’s include path (PEAR is up to date)
* Installed latest Makegood plugin for Eclipse (works fine with PHPunit)
* I properly set up Makegood settings for CIUnit
* My environment variables are set in my .profile and have the XAMPP bins there (it’s why I can actually run CIUnit from command line)

Have you gotten any reports about this pesky problem with Makegood? I know it has to do with dependency resolution by Makegood/Eclipse. Any help much appreciated.

 
Posted: 22 January 2012 11:07 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2007-12-02
134 posts
jessejimz - 22 January 2012 10:18 PM

Man, I cannot tell you how many hours I have spent tryting to get Makegood plugin for Eclipse working with CIUnit on my Mac. I keep getting this “CIUnit_TestCase_Selenium class is not available. Fix…” error that I can’t get rid of.

My checklist of things I ensured:
* I Have PHP 5.3.x installed
* I have latest PHPUnit 3.7 installed via PEAR
* I have PHPUnit Selenium installed via PEAR
* I have the PEAR path in my Eclipse project’s include path (PEAR is up to date)
* Installed latest Makegood plugin for Eclipse (works fine with PHPunit)
* I properly set up Makegood settings for CIUnit
* My environment variables are set in my .profile and have the XAMPP bins there (it’s why I can actually run CIUnit from command line)

Have you gotten any reports about this pesky problem with Makegood? I know it has to do with dependency resolution by Makegood/Eclipse. Any help much appreciated.

Your checks seem to be good.

But, what is “CIUnit_TestCase_Selenium class” ?
I think there is no such class.

I have not installed PHPUnit Selenium, but MakeGood works fine.

 

 
Posted: 23 January 2012 08:06 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2007-04-13
43 posts

Kenji, you rock! this is awesome and works great, thank you.

I added a webtest folder, and selenium and it works perfectly

 Signature 

twitter
philpalmieri.com

 
Posted: 08 February 2012 07:42 AM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Joined: 2012-02-08
3 posts

Hi!

Whoah Kenji, thanks for the amazing work!

I’m close to make it work, I have a problem with a simple test of a controller

This is my controller

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class 
Home extends MY_Controller {
 
    
function __construct()
    
{
        parent
::__construct();
  
$this->load->helper('json'); 
    
}
 
public function view($page 'home')
 
{
  log_message
('debug''Page: '$page);
  if ( ! 
file_exists('application/views/pages/'.$page.'.php'))
  
{   
   show_404
(); // Whoops, we don't have a page for that!
  
}
  
  $data[
'sections'$this->get_sections_master();
  
  
$this->load->view('templates/header'$data);
  
$this->load->view('templates/sidebar'$data);
  
$this->load->view('pages/'.$page$data);
  
$this->load->view('templates/footer'$data);
   
 
}
... Other stuff 

And this my test:

<?php

/**
 * @group Controller
 */

class SomeControllerTest extends CIUnit_TestCase
{
 
public function setUp()
 
{
  
// Set the tested controller
  
$this->CI set_controller('Home');
 
}
 
 
public function testWelcomeController()
 
{
  
// Call the controllers method
  //$this->CI->index();
  
$this->CI->view('home');
  
  
// Fetch the buffered output
  
$out output();
  
  
// Check if the content is OK
  
$this->assertSame(0preg_match('/(error|notice)/i'$out));
 
}

When I run phpunit I receive 404 Message because the

if ( ! file_exists('application/views/pages/'.$page.'.php')) 

But the file exists and if I try to open in a browser works fine, I miss something? :-(

 
Posted: 08 February 2012 08:07 AM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2007-12-02
134 posts
rubdottocom - 08 February 2012 07:42 AM

Hi!

Whoah Kenji, thanks for the amazing work!

I’m close to make it work, I have a problem with a simple test of a controller

This is my controller

...snip...
  if ( ! 
file_exists('application/views/pages/'.$page.'.php'))
...
snip... 

...snip…

When I run phpunit I receive 404 Message because the

if ( ! file_exists('application/views/pages/'.$page.'.php')) 

But the file exists and if I try to open in a browser works fine, I miss something? :-(

Probably because you are pointing your view file as relative path.
Please change the path as absolute path.

For example:
APPPATH.‘views/pages/’.$page.’.php’

 

 
Posted: 08 February 2012 09:13 AM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Joined: 2012-02-08
3 posts
Kenji @ CodeIgniter Users Group in Japan - 08 February 2012 08:07 AM
rubdottocom - 08 February 2012 07:42 AM

Hi!

Whoah Kenji, thanks for the amazing work!

I’m close to make it work, I have a problem with a simple test of a controller

This is my controller

...snip...
  if ( ! 
file_exists('application/views/pages/'.$page.'.php'))
...
snip... 

...snip…

When I run phpunit I receive 404 Message because the

if ( ! file_exists('application/views/pages/'.$page.'.php')) 

But the file exists and if I try to open in a browser works fine, I miss something? :-(

Probably because you are pointing your view file as relative path.
Please change the path as absolute path.

For example:
APPPATH.‘views/pages/’.$page.’.php’

Works perfect :- ) I’m pretty newbie with CI and php ^^u

 
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.

 
1 of 2
1