Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API Refactor SapphireTest state management into SapphireTestState
API Remove Injector::unregisterAllObjects() API Remove FakeController
- Loading branch information
Damian Mooyman
committed
Jun 20, 2017
1 parent
f26ae75
commit c66d433
Showing
23 changed files
with
493 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
Name: sapphiretest | ||
--- | ||
SilverStripe\Core\Injector\Injector: | ||
SilverStripe\Dev\SapphireTestState: | ||
properties: | ||
States: | ||
flushable: %$SilverStripe\Dev\FlushableTestState | ||
requirements: %$SilverStripe\View\Dev\RequirementsTestState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Core; | ||
|
||
/** | ||
* Kernel for running unit tests | ||
*/ | ||
class TestKernel extends AppKernel | ||
{ | ||
public function __construct($flush = true) | ||
{ | ||
parent::__construct($flush); | ||
$this->setEnvironment(self::DEV); | ||
} | ||
|
||
/** | ||
* Reset kernel between tests. | ||
* Note: this avoids resetting services (See TestState for service specific reset) | ||
*/ | ||
public function reset() | ||
{ | ||
$this->setEnvironment(self::DEV); | ||
$this->bootPHP(); | ||
} | ||
|
||
protected function getIncludeTests() | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Dev; | ||
|
||
use SilverStripe\Core\ClassInfo; | ||
use SilverStripe\Core\Flushable; | ||
use SilverStripe\Core\Resettable; | ||
|
||
/** | ||
* Clears flushable / resettable objects | ||
*/ | ||
class FlushableTestState implements TestState | ||
{ | ||
/** | ||
* @var bool | ||
*/ | ||
protected $flushed = false; | ||
|
||
public function setUp(SapphireTest $test) | ||
{ | ||
// Reset all resettables | ||
/** @var Resettable $resettable */ | ||
foreach (ClassInfo::implementorsOf(Resettable::class) as $resettable) { | ||
$resettable::reset(); | ||
} | ||
} | ||
|
||
public function tearDown(SapphireTest $test) | ||
{ | ||
} | ||
|
||
public function setUpOnce($class) | ||
{ | ||
if ($this->flushed) { | ||
return; | ||
} | ||
$this->flushed = true; | ||
|
||
// Flush all flushable records | ||
/** @var Flushable $class */ | ||
foreach (ClassInfo::implementorsOf(Flushable::class) as $class) { | ||
$class::flush(); | ||
} | ||
} | ||
|
||
public function tearDownOnce($class) | ||
{ | ||
} | ||
} |
Oops, something went wrong.