mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Fix non-test class manifest including sapphiretest / functionaltest
This commit is contained in:
parent
9379834cb4
commit
76f95944fa
@ -368,7 +368,9 @@ class ClassManifest
|
||||
'name_regex' => '/^[^_].*\\.php$/',
|
||||
'ignore_files' => array('index.php', 'main.php', 'cli-script.php'),
|
||||
'ignore_tests' => !$includeTests,
|
||||
'file_callback' => array($this, 'handleFile'),
|
||||
'file_callback' => function ($basename, $pathname) use ($includeTests) {
|
||||
$this->handleFile($basename, $pathname, $includeTests);
|
||||
},
|
||||
));
|
||||
$finder->find($this->base);
|
||||
|
||||
@ -388,7 +390,7 @@ class ClassManifest
|
||||
}
|
||||
}
|
||||
|
||||
public function handleFile($basename, $pathname)
|
||||
public function handleFile($basename, $pathname, $includeTests)
|
||||
{
|
||||
$classes = null;
|
||||
$interfaces = null;
|
||||
@ -401,6 +403,7 @@ class ClassManifest
|
||||
$key = preg_replace('/[^a-zA-Z0-9_]/', '_', $basename) . '_' . md5_file($pathname);
|
||||
|
||||
// Attempt to load from cache
|
||||
$changed = false;
|
||||
if ($this->cache
|
||||
&& ($data = $this->cache->get($key))
|
||||
&& $this->validateItemCache($data)
|
||||
@ -409,6 +412,7 @@ class ClassManifest
|
||||
$interfaces = $data['interfaces'];
|
||||
$traits = $data['traits'];
|
||||
} else {
|
||||
$changed = true;
|
||||
// Build from php file parser
|
||||
$fileContents = ClassContentRemover::remove_class_content($pathname);
|
||||
try {
|
||||
@ -422,23 +426,16 @@ class ClassManifest
|
||||
$classes = $this->getVisitor()->getClasses();
|
||||
$interfaces = $this->getVisitor()->getInterfaces();
|
||||
$traits = $this->getVisitor()->getTraits();
|
||||
|
||||
// Save back to cache if configured
|
||||
if ($this->cache) {
|
||||
$cache = array(
|
||||
'classes' => $classes,
|
||||
'interfaces' => $interfaces,
|
||||
'traits' => $traits,
|
||||
);
|
||||
$this->cache->set($key, $cache);
|
||||
}
|
||||
}
|
||||
|
||||
// Merge this data into the global list
|
||||
foreach ($classes as $className => $classInfo) {
|
||||
$extends = isset($classInfo['extends']) ? $classInfo['extends'] : null;
|
||||
$implements = isset($classInfo['interfaces']) ? $classInfo['interfaces'] : null;
|
||||
|
||||
$extends = !empty($classInfo['extends'])
|
||||
? array_map('strtolower', $classInfo['extends'])
|
||||
: [];
|
||||
$implements = !empty($classInfo['interfaces'])
|
||||
? array_map('strtolower', $classInfo['interfaces'])
|
||||
: [];
|
||||
$lowercaseName = strtolower($className);
|
||||
if (array_key_exists($lowercaseName, $this->classes)) {
|
||||
throw new Exception(sprintf(
|
||||
@ -449,12 +446,20 @@ class ClassManifest
|
||||
));
|
||||
}
|
||||
|
||||
// Skip if implements TestOnly, but doesn't include tests
|
||||
if (!$includeTests
|
||||
&& $implements
|
||||
&& in_array(strtolower(TestOnly::class), $implements)
|
||||
) {
|
||||
$changed = true;
|
||||
unset($classes[$className]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->classes[$lowercaseName] = $pathname;
|
||||
|
||||
if ($extends) {
|
||||
foreach ($extends as $ancestor) {
|
||||
$ancestor = strtolower($ancestor);
|
||||
|
||||
if (!isset($this->children[$ancestor])) {
|
||||
$this->children[$ancestor] = array($className);
|
||||
} else {
|
||||
@ -467,8 +472,6 @@ class ClassManifest
|
||||
|
||||
if ($implements) {
|
||||
foreach ($implements as $interface) {
|
||||
$interface = strtolower($interface);
|
||||
|
||||
if (!isset($this->implementors[$interface])) {
|
||||
$this->implementors[$interface] = array($className);
|
||||
} else {
|
||||
@ -484,6 +487,16 @@ class ClassManifest
|
||||
foreach ($traits as $traitName => $traitInfo) {
|
||||
$this->traits[strtolower($traitName)] = $pathname;
|
||||
}
|
||||
|
||||
// Save back to cache if configured
|
||||
if ($changed && $this->cache) {
|
||||
$cache = array(
|
||||
'classes' => $classes,
|
||||
'interfaces' => $interfaces,
|
||||
'traits' => $traits,
|
||||
);
|
||||
$this->cache->set($key, $cache);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,7 +30,7 @@ class ClassManifestVisitor extends NodeVisitorAbstract
|
||||
public function enterNode(Node $node)
|
||||
{
|
||||
if ($node instanceof Node\Stmt\Class_) {
|
||||
$extends = '';
|
||||
$extends = [];
|
||||
$interfaces = [];
|
||||
|
||||
if ($node->extends) {
|
||||
|
@ -34,7 +34,7 @@ use SimpleXMLElement;
|
||||
* }
|
||||
* </code>
|
||||
*/
|
||||
class FunctionalTest extends SapphireTest
|
||||
class FunctionalTest extends SapphireTest implements TestOnly
|
||||
{
|
||||
/**
|
||||
* Set this to true on your sub-class to disable the use of themes in this test.
|
||||
|
@ -45,7 +45,7 @@ if (!class_exists(PHPUnit_Framework_TestCase::class)) {
|
||||
* This class should not be used anywhere outside of unit tests, as phpunit may not be installed
|
||||
* in production sites.
|
||||
*/
|
||||
class SapphireTest extends PHPUnit_Framework_TestCase
|
||||
class SapphireTest extends PHPUnit_Framework_TestCase implements TestOnly
|
||||
{
|
||||
/**
|
||||
* Path to fixture data for this test run.
|
||||
|
Loading…
Reference in New Issue
Block a user