Merge pull request #8177 from creative-commoners/pulls/4.2/relative-fixture-fix

FIX SapphireTest can load relative fixtures in subfolders, switch "needs db" priority check order
This commit is contained in:
Damian Mooyman 2018-06-14 16:34:40 +12:00 committed by GitHub
commit 9139db2a9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
}
}