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

(10-19-2015, 05:03 AM)iamthwee Wrote: Sorry it was supposed to be ka-e-n-gi  = kenjis but to be honest I'm not sure how names translate using hirigana Big Grin

Anyway on topic, look forward to the release, did you guys decide on the cover?

My real name is Kenji = ke-n-ji.

We did not decide the cover yet. We are still looking for a good photo for the book.
Reply
#42

v0.9.0 was released.
https://github.com/kenjis/ci-phpunit-test/releases

* `$this->request->addCallable()` to add callable.
* Autoloading classes in `application/modules` folder.
* You can configure search paths for autoloader.
Reply
#43

I'm planning to merge the PR: https://github.com/kenjis/ci-phpunit-test/pull/74

It changes $this->getDouble() method.

If you have any trouble with your existing test cases when you apply the patch,
please let me know.
Reply
#44

(11-19-2015, 06:15 PM)kenjis Wrote: I'm planning to merge the PR: https://github.com/kenjis/ci-phpunit-test/pull/74

It changes $this->getDouble() method.

If you have any trouble with your existing test cases when you apply the patch,
please let me know.

The PR initially only contains the change of $this->getDouble().
But after all, I got to the conclusion that the reset_instance() implementation was wrong.
So I added the fix.

I've just merged the PR, so now [email protected]dev (dev-master) includes BC break changes.

See https://github.com/kenjis/ci-phpunit-tes...md#changed
for details.
Reply
#45

I've just released v0.10.0: https://github.com/kenjis/ci-phpunit-test/releases

This includes BC break according to bug fix.

* Now reset_instance() removes the existing CodeIgniter instance.
* Now $this->getDouble() does not call the original constructor by default.

The changes may break your test code. If so, please fix or update your tests.
Reply
#46

Here is the current specification of ci-phpunit-test for CodeIgniter Hooks:
https://github.com/kenjis/ci-phpunit-tes...s.md#hooks

If anyone has any opinion about it, please post to https://github.com/kenjis/ci-phpunit-test/issues/20

I think the current specification is good enough. So I'm planning to close the issue.
Reply
#47

Hi guys!

Today ci-phpunit-test got 90 stars on GitHub.
If you like it and don't mind, please star it on https://github.com/kenjis/ci-phpunit-test

[Image: attachment.php?aid=435]

Attached Files Thumbnail(s)
   
Reply
#48

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 
setUpBeforeClass()
    {
        
parent::setUpBeforeClass();
        
        
$CI =& get_instance();
        
$CI->load->library('Seeder');
        
$CI->seeder->call('CategorySeeder');
    }
    public function 
setUp()
    {
        
$this->resetInstance();
        
$this->CI->load->model('Category_model');
        
$this->obj $this->CI->Category_model;
    }
    public function 
test_get_category_list()
    {
        
$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;

Code:
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:
<?php
class Category_model extends CI_Model {
    
    private $category 
'category';
    
    function __construct
() {
        parent::__construct ();
    }
    
    public 
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:

Code:
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.

Regards,
Reply
#49

(This post was last modified: 12-30-2015, 07:27 PM by kenjis. Edit Reason: Fix filename )

@resolv_25

Tests run on `testing` environment.
https://github.com/kenjis/ci-phpunit-tes...nvironment

Did you setup database.php for testing environment correctly?
Reply
#50

I've just released v0.10.1: https://github.com/kenjis/ci-phpunit-test/releases

It includes only small bug fixes.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB