Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nette/tester
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 24cfefa118bd9447718564157fcc6a27390c9cd6
Choose a base ref
..
head repository: nette/tester
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: eacdb436fc5155cb222fc2a7dc5da288fb29e108
Choose a head ref
Showing with 19 additions and 8 deletions.
  1. +9 −0 src/Framework/TestCase.php
  2. +10 −8 src/Runner/TestHandler.php
9 changes: 9 additions & 0 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
@@ -70,6 +70,15 @@ private function runFromCli(): bool
}


public static function parseOutput(string $output): ?array
{
if (!preg_match('#\[([^[]*)]#', (string) strrchr($output, '['), $m)) {
return null;
}
return $m[1] ? explode(',', $m[1]) : [];
}


/**
* Runs the test method.
* @param array $args test method parameters (dataprovider bypass)
18 changes: 10 additions & 8 deletions src/Runner/TestHandler.php
Original file line number Diff line number Diff line change
@@ -164,15 +164,16 @@ private function initiateTestCase(Test $test, $foo, PhpInterpreter $interpreter)
return $test->withResult($job->getExitCode() === Job::CODE_SKIP ? Test::SKIPPED : Test::FAILED, $job->getTest()->stdout);
}

if (!preg_match('#\[([^[]*)]#', (string) strrchr($job->getTest()->stdout, '['), $m)) {
$methods = TestCase::parseOutput($job->getTest()->stdout);
if ($methods === null) {
return $test->withResult(Test::FAILED, "Cannot list TestCase methods in file '{$test->getFile()}'. Do you call TestCase::run() in it?");
} elseif (!strlen($m[1])) {
} elseif (!$methods) {
return $test->withResult(Test::SKIPPED, "TestCase in file '{$test->getFile()}' does not contain test methods.");
}

return array_map(function (string $method) use ($test): Test {
return $test->withArguments(['method' => $method]);
}, explode(',', $m[1]));
}, $methods);
}


@@ -187,12 +188,13 @@ private function assessExitCode(Job $job, $code): ?Test
return $test->withResult(Test::SKIPPED, trim($message));

} elseif ($job->getExitCode() === Job::CODE_TESTCASE) {
if (!preg_match('#\[([^[]*)]#', (string) strrchr($test->stdout, '['), $m)) {
return $test->withResult(Test::FAILED, "Cannot list TestCase methods in file '{$test->getFile()}'. Do you call TestCase::run() in it?");
} elseif (!strlen($m[1])) {
return $test->withResult(Test::SKIPPED, "TestCase in file '{$test->getFile()}' does not contain test methods.");
$methods = TestCase::parseOutput($test->stdout);
if ($methods === null) {
return $test->withResult(Test::FAILED, "Cannot read TestCaseRunner output in file '{$test->getFile()}'.");
} elseif (!$methods) {
return $test->withResult(Test::SKIPPED, "TestCaseRunner in file '{$test->getFile()}' does not contain any test.");
}
foreach (explode(',', $m[1]) as $method) {
foreach ($methods as $method) {
$testVariety = $test->withArguments(['method' => $method]);
$this->runner->prepareTest($testVariety);
$this->runner->addJob(new Job($testVariety, $this->runner->getInterpreter(), $this->runner->getEnvironmentVariables()));