Skip to content

Commit

Permalink
Merge branch '7.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 6, 2018
2 parents 9754efc + 6d4aa0d commit 12893f8
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/_files/NotSelfDescribingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/*
* 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\Test;
use PHPUnit\Framework\TestResult;

class NotSelfDescribingTest implements Test
{
public function log($msg): void
{
print $msg;
}

public function count(): int
{
return 0;
}

public function run(TestResult $result = null): TestResult
{
return new TestResult();
}
}
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

require_once TEST_FILES_PATH . 'NotPublicTestCase.php';

require_once TEST_FILES_PATH . 'NotSelfDescribingTest.php';

require_once TEST_FILES_PATH . 'NotVoidTestCase.php';

require_once TEST_FILES_PATH . 'OverrideTestCase.php';
Expand Down
101 changes: 101 additions & 0 deletions tests/unit/Framework/TestFailureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/
namespace PHPUnit\Framework;

use PHPUnit\Framework\Error\Error;
use SebastianBergmann\Comparator\ComparisonFailure;

class TestFailureTest extends TestCase
{
public function testToString(): void
Expand All @@ -29,6 +32,15 @@ public function testToStringForError(): void
$this->assertEquals(__METHOD__ . ': message', $failure->toString());
}

public function testToStringForNonSelfDescribing(): void
{
$test = new \NotSelfDescribingTest();
$exception = new Exception('message');
$failure = new TestFailure($test, $exception);

$this->assertEquals('NotSelfDescribingTest: message', $failure->toString());
}

public function testgetExceptionAsString(): void
{
$test = new self(__FUNCTION__);
Expand All @@ -37,4 +49,93 @@ public function testgetExceptionAsString(): void

$this->assertEquals("Error: message\n", $failure->getExceptionAsString());
}

public function testExceptionToString(): void
{
$exception = new AssertionFailedError('message');

$this->assertEquals("message\n", TestFailure::exceptionToString($exception));
}

public function testExceptionToStringForExpectationFailedException(): void
{
$exception = new ExpectationFailedException('message');

$this->assertEquals("message\n", TestFailure::exceptionToString($exception));
}

public function testExceptionToStringForExpectationFailedExceptionWithComparisonFailure(): void
{
$exception = new ExpectationFailedException('message', new ComparisonFailure('expected', 'actual', 'expected', 'actual'));

$this->assertEquals("message\n--- Expected\n+++ Actual\n@@ @@\n-expected\n+actual\n", TestFailure::exceptionToString($exception));
}

public function testExceptionToStringForFrameworkError(): void
{
$exception = new Error('message', 0, 'file', 1);

$this->assertEquals("message\n", TestFailure::exceptionToString($exception));
}

public function testExceptionToStringForExceptionWrapper(): void
{
$exception = new ExceptionWrapper(new \Error('message'));

$this->assertEquals("Error: message\n", TestFailure::exceptionToString($exception));
}

public function testGetTestName(): void
{
$test = new self(__FUNCTION__);
$exception = new Exception('message');
$failure = new TestFailure($test, $exception);

$this->assertEquals($this->toString(), $failure->getTestName());
}

public function testFailedTest(): void
{
$test = new self(__FUNCTION__);
$exception = new Exception('message');
$failure = new TestFailure($test, $exception);

$this->assertEquals($test, $failure->failedTest());
}

public function testThrownException(): void
{
$test = new self(__FUNCTION__);
$exception = new Exception('message');
$failure = new TestFailure($test, $exception);

$this->assertEquals($exception, $failure->thrownException());
}

public function testExceptionMessage(): void
{
$test = new self(__FUNCTION__);
$exception = new Exception('message');
$failure = new TestFailure($test, $exception);

$this->assertEquals('message', $failure->exceptionMessage());
}

public function testIsFailure(): void
{
$test = new self(__FUNCTION__);
$exception = new ExpectationFailedException('message');
$failure = new TestFailure($test, $exception);

$this->assertTrue($failure->isFailure());
}

public function testIsFailureFalse(): void
{
$test = new self(__FUNCTION__);
$exception = new Warning('message');
$failure = new TestFailure($test, $exception);

$this->assertFalse($failure->isFailure());
}
}

0 comments on commit 12893f8

Please sign in to comment.