1

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.

1

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);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.