FIX Flush extra_methods statics between test runs

This commit is contained in:
Robbie Averill 2018-10-09 13:22:54 +02:00
parent 55e79ffdfd
commit 56d5621934
5 changed files with 15 additions and 23 deletions

View File

@ -3,12 +3,9 @@
namespace SilverStripe\Core;
use InvalidArgumentException;
use SilverStripe\Control\RequestHandler;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject;
use SilverStripe\View\ViewableData;
/**
@ -214,6 +211,14 @@ trait Extensible
return true;
}
/**
* Clears all cached extra_methods cache data
*/
public static function flush_extra_methods_cache()
{
self::$extra_methods = [];
}
/**
* Remove an extension from a class.

View File

@ -30,6 +30,7 @@ class ExtensionTestState implements TestState
*/
public function setUp(SapphireTest $test)
{
DataObject::flush_extra_methods_cache();
}
public function tearDown(SapphireTest $test)
@ -104,23 +105,5 @@ class ExtensionTestState implements TestState
public function tearDownOnce($class)
{
// @todo: This isn't strictly necessary to restore extensions, but only to ensure that
// Object::$extra_methods is properly flushed. This should be replaced with a simple
// flush mechanism for each $class.
/** @var string|DataObject $dataClass */
// Remove extensions added for testing
foreach ($this->extensionsToRemove as $dataClass => $extensions) {
foreach ($extensions as $extension) {
$dataClass::remove_extension($extension);
}
}
// Reapply ones removed
foreach ($this->extensionsToReapply as $dataClass => $extensions) {
foreach ($extensions as $extension) {
$dataClass::add_extension($extension);
}
}
}
}

View File

@ -1065,6 +1065,7 @@ class InjectorTest extends SapphireTest
/** @var Member|SomeExtension $member */
$member = new Member();
$this->assertTrue($member->hasExtension(SomeExtension::class));
$this->assertTrue($member->hasMethod('someMethod'));
$this->assertSame('bar', $member->someMethod());
}
}

View File

@ -2,7 +2,9 @@
namespace SilverStripe\Core\Tests\Injector\InjectorTest;
class SomeCustomisedExtension extends SomeExtension
use SilverStripe\Dev\TestOnly;
class SomeCustomisedExtension extends SomeExtension implements TestOnly
{
public function someMethod()
{

View File

@ -2,9 +2,10 @@
namespace SilverStripe\Core\Tests\Injector\InjectorTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataExtension;
class SomeExtension extends DataExtension
class SomeExtension extends DataExtension implements TestOnly
{
public function someMethod()
{