mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Ensure that tests run with flush=1 clean Flushables
BUG Restore opt-in flushing (regression from #4404)
This commit is contained in:
parent
6d88ed1627
commit
7b26b4a1f3
@ -12,6 +12,7 @@ use SilverStripe\Control\Controller;
|
|||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Core\ClassInfo;
|
use SilverStripe\Core\ClassInfo;
|
||||||
|
use SilverStripe\Core\Flushable;
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\Core\Manifest\ClassManifest;
|
use SilverStripe\Core\Manifest\ClassManifest;
|
||||||
use SilverStripe\Core\Manifest\ClassLoader;
|
use SilverStripe\Core\Manifest\ClassLoader;
|
||||||
@ -159,6 +160,12 @@ class SapphireTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
private $extensionsToReapply = array(), $extensionsToRemove = array();
|
private $extensionsToReapply = array(), $extensionsToRemove = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check flushables on setupOnce()
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected static $flushedFlushables = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if unit tests are currently run, flag set during test bootstrap.
|
* Determines if unit tests are currently run, flag set during test bootstrap.
|
||||||
@ -379,6 +386,15 @@ class SapphireTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
// Set default timezone consistently to avoid NZ-specific dependencies
|
// Set default timezone consistently to avoid NZ-specific dependencies
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
|
|
||||||
|
// Flush all flushable records
|
||||||
|
$flush = !empty($_GET['flush']);
|
||||||
|
if (!self::$flushedFlushables && $flush) {
|
||||||
|
self::$flushedFlushables = true;
|
||||||
|
foreach (ClassInfo::implementorsOf(Flushable::class) as $class) {
|
||||||
|
$class::flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -976,11 +992,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public static function use_test_manifest()
|
public static function use_test_manifest()
|
||||||
{
|
{
|
||||||
$flush = true;
|
$flush = !empty($_GET['flush']);
|
||||||
if (isset($_GET['flush']) && $_GET['flush'] === '0') {
|
|
||||||
$flush = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$classManifest = new ClassManifest(
|
$classManifest = new ClassManifest(
|
||||||
BASE_PATH,
|
BASE_PATH,
|
||||||
true,
|
true,
|
||||||
|
@ -2,20 +2,20 @@
|
|||||||
|
|
||||||
namespace SilverStripe\Control\Tests;
|
namespace SilverStripe\Control\Tests;
|
||||||
|
|
||||||
|
use SilverStripe\Control\Tests\FlushRequestFilterTest\TestFlushable;
|
||||||
use SilverStripe\Dev\FunctionalTest;
|
use SilverStripe\Dev\FunctionalTest;
|
||||||
|
|
||||||
class FlushRequestFilterTest extends FunctionalTest
|
class FlushRequestFilterTest extends FunctionalTest
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert that classes that implement flushable are called
|
* Assert that classes that implement flushable are called
|
||||||
*/
|
*/
|
||||||
public function testImplementorsAreCalled()
|
public function testImplementorsAreCalled()
|
||||||
{
|
{
|
||||||
$this->assertFalse(FlushRequestFilterTest\TestFlushable::$flushed);
|
TestFlushable::$flushed = false;
|
||||||
|
|
||||||
$this->get('?flush=1');
|
$this->get('?flush=1');
|
||||||
|
|
||||||
$this->assertTrue(FlushRequestFilterTest\TestFlushable::$flushed);
|
$this->assertTrue(TestFlushable::$flushed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user