Page 1 of 2

Getting some HTML out of PHPUnit

Posted: Mon Sep 04, 2006 9:04 am
by Ollie Saunders
I've written this

Code: Select all

require_once 'PHPUnit/Framework/TestCase.php';

class TestOfStuff extends PHPUnit_Framework_TestCase 
{
    public function testSucess()
    {
        $this->assertEqual(1 + 2, 3);
        $this->assertTrue(true);
        $this->assertFalse(false);
        $this->assertNull(null);
    }
    public function testFailure()
    {
        $this->assertEqual(1 + 2, 4);
        $this->assertTrue(false);
        $this->assertFalse(true);
        $this->assertNull(1);
    }
    public function testFail()
    {
        $this->fail('Doh!');
    }
    public function testPass()
    {
        $this->pass();
    }
    public function testSkip()
    {
        $this->markTestSkipped('Skippy');
    }
    public function testIncomplete()
    {
        $this->markTestIncomplete('Incompletely Convincing');
    }
}

$test = new TestOfStuff();
$result = new PHPUnit_Framework_TestResult();
$test->run($result);
And despite reading virtually everything in the almost entirely irrelevent, PHPUnit Pocket Guide I've still no idea how I actually run this test and get HTML output. Is there no HtmlReporter in PHPUnit?

This is what that code produces:

Code: Select all

Warning: Missing argument 2 for PHPUnit_Framework_Error::__construct(), called in /osis/lib/code/php/PHPUnit/Framework/TestCase.php on line 284 and defined in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 79

Warning: Missing argument 3 for PHPUnit_Framework_Error::__construct(), called in /osis/lib/code/php/PHPUnit/Framework/TestCase.php on line 284 and defined in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 79

Warning: Missing argument 4 for PHPUnit_Framework_Error::__construct(), called in /osis/lib/code/php/PHPUnit/Framework/TestCase.php on line 284 and defined in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 79

Warning: Missing argument 5 for PHPUnit_Framework_Error::__construct(), called in /osis/lib/code/php/PHPUnit/Framework/TestCase.php on line 284 and defined in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 79

Notice: Undefined variable: code in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 81

Notice: Undefined variable: file in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 83

Notice: Undefined variable: line in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 84

Notice: Undefined variable: trace in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 85

Posted: Mon Sep 04, 2006 9:12 am
by Ambush Commander

Posted: Mon Sep 04, 2006 9:27 am
by Ollie Saunders
Yeah I saw that which is why I'm confused.
How do you get that?!

Posted: Mon Sep 04, 2006 9:29 am
by Ambush Commander
Try

Code: Select all

$result = PHPUnit_Framework_PrettyTestResult()
:?:

Posted: Mon Sep 04, 2006 9:31 am
by Ollie Saunders
Tried that already. In fact the word "pretty" doesn't exist in the entire library.

Posted: Mon Sep 04, 2006 9:33 am
by Ambush Commander
Well, you could always write your own. And make it look like SimpleTest's...

That's quite puzzling. Maybe it's in the SVN.

Posted: Mon Sep 04, 2006 9:42 am
by Ollie Saunders
I wouldn't mind writing my own actually but this:

Code: Select all

$test = new TestOfStuff();
$result = new PHPUnit_Framework_TestResult();
$test->run($result);
Shouldn't be triggering loads of errors should it?

I'm supposed to be able to get data of that $result object:
PHPUnit Pocket Guide wrote:void addError(PHPUnit_Framework_Test $test, Exception $e) Record that running $test caused $e to be thrown unexpectedly.
void addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e) Record that running $test caused $e to be thrown unexpectedly.
PHPUnit_Framework_TestFailure[] errors() Return the errors recorded.
PHPUnit_Framework_TestFailure[] failures() Return the failures recorded.
PHPUnit_Framework_TestFailure[] notImplemented() Return the incomplete test cases recorded.
int errorCount() Return the number of errors.
int failureCount() Return the number of failures.
int notImplementedCount() Return the number of incomplete test cases.
int count() Return the total number of test cases run.
Boolean wasSuccessfull() Return whether or not all tests ran successfully.
Boolean allCompletlyImplemented() Return whether or not all tests were completely implemented.
void collectCodeCoverageInformation(Boolean $flag) Enables or disables the collection of Code Coverage information.
Array getCodeCoverageInformation() Return the code coverage information collected.
Is that right?

Posted: Mon Sep 04, 2006 9:48 am
by Ambush Commander
Maybe it ought to be

Code: Select all

$result->run($test)

Posted: Mon Sep 04, 2006 9:53 am
by Ollie Saunders
Exactly the same errors :D
Dw if you don't know look like i'm going to have to find a forum where people are clued up on PHPUnit.

Posted: Mon Sep 04, 2006 9:58 am
by Ambush Commander
Yeah, I think that would be a good course of action.

Posted: Mon Sep 04, 2006 9:58 am
by feyd
Considering most of us appear to prefer SimpleTest around here.. that may not be a horrible idea, although it would be nice to have a few people versed in PHPUnit around for balance's sake.

Posted: Mon Sep 04, 2006 12:29 pm
by Ollie Saunders
Just realised I had downloaded the PHPUnit 3 alpha.
I'm now on stable 2.3.6 this may have had something to do with the problems.

Posted: Mon Sep 04, 2006 6:30 pm
by Ollie Saunders
Nope.
Bah PHPUnit is t3h sux.

Shame most of what I read about it sounded really cool, the PHP 5 support and all. No HTML Reporter == No point. If I knew my way about it I would probably write one myself but I don't and thus I can't justify the time it would take.

Posted: Wed Sep 06, 2006 6:26 pm
by Ollie Saunders
Its coming!

Image
Image

I can't wait until this is ready.
Extracted from this post.

Posted: Wed Sep 06, 2006 8:10 pm
by alex.barylski
So what was causing the problems? Was it the CLI issue?

I want to start playing around with as well...need to hear more about your trials and errors, so I don't repeat what has already been done... :)