Skip to content

Commit

Permalink
Clean up. Bit of refactoring and new @testdox annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
epdenouden authored and sebastianbergmann committed Jan 11, 2019
1 parent 35dfa54 commit 5189727
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
30 changes: 30 additions & 0 deletions src/Framework/Assert.php
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
27 changes: 1 addition & 26 deletions src/Framework/TestCase.php
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/Runner/PhptTestCase.php
Expand Up @@ -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,
];
}

Expand All @@ -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++;
Expand Down
1 change: 1 addition & 0 deletions tests/unit/Runner/TestSuiteSorterTest.php
Expand Up @@ -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
Expand Down

0 comments on commit 5189727

Please sign in to comment.