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$/',
|
'name_regex' => '/^[^_].*\\.php$/',
|
||||||
'ignore_files' => array('index.php', 'main.php', 'cli-script.php'),
|
'ignore_files' => array('index.php', 'main.php', 'cli-script.php'),
|
||||||
'ignore_tests' => !$includeTests,
|
'ignore_tests' => !$includeTests,
|
||||||
'file_callback' => array($this, 'handleFile'),
|
'file_callback' => function ($basename, $pathname) use ($includeTests) {
|
||||||
|
$this->handleFile($basename, $pathname, $includeTests);
|
||||||
|
},
|
||||||
));
|
));
|
||||||
$finder->find($this->base);
|
$finder->find($this->base);
|
||||||
|
|
||||||
@ -388,7 +390,7 @@ class ClassManifest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleFile($basename, $pathname)
|
public function handleFile($basename, $pathname, $includeTests)
|
||||||
{
|
{
|
||||||
$classes = null;
|
$classes = null;
|
||||||
$interfaces = null;
|
$interfaces = null;
|
||||||
@ -401,6 +403,7 @@ class ClassManifest
|
|||||||
$key = preg_replace('/[^a-zA-Z0-9_]/', '_', $basename) . '_' . md5_file($pathname);
|
$key = preg_replace('/[^a-zA-Z0-9_]/', '_', $basename) . '_' . md5_file($pathname);
|
||||||
|
|
||||||
// Attempt to load from cache
|
// Attempt to load from cache
|
||||||
|
$changed = false;
|
||||||
if ($this->cache
|
if ($this->cache
|
||||||
&& ($data = $this->cache->get($key))
|
&& ($data = $this->cache->get($key))
|
||||||
&& $this->validateItemCache($data)
|
&& $this->validateItemCache($data)
|
||||||
@ -409,6 +412,7 @@ class ClassManifest
|
|||||||
$interfaces = $data['interfaces'];
|
$interfaces = $data['interfaces'];
|
||||||
$traits = $data['traits'];
|
$traits = $data['traits'];
|
||||||
} else {
|
} else {
|
||||||
|
$changed = true;
|
||||||
// Build from php file parser
|
// Build from php file parser
|
||||||
$fileContents = ClassContentRemover::remove_class_content($pathname);
|
$fileContents = ClassContentRemover::remove_class_content($pathname);
|
||||||
try {
|
try {
|
||||||
@ -422,23 +426,16 @@ class ClassManifest
|
|||||||
$classes = $this->getVisitor()->getClasses();
|
$classes = $this->getVisitor()->getClasses();
|
||||||
$interfaces = $this->getVisitor()->getInterfaces();
|
$interfaces = $this->getVisitor()->getInterfaces();
|
||||||
$traits = $this->getVisitor()->getTraits();
|
$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
|
// Merge this data into the global list
|
||||||
foreach ($classes as $className => $classInfo) {
|
foreach ($classes as $className => $classInfo) {
|
||||||
$extends = isset($classInfo['extends']) ? $classInfo['extends'] : null;
|
$extends = !empty($classInfo['extends'])
|
||||||
$implements = isset($classInfo['interfaces']) ? $classInfo['interfaces'] : null;
|
? array_map('strtolower', $classInfo['extends'])
|
||||||
|
: [];
|
||||||
|
$implements = !empty($classInfo['interfaces'])
|
||||||
|
? array_map('strtolower', $classInfo['interfaces'])
|
||||||
|
: [];
|
||||||
$lowercaseName = strtolower($className);
|
$lowercaseName = strtolower($className);
|
||||||
if (array_key_exists($lowercaseName, $this->classes)) {
|
if (array_key_exists($lowercaseName, $this->classes)) {
|
||||||
throw new Exception(sprintf(
|
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;
|
$this->classes[$lowercaseName] = $pathname;
|
||||||
|
|
||||||
if ($extends) {
|
if ($extends) {
|
||||||
foreach ($extends as $ancestor) {
|
foreach ($extends as $ancestor) {
|
||||||
$ancestor = strtolower($ancestor);
|
|
||||||
|
|
||||||
if (!isset($this->children[$ancestor])) {
|
if (!isset($this->children[$ancestor])) {
|
||||||
$this->children[$ancestor] = array($className);
|
$this->children[$ancestor] = array($className);
|
||||||
} else {
|
} else {
|
||||||
@ -467,8 +472,6 @@ class ClassManifest
|
|||||||
|
|
||||||
if ($implements) {
|
if ($implements) {
|
||||||
foreach ($implements as $interface) {
|
foreach ($implements as $interface) {
|
||||||
$interface = strtolower($interface);
|
|
||||||
|
|
||||||
if (!isset($this->implementors[$interface])) {
|
if (!isset($this->implementors[$interface])) {
|
||||||
$this->implementors[$interface] = array($className);
|
$this->implementors[$interface] = array($className);
|
||||||
} else {
|
} else {
|
||||||
@ -484,6 +487,16 @@ class ClassManifest
|
|||||||
foreach ($traits as $traitName => $traitInfo) {
|
foreach ($traits as $traitName => $traitInfo) {
|
||||||
$this->traits[strtolower($traitName)] = $pathname;
|
$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)
|
public function enterNode(Node $node)
|
||||||
{
|
{
|
||||||
if ($node instanceof Node\Stmt\Class_) {
|
if ($node instanceof Node\Stmt\Class_) {
|
||||||
$extends = '';
|
$extends = [];
|
||||||
$interfaces = [];
|
$interfaces = [];
|
||||||
|
|
||||||
if ($node->extends) {
|
if ($node->extends) {
|
||||||
|
@ -34,7 +34,7 @@ use SimpleXMLElement;
|
|||||||
* }
|
* }
|
||||||
* </code>
|
* </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.
|
* 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
|
* This class should not be used anywhere outside of unit tests, as phpunit may not be installed
|
||||||
* in production sites.
|
* 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.
|
* Path to fixture data for this test run.
|
||||||
|
Loading…
Reference in New Issue
Block a user