Skip to content

Commit

Permalink
Enhancement: Add tests for TestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz authored and sebastianbergmann committed Apr 29, 2019
1 parent b2f6b82 commit dcdbda6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/_files/TestWithDifferentOutput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;

final class TestWithDifferentOutput extends TestCase
{
public function testThatDoesNotGenerateOutput(): void
{
$this->assertTrue(true);
}

public function testThatExpectsOutputRegex(): void
{
$this->expectOutputRegex('.*');

print 'Hello!';
}

public function testThatExpectsOutputString(): void
{
$this->expectOutputString('Hello!');

print 'Hello!';
}

public function testThatGeneratesOutput(): void
{
print 'Hello!';

$this->assertTrue(true);
}
}
36 changes: 36 additions & 0 deletions tests/unit/Framework/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,42 @@ public function testHasFailedReturnsFalseWhenTestHasEmittedWarning(): void
$this->assertFalse($test->hasFailed());
}

public function testHasOutputReturnsFalseWhenTestDoesNotGenerateOutput(): void
{
$test = new \TestWithDifferentOutput('testThatDoesNotGenerateOutput');

$test->run();

$this->assertFalse($test->hasOutput());
}

public function testHasOutputReturnsFalseWhenTestExpectsOutputRegex(): void
{
$test = new \TestWithDifferentOutput('testThatExpectsOutputRegex');

$test->run();

$this->assertFalse($test->hasOutput());
}

public function testHasOutputReturnsFalseWhenTestExpectsOutputString(): void
{
$test = new \TestWithDifferentOutput('testThatExpectsOutputString');

$test->run();

$this->assertFalse($test->hasOutput());
}

public function testHasOutputReturnsTrueWhenTestGeneratesOutput(): void
{
$test = new \TestWithDifferentOutput('testThatGeneratesOutput');

$test->run();

$this->assertTrue($test->hasOutput());
}

/**
* @return array<string, array>
*/
Expand Down

0 comments on commit dcdbda6

Please sign in to comment.