FIX SapphireTest can load relative fixtures in subfolders, switch "needs db" priority check order

A minute performance gain by checking instance properties for "uses database" before loading and parsing PHPDoc
annotations for the same thing, rather than doing it afterwards.
This commit is contained in:
Robbie Averill 2018-06-14 13:59:44 +12:00
parent 6c985c4e5f
commit acc8d48b11
2 changed files with 17 additions and 29 deletions

View File

@ -1191,15 +1191,9 @@ class SapphireTest extends PHPUnit_Framework_TestCase implements TestOnly
// Support fixture paths relative to the test class, rather than relative to webroot
// String checking is faster than file_exists() calls.
$isRelativeToFile
= (strpos('/', $fixtureFilePath) === false)
|| preg_match('/^(\.){1,2}/', $fixtureFilePath);
if ($isRelativeToFile) {
$resolvedPath = realpath($this->getCurrentAbsolutePath() . '/' . $fixtureFilePath);
if ($resolvedPath) {
return $resolvedPath;
}
$resolvedPath = realpath($this->getCurrentAbsolutePath() . '/' . $fixtureFilePath);
if ($resolvedPath) {
return $resolvedPath;
}
// Check if file exists relative to base dir

View File

@ -155,15 +155,9 @@ class FixtureTestState implements TestState
{
// Support fixture paths relative to the test class, rather than relative to webroot
// String checking is faster than file_exists() calls.
$isRelativeToFile
= (strpos($fixtureFilePath, '/') === false)
|| preg_match('/^(\.){1,2}/', $fixtureFilePath);
if ($isRelativeToFile) {
$resolvedPath = realpath($this->getTestAbsolutePath($test) . '/' . $fixtureFilePath);
if ($resolvedPath) {
return $resolvedPath;
}
$resolvedPath = realpath($this->getTestAbsolutePath($test) . '/' . $fixtureFilePath);
if ($resolvedPath) {
return $resolvedPath;
}
// Check if file exists relative to base dir
@ -199,6 +193,17 @@ class FixtureTestState implements TestState
*/
protected function testNeedsDB(SapphireTest $test)
{
// test class explicitly enables DB
if ($test->getUsesDatabase()) {
return true;
}
// presence of fixture file implicitly enables DB
$fixtures = $test::get_fixture_file();
if (!empty($fixtures)) {
return true;
}
$annotations = $test->getAnnotations();
// annotation explicitly disables the DB
@ -213,17 +218,6 @@ class FixtureTestState implements TestState
return true;
}
// test class explicitly enables DB
if ($test->getUsesDatabase()) {
return true;
}
// presence of fixture file implicitly enables DB
$fixtures = $test::get_fixture_file();
if (!empty($fixtures)) {
return true;
}
return false;
}
}