The Artima Developer Community
Sponsored Link

PHP Buzz Forum
Testing Output with PHPUnit

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Sebastian Bergmann

Posts: 313
Nickname: sbergmann
Registered: Sep, 2004

Sebastian Bergmann is the developer of PHPUnit.
Testing Output with PHPUnit Posted: Mar 3, 2006 1:29 PM
Reply to this message Reply

This post originated from an RSS feed registered with PHP Buzz by Sebastian Bergmann.
Original Post: Testing Output with PHPUnit
Feed Title: Sebastian Bergmann
Feed URL: http://sebastian-bergmann.de/
Feed Description: Geek by nature, PHP by choice.
Latest PHP Buzz Posts
Latest PHP Buzz Posts by Sebastian Bergmann
Latest Posts From Sebastian Bergmann

Advertisement
I just listened to this Pro PHP Podcast interview with Greg Beaver. In his interview, Greg mentions one thing that he thinks is missing from PHPUnit: the ability to test output.

It took me about five minutes to add this functionality to PHPUnit 3.0 and now you can write the following:
<?php
require_once 'PHPUnit2/Extensions/OutputTestCase.php';
 
class OutputTest extends PHPUnit2_Extensions_OutputTestCase
{
    public function testExpectFooActualFoo()
    {
        $this->setExpectedOutput('foo');
        print 'foo';
    }
 
    public function testExpectFooActualBar()
    {
        $this->setExpectedOutput('foo');
        print 'bar';
    }
}
?>
The above test will give the following result:
PHPUnit 3.0.0 by Sebastian Bergmann.

.F

Time: 00:00
There was 1 failure:
1) testExpectFooActualBar(OutputTest)
failed asserting that <'bar'> is equal to <string:'foo'>
expected string <foo>
difference      <xxx>
got string      <bar>

FAILURES!
Tests: 2, Failures: 1.
I hope this is what Greg had in mind ;-)

Read: Testing Output with PHPUnit

Topic: FrOSCon 2006 - Call for Projects Previous Topic   Next Topic Topic: Extreme Simplicity

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use