fmalk / codeigniter-phpunit

Hack to make CodeIgniter work with PHPUnit.
234 stars 61 forks source link

Load in construct of TestCase is useless #41

Closed shelverizr closed 8 years ago

shelverizr commented 8 years ago

If code like this:

<?php
/**
* 栏目测试类
*/
class CategoryTest extends CITestCase
{
    function __construct()
    {
        parent::__construct();
    }

    public function test_get_all_children()
    {
        $this->CI->load->database();
        $this->CI->load->model('category');
        $this->assertEquals($this->CI->db->query("SELECT * FROM typelist WHERE reid='212'")->result(), $this->CI->category->get_all_children('212'));
    }
}

The result

qq 20160402182620

But if code like this:

<?php
/**
* 栏目测试类
*/
class CategoryTest extends CITestCase
{
    function __construct()
    {
        parent::__construct();
        $this->CI->load->database();
        $this->CI->load->model('category');
    }

    public function test_get_all_children()
    {
        $this->assertEquals($this->CI->db->query("SELECT * FROM typelist WHERE reid='212'")->result(), $this->CI->category->get_all_children('212'));
    }
}

The result

qq 20160402182620

feryardiant commented 8 years ago

AFAIK PHPUnit use setUp() & setUpBeforeClass() method to load all of your requirements instead of __construct().

shelverizr commented 8 years ago

Ok, it is my mistake