Welcome Guest, Not a member yet? Register   Sign In
How to use PHPUnit (CIUnit) with CodeIgniter 2.1.0
#1

[eluser]kenjis[/eluser]
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
#2

[eluser]ShipSailingHome[/eluser]
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:

Code:
controllers  fixtures  generate  generate.php  getops.php  helpers  libs  models  phpunit.xml  system
bob@dev1:~/zbb-dev/zbb/trunk/tests$ phpunit
[CIUnit] PHP Error: Warning - require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory File Path: CIUnit/bootstrap_phpunit.php (line: 259)

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:
Code:
bob@dev1:~/zbb-dev/zbb$ ls
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/zbb$ cd trunk/

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

bob@dev1:~/zbb-dev/zbb/trunk$ ln -s PHPUnit ../PHPUnit-3.4.15/
bob@dev1:~/zbb-dev/zbb/trunk$ cd tests/

bob@dev1:~/zbb-dev/zbb/trunk/tests$ phpunit
[CIUnit] PHP Error: Warning - require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory File Path: CIUnit/bootstrap_phpunit.php (line: 259)

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?
#3

[eluser]ShipSailingHome[/eluser]
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.
#4

[eluser]ShipSailingHome[/eluser]
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!
#5

[eluser]jessejimz[/eluser]
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.

#6

[eluser]kenjis[/eluser]
[quote author="jessejimz" date="1327285111"]
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.
[/quote]

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

[eluser]philpalmieri[/eluser]
Kenji, you rock! this is awesome and works great, thank you.

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

[eluser]rubdottocom[/eluser]
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
Code:
<?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:
Code:
<?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(0, preg_match('/(error|notice)/i', $out));
}
}

When I run phpunit I receive 404 Message because the
Code:
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? :-(
#9

[eluser]kenjis[/eluser]
[quote author="rubdottocom" date="1328701352"]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
Code:
...snip...
  if ( ! file_exists('application/views/pages/'.$page.'.php'))
...snip...

...snip...

When I run phpunit I receive 404 Message because the
Code:
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? :-([/quote]

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'
#10

[eluser]rubdottocom[/eluser]
[quote author="Kenji @ CodeIgniter Users Group in Japan" date="1328702847"][quote author="rubdottocom" date="1328701352"]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
Code:
...snip...
  if ( ! file_exists('application/views/pages/'.$page.'.php'))
...snip...

...snip...

When I run phpunit I receive 404 Message because the
Code:
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? :-([/quote]

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'
[/quote]

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




Theme © iAndrew 2016 - Forum software by © MyBB