fmalk/codeigniter-phpunit

Can CI custom libraries be tested?

jagandecapri opened this issue · 5 comments

I have a custom library, Item.php, written as such:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Item {
        public function dummy()
        {
          return 1;
        }
}

ItemTest.php is as such:

<?php
require('CITestCase.php');

class ItemTest extends CITestCase {

  protected $item;

  public function setUp()
  {
    $this->CI->load->library('item');
  }

  public function testItem()
  {
    $this->assertEquals($this->CI->item->dummy(), 1);
  }
}
/* End of file ItemTest.php */

However, running this test shows error Call to a member function dummy() on a non-objectFilename:

Any help would be greated appreciated. Thanks.

if you install it properly, you shouldn't get any error. I've try it and nothing happen

ciunit - 34

Hi @feryardiant ,

I found the problem, I was loading a controller with same name with my library class.

controllers/Item.php
libraries/Item.php

CI could not have have same name for controller, models and libraries as I found out from this link
http://stackoverflow.com/questions/7156123/why-are-code-igniters-models-controllers-libraries-not-seperated
and by testing myself.

Beginner mistake I think. Anyway thanks. ;)

Anytime dude 😄

Hello,
I have a problem with my library Cockpit and phpunit (which ran well before adding the Library).
"Class 'CI_Cockpit' not found" is the error phpunit produces, right after a class_load() call.
What did I missed?

fmalk commented

@stephane-wis please open another issue, with more information. Which CI version? Where is your CI_Cockpit file located?