From 4fb945b85f74eb1a415ae6661b5bcfccd1f1c34d Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Sun, 15 Jan 2017 12:34:06 +0100 Subject: [PATCH 1/2] [PhpUnitBridge] Assert missing deprecations --- src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php index 339ff3f8d417e..f5c9cca0404df 100644 --- a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php +++ b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php @@ -194,6 +194,10 @@ public function endTest(\PHPUnit_Framework_Test $test, $time) try { $prefix = "@expectedDeprecation:\n"; $test->assertStringMatchesFormat($prefix.'%A '.implode("\n%A ", $this->expectedDeprecations)."\n%A", $prefix.' '.implode("\n ", $this->gatheredDeprecations)."\n"); + + if ($missing = array_diff($this->gatheredDeprecations, $this->expectedDeprecations)) { + $test->assertStringMatchesFormat($prefix.'%A '.implode("\n%A ", $missing)."\n%A", $prefix.' '.implode("\n ", array())."\n"); + } } catch (\PHPUnit_Framework_AssertionFailedError $e) { $test->getTestResultObject()->addFailure($test, $e, $time); } From e24d9134de8ff9826e5bfa957b6191d12909c6e3 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Sun, 15 Jan 2017 13:40:10 +0100 Subject: [PATCH 2/2] different approach --- .../Bridge/PhpUnit/SymfonyTestsListener.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php index f5c9cca0404df..df2de43cf1163 100644 --- a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php +++ b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php @@ -12,6 +12,7 @@ namespace Symfony\Bridge\PhpUnit; use Doctrine\Common\Annotations\AnnotationRegistry; +use SebastianBergmann\Diff\Differ; /** * Collects and replays skipped tests. @@ -191,15 +192,11 @@ public function endTest(\PHPUnit_Framework_Test $test, $time) restore_error_handler(); if (!in_array($test->getStatus(), array(\PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, \PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE, \PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE, \PHPUnit_Runner_BaseTestRunner::STATUS_ERROR), true)) { - try { - $prefix = "@expectedDeprecation:\n"; - $test->assertStringMatchesFormat($prefix.'%A '.implode("\n%A ", $this->expectedDeprecations)."\n%A", $prefix.' '.implode("\n ", $this->gatheredDeprecations)."\n"); - - if ($missing = array_diff($this->gatheredDeprecations, $this->expectedDeprecations)) { - $test->assertStringMatchesFormat($prefix.'%A '.implode("\n%A ", $missing)."\n%A", $prefix.' '.implode("\n ", array())."\n"); - } - } catch (\PHPUnit_Framework_AssertionFailedError $e) { - $test->getTestResultObject()->addFailure($test, $e, $time); + if ($this->gatheredDeprecations !== $this->expectedDeprecations) { + $differ = new Differ("--- Expected\n+++ Actual\n"); + $test->getTestResultObject()->addFailure($test, new \PHPUnit_Framework_AssertionFailedError( + "Failed asserting expected deprecations.\n\n".$differ->diff(implode("\n", $this->gatheredDeprecations), implode("\n", $this->expectedDeprecations)) + ), $time); } }