#208 class TestGetClass extends UnitTestCase fails

closed-wont-fix
5
2011-11-30
2011-07-21
John Elliot
No

Using SimpleTest v1.1alpha3. The following error is produced by the following code:

Fatal error: Call to a member function getDumper() on a non-object in ...\simpletest\test_case.php on line 316

<?php

error_reporting( E_ALL );
ini_set( 'display_errors', 'On' );

require_once( dirname( __FILE__ ) . '/../lib/simpletest/autorun.php' );

class TestGetClass extends UnitTestCase {

public function testGetClass() {

$this->assertTrue( true );

}
}

?>

The resolution is to rename the test case from "class TestGetClass" to "class Test_GetClass". I searched the simple test source code for 'GetClass' and found no references, so I'm stumped as to why the class name causes the test to fail like that. I had a TestGetClass unit-test because I was experimenting with uses of the PHP get_class function.

Discussion

  • Perrick Penet

    Perrick Penet - 2011-11-30

    The trouble starts when you call the "testGetClass" function : PHP thinks it's the constructor and SimpleTest thinks it's a test function. From then on everything gets confused ;-)

    Depending on what you really wanted to do you should either do :

    class TestGetClass extends UnitTestCase {
    public function __construct() {
    $this->assertTrue( true );
    }
    }

    or

    class TestGetClass extends UnitTestCase {
    public function test_GetClass() {
    $this->assertTrue( true );
    }
    }

    I hope you'll find this useful.

    Yours,
    Perrick

     
  • Perrick Penet

    Perrick Penet - 2011-11-30
    • labels: --> Unit test framework
    • assigned_to: nobody --> pp11
    • status: open --> closed-wont-fix
     

Log in to post a comment.