Table_test.php unit test fatal error #1148

Closed
tiyowan opened this Issue Mar 8, 2012 · 3 comments

Comments

Projects
None yet
2 participants
Contributor

tiyowan commented Mar 8, 2012

When running the unit tests from feature/unit-tests:

Fatal error: Call to protected method CI_Table::_prep_args() from context 'Table
_test' in C:\home\hamza\code\CodeIgniter\tests\codeigniter\libraries\Table_test.
php on line 111

Contributor

tiyowan commented Mar 8, 2012

It seems this problem is sprinkled all over this test class. In any case, this isn't the proper way to unit test protected/private methods. These tests need to be reworked.

Contributor

tiyowan commented Mar 9, 2012

This works:

public function test_prep_args()
    {
        $expected = array(
            array('data' => 'name'),
            array('data' => 'color'),
            array('data' => 'size')
        );

        // test what would be discreet args,
        // basically means a single array as the calling method
        // will use func_get_args()


        $reflectionOfTable = new ReflectionClass($this->table);
        $method = $reflectionOfTable->getMethod('_prep_args');

        $method->setAccessible(true);

        $this->assertEquals(
            $expected,
            $method->invokeArgs(
                $this->table, array(array('name', 'color', 'size'), 'discreet')
            )
        );  
    }

@tiyowan tiyowan added a commit to tiyowan/CodeIgniter that referenced this issue Mar 9, 2012

@tiyowan tiyowan Fix issue #1148
Rewrote tests to use reflection to access protected/private
functions of Table class. This fixes fatal errors that
prevent the test suite from executing other tests.

Signed-off-by: tiyowan <tiyowan@gmail.com>
e39728c
Contributor

philsturgeon commented Mar 9, 2012

Thanks for fixing this yourself :)

In the future don't report broken tests, just send the fix in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment