Question

I want to add some logging to an extension of WP_UnitTestCase.

Like this:

class MZMBO_UnitTestCase extends WP_UnitTestCase
{
    public function el($message){
        file_put_contents('./log_'.date("j.n.Y").'.log', $message, FILE_APPEND);
    }
}

And

include('class-mzmbo-wpunittestcase.php');

class Tests_Session extends MZMBO_UnitTestCase {
    /** some tests **\
    $this->el('some data');
}

Then there's a warning:

1) Warning
No tests found in class "MZMBO_UnitTestCase".

So I add a useless method and the warning goes away.

public function test_nothing() {
    $this->assertEquals( true, true );
}

There must be a better way.

Was it helpful?

Solution

You just need to define the MZMBO_UnitTestCase class as abstract:

abstract class MZMBO_UnitTestCase extends WP_UnitTestCase
{
    public function el($message){
        file_put_contents('./log_'.date("j.n.Y").'.log', $message, FILE_APPEND);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top