Welcome Guest, Not a member yet? Register   Sign In
ci-phpunit-test for CodeIgniter 3.0

Hi, I'm trying to use your this library, it works fine with controllers, I have a problem with model testing.

As instructed in your guide, I extracted your library into application/tests
I tried with my own model test, and then created test for your Category_model, also, the model with a proper method is created, as well as table in database.
Your CategorySeeder successfully inserted data into database.
Category_model_test.php is copy/paste as from example:
PHP Code:
class Category_model_test extends TestCase
    public static function 
$CI =& get_instance();
    public function 
$this->obj $this->CI->Category_model;
    public function 
$expected = [
=> 'Book',
=> 'CD',
=> 'DVD',
$list $this->obj->get_category_list();
        foreach (
$list as $category) {
$this->assertEquals($expected[$category->id], $category->name);

I've got the following error by PHPunit;

Fatal error: Call to a member function query() on null in /var/www/html/lipa2016/application/models/Category_model.php on line 11
/Category_model.php on line 11 is like that:
return $this->db->query("SELECT * FROM category");

Category_model.php is this:

PHP Code:
class Category_model extends CI_Model {
    private $category 
    function __construct
() {
        parent::__construct ();
function get_category_list() {
        return $this->db->query("SELECT * FROM category");
        //$this->db->order_by ( 'name', 'asc' );
        //return $this->db->get ('category');  

If I uncomment query like this:
$this->db->order_by ( 'name', 'asc' );
return $this->db->get ('category');
I've got error from phpunit:

Severity: Error
Message: Call to a member function order_by() on null
Filename: /var/www/html/lipa2016/application/models/Category_model.php
Line Number: 12

PHPUnit version is 5.1.3, PHP version is 5.6.14,
The same error was with PHPUnit 4.8 and php 5.4.

If you need more details about the code, please, let me know.


Messages In This Thread
ci-phpunit-test for CodeIgniter 3.0 - by kenjis - 05-09-2015, 11:33 PM
RE: ci-phpunit-test for CodeIgniter 3.0 - by resolv_25 - 12-30-2015, 01:43 PM

Theme © iAndrew 2016 - Forum software by © MyBB