mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
6c985c4e5f
commit
acc8d48b11
@ -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
|
// Support fixture paths relative to the test class, rather than relative to webroot
|
||||||
// String checking is faster than file_exists() calls.
|
// String checking is faster than file_exists() calls.
|
||||||
$isRelativeToFile
|
$resolvedPath = realpath($this->getCurrentAbsolutePath() . '/' . $fixtureFilePath);
|
||||||
= (strpos('/', $fixtureFilePath) === false)
|
if ($resolvedPath) {
|
||||||
|| preg_match('/^(\.){1,2}/', $fixtureFilePath);
|
return $resolvedPath;
|
||||||
|
|
||||||
if ($isRelativeToFile) {
|
|
||||||
$resolvedPath = realpath($this->getCurrentAbsolutePath() . '/' . $fixtureFilePath);
|
|
||||||
if ($resolvedPath) {
|
|
||||||
return $resolvedPath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if file exists relative to base dir
|
// Check if file exists relative to base dir
|
||||||
|
@ -155,15 +155,9 @@ class FixtureTestState implements TestState
|
|||||||
{
|
{
|
||||||
// Support fixture paths relative to the test class, rather than relative to webroot
|
// Support fixture paths relative to the test class, rather than relative to webroot
|
||||||
// String checking is faster than file_exists() calls.
|
// String checking is faster than file_exists() calls.
|
||||||
$isRelativeToFile
|
$resolvedPath = realpath($this->getTestAbsolutePath($test) . '/' . $fixtureFilePath);
|
||||||
= (strpos($fixtureFilePath, '/') === false)
|
if ($resolvedPath) {
|
||||||
|| preg_match('/^(\.){1,2}/', $fixtureFilePath);
|
return $resolvedPath;
|
||||||
|
|
||||||
if ($isRelativeToFile) {
|
|
||||||
$resolvedPath = realpath($this->getTestAbsolutePath($test) . '/' . $fixtureFilePath);
|
|
||||||
if ($resolvedPath) {
|
|
||||||
return $resolvedPath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if file exists relative to base dir
|
// Check if file exists relative to base dir
|
||||||
@ -199,6 +193,17 @@ class FixtureTestState implements TestState
|
|||||||
*/
|
*/
|
||||||
protected function testNeedsDB(SapphireTest $test)
|
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();
|
$annotations = $test->getAnnotations();
|
||||||
|
|
||||||
// annotation explicitly disables the DB
|
// annotation explicitly disables the DB
|
||||||
@ -213,17 +218,6 @@ class FixtureTestState implements TestState
|
|||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user