Skip to content

Commit

Permalink
slight simplifications for testresult and testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
Idrinth authored and sebastianbergmann committed Jul 7, 2018
1 parent 80834b0 commit 7e68764
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 99 deletions.
4 changes: 1 addition & 3 deletions src/Framework/TestResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,7 @@ public function run(Test $test): void
} catch (OriginalCodeCoverageException $cce) {
$error = true;

if (!isset($e)) {
$e = $cce;
}
$e = $e ?? $cce;
}
}

Expand Down
189 changes: 93 additions & 96 deletions src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,131 +141,128 @@ public static function createTest(ReflectionClass $theClass, $name): Test

$constructor = $theClass->getConstructor();

if ($constructor !== null) {
$parameters = $constructor->getParameters();
if ($constructor === null) {
throw new Exception('No valid test provided.');
}
$parameters = $constructor->getParameters();

// TestCase() or TestCase($name)
if (\count($parameters) < 2) {
$test = new $className;
} // TestCase($name, $data)
else {
try {
$data = \PHPUnit\Util\Test::getProvidedData(
$className,
$name
);
} catch (IncompleteTestError $e) {
$message = \sprintf(
'Test for %s::%s marked incomplete by data provider',
$className,
$name
);

// TestCase() or TestCase($name)
if (\count($parameters) < 2) {
$test = new $className;
} // TestCase($name, $data)
else {
try {
$data = \PHPUnit\Util\Test::getProvidedData(
$className,
$name
);
} catch (IncompleteTestError $e) {
$message = \sprintf(
'Test for %s::%s marked incomplete by data provider',
$className,
$name
);
$_message = $e->getMessage();

$_message = $e->getMessage();
if (!empty($_message)) {
$message .= "\n" . $_message;
}

if (!empty($_message)) {
$message .= "\n" . $_message;
}
$data = self::incompleteTest($className, $name, $message);
} catch (SkippedTestError $e) {
$message = \sprintf(
'Test for %s::%s skipped by data provider',
$className,
$name
);

$data = self::incompleteTest($className, $name, $message);
} catch (SkippedTestError $e) {
$message = \sprintf(
'Test for %s::%s skipped by data provider',
$className,
$name
);
$_message = $e->getMessage();

$_message = $e->getMessage();
if (!empty($_message)) {
$message .= "\n" . $_message;
}

if (!empty($_message)) {
$message .= "\n" . $_message;
}
$data = self::skipTest($className, $name, $message);
} catch (Throwable $t) {
$message = \sprintf(
'The data provider specified for %s::%s is invalid.',
$className,
$name
);

$data = self::skipTest($className, $name, $message);
} catch (Throwable $t) {
$message = \sprintf(
'The data provider specified for %s::%s is invalid.',
$className,
$name
);
$_message = $t->getMessage();

$_message = $t->getMessage();
if (!empty($_message)) {
$message .= "\n" . $_message;
}

if (!empty($_message)) {
$message .= "\n" . $_message;
}
$data = self::warning($message);
}

$data = self::warning($message);
}
// Test method with @dataProvider.
if (isset($data)) {
$test = new DataProviderTestSuite(
$className . '::' . $name
);

// Test method with @dataProvider.
if (isset($data)) {
$test = new DataProviderTestSuite(
$className . '::' . $name
if (empty($data)) {
$data = self::warning(
\sprintf(
'No tests found in suite "%s".',
$test->getName()
)
);
}

if (empty($data)) {
$data = self::warning(
\sprintf(
'No tests found in suite "%s".',
$test->getName()
)
);
}

$groups = \PHPUnit\Util\Test::getGroups($className, $name);
$groups = \PHPUnit\Util\Test::getGroups($className, $name);

if ($data instanceof WarningTestCase ||
$data instanceof SkippedTestCase ||
$data instanceof IncompleteTestCase) {
$test->addTest($data, $groups);
} else {
foreach ($data as $_dataName => $_data) {
$_test = new $className($name, $_data, $_dataName);
if ($data instanceof WarningTestCase ||
$data instanceof SkippedTestCase ||
$data instanceof IncompleteTestCase) {
$test->addTest($data, $groups);
} else {
foreach ($data as $_dataName => $_data) {
$_test = new $className($name, $_data, $_dataName);

/* @var TestCase $_test */
/* @var TestCase $_test */

if ($runTestInSeparateProcess) {
$_test->setRunTestInSeparateProcess(true);
if ($runTestInSeparateProcess) {
$_test->setRunTestInSeparateProcess(true);

if ($preserveGlobalState !== null) {
$_test->setPreserveGlobalState($preserveGlobalState);
}
if ($preserveGlobalState !== null) {
$_test->setPreserveGlobalState($preserveGlobalState);
}
}

if ($runClassInSeparateProcess) {
$_test->setRunClassInSeparateProcess(true);

if ($preserveGlobalState !== null) {
$_test->setPreserveGlobalState($preserveGlobalState);
}
}
if ($runClassInSeparateProcess) {
$_test->setRunClassInSeparateProcess(true);

if ($backupSettings['backupGlobals'] !== null) {
$_test->setBackupGlobals(
$backupSettings['backupGlobals']
);
if ($preserveGlobalState !== null) {
$_test->setPreserveGlobalState($preserveGlobalState);
}
}

if ($backupSettings['backupStaticAttributes'] !== null) {
$_test->setBackupStaticAttributes(
$backupSettings['backupStaticAttributes']
);
}
if ($backupSettings['backupGlobals'] !== null) {
$_test->setBackupGlobals(
$backupSettings['backupGlobals']
);
}

$test->addTest($_test, $groups);
if ($backupSettings['backupStaticAttributes'] !== null) {
$_test->setBackupStaticAttributes(
$backupSettings['backupStaticAttributes']
);
}

$test->addTest($_test, $groups);
}
} else {
$test = new $className;
}
} else {
$test = new $className;
}
}

if (!isset($test)) {
throw new Exception('No valid test provided.');
}

if ($test instanceof TestCase) {
$test->setName($name);

Expand Down

0 comments on commit 7e68764

Please sign in to comment.