0

I'm stuck with an OO issue. I have a simple Unit Test class with which I can do some assertions. For exmaple, my code could look like this:

class TestSomething extends UnitTestCase
{
    public function someTest() { ... }
}

An important thing is obviously to log the results of the test to some place. That could be a web page, or just a file or maybe a database.

Currently I need to log to both a file and disply the results in a web browser. But I want to keep my code as extensible as possible. It should be easy to add another type of "logging" mechanism.

So currently my UnitTestCase class looks like this:

class UnitTestCase
{
    protected function printHeader ( $testResults )
    {
    }

    protected function printResults ( $testResults )
    {
    }

    protected function printFooter ( $testResults )
    {
    }

    public function assertSomething() {...}
    // ... And alot of other assertions
}

Currently I am not logging anything, because I'm not sure how to continue. What would be a good way to implement different types of logging mechanisms in the UnitTestCase class and keep the code clean and OO?

Vivendi
  • 20,047
  • 25
  • 121
  • 196
  • You might find [this](http://stackoverflow.com/a/18682856/727208) relevant (though I am not use if you can consider that topic to be a duplicate of yours). – tereško Nov 08 '13 at 11:28
  • Have a look at monolog https://github.com/Seldaek/monolog – busypeoples Nov 10 '13 at 00:10

0 Answers0