From 5189727a770c43da67da1605ee95665fecf2400c Mon Sep 17 00:00:00 2001 From: Ewout Pieter den Ouden Date: Thu, 10 Jan 2019 16:06:36 +0100 Subject: [PATCH] Clean up. Bit of refactoring and new @testdox annotations --- src/Framework/Assert.php | 30 +++++++++++++++++++++++ src/Framework/TestCase.php | 27 +------------------- src/Runner/PhptTestCase.php | 8 +++--- tests/unit/Runner/TestSuiteSorterTest.php | 1 + 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/Framework/Assert.php b/src/Framework/Assert.php index 453abd9bbdc..4b08f1161e8 100644 --- a/src/Framework/Assert.php +++ b/src/Framework/Assert.php @@ -3000,6 +3000,12 @@ public static function markTestIncomplete(string $message = ''): void */ public static function markTestSkipped(string $message = ''): void { + if ($hint = self::detectLocationHint($message)) { + $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS); + + throw new SyntheticSkippedError($hint['message'], 0, $hint['file'], $hint['line'], $trace); + } + throw new SkippedTestError($message); } @@ -3019,6 +3025,30 @@ public static function resetCount(): void self::$count = 0; } + private static function detectLocationHint(string $message): ?array + { + $hint = null; + $lines = \preg_split('/\r\n|\r|\n/', $message); + + while (\strpos($lines[0], '__OFFSET') !== false) { + $offset = \explode('=', \array_shift($lines)); + + if ($offset[0] === '__OFFSET_FILE') { + $hint['file'] = $offset[1]; + } + + if ($offset[0] === '__OFFSET_LINE') { + $hint['line'] = $offset[1]; + } + } + + if ($hint) { + $hint['message'] = \implode(\PHP_EOL, $lines); + } + + return $hint; + } + private static function isValidAttributeName(string $attributeName): bool { return \preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $attributeName); diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index 3e8c4d29b69..f70f658a354 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -1644,35 +1644,10 @@ private function checkRequirements(): void ); if (!empty($missingRequirements)) { - $this->markTestSkippedWithLocationHint($missingRequirements); + $this->markTestSkipped(\implode(\PHP_EOL, $missingRequirements)); } } - private function markTestSkippedWithLocationHint(array $required): void - { - $file = null; - $line = null; - - while (\strpos($required[0], '__OFFSET') !== false) { - $offset = \explode('=', \array_shift($required)); - - if ($offset[0] === '__OFFSET_FILE') { - $file = $offset[1]; - } - - if ($offset[0] === '__OFFSET_LINE') { - $line = $offset[1]; - } - } - - if ($file && $line) { - $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS); - - throw new SyntheticSkippedError(\implode(\PHP_EOL, $required), 0, $file, $line, $trace); - } - $this->markTestSkipped(\implode(\PHP_EOL, $required)); - } - private function verifyMockObjects(): void { foreach ($this->mockObjects as $mockObject) { diff --git a/src/Runner/PhptTestCase.php b/src/Runner/PhptTestCase.php index 2b254da2c79..5341c677178 100644 --- a/src/Runner/PhptTestCase.php +++ b/src/Runner/PhptTestCase.php @@ -647,8 +647,8 @@ private function getLocationHint(string $needle, array $sections, ?string $secti $file = \trim($sections[$section . '_EXTERNAL']); return [ - 'file' => \realpath(\dirname($this->filename) . \DIRECTORY_SEPARATOR . $file), - 'line' => 1, + 'file' => \realpath(\dirname($this->filename) . \DIRECTORY_SEPARATOR . $file), + 'line' => 1, ]; } @@ -660,8 +660,8 @@ private function getLocationHint(string $needle, array $sections, ?string $secti foreach ($lines as $line) { if (\strpos($line, $needle) !== false) { return [ - 'file' => \realpath($this->filename), - 'line' => $offset, + 'file' => \realpath($this->filename), + 'line' => $offset, ]; } $offset++; diff --git a/tests/unit/Runner/TestSuiteSorterTest.php b/tests/unit/Runner/TestSuiteSorterTest.php index 9f2114477b2..355dd729834 100644 --- a/tests/unit/Runner/TestSuiteSorterTest.php +++ b/tests/unit/Runner/TestSuiteSorterTest.php @@ -56,6 +56,7 @@ public function testThrowsExceptionWhenUsingInvalidOrderDefectsOption(): void } /** + * @testdox Empty TestSuite not affected (order=$order, resolve=$resolveDependencies, defects=$orderDefects) * @dataProvider suiteSorterOptionPermutationsProvider */ public function testShouldNotAffectEmptyTestSuite(int $order, bool $resolveDependencies, int $orderDefects): void