-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from creative-commoners/pulls/1.0/disable-snaps…
…hots-in-tests NEW Allow pausing snapshots globally
- Loading branch information
Showing
3 changed files
with
109 additions
and
0 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: snapshotssapphiretest | ||
Before: '#sapphiretest' | ||
--- | ||
SilverStripe\Core\Injector\Injector: | ||
SilverStripe\Dev\State\SapphireTestState: | ||
properties: | ||
States: | ||
disablesnapshots: '%$SilverStripe\Snapshots\Dev\State\DisableSnapshots' |
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,63 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Snapshots\Dev\State; | ||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\Dev\State\TestState; | ||
use SilverStripe\Snapshots\SnapshotPublishable; | ||
|
||
/** | ||
* Disable snapshots in tests by default. Snapshots will analyze a relationship tree for objects when they are saved but | ||
* fixtures will not necessarily scaffold all required tables for this when the test state is scaffolded. | ||
* | ||
* Tests that rely on snapshot functionality should explicitly opt-in to snapshots by calling | ||
* `SnapshotPublishable::resume`. | ||
*/ | ||
class DisableSnapshots implements TestState | ||
{ | ||
|
||
/** | ||
* Called on setup | ||
* | ||
* @param SapphireTest $test | ||
*/ | ||
public function setUp(SapphireTest $test) | ||
{ | ||
// Skip tests in this modules' namespace | ||
if (strpos(get_class($test), 'SilverStripe\\Snapshots\\') === 0) { | ||
return; | ||
} | ||
|
||
SnapshotPublishable::pause(); | ||
} | ||
|
||
/** | ||
* Called on tear down | ||
* | ||
* @param SapphireTest $test | ||
*/ | ||
public function tearDown(SapphireTest $test) | ||
{ | ||
SnapshotPublishable::resume(); | ||
} | ||
|
||
/** | ||
* Called once on setup | ||
* | ||
* @param string $class Class being setup | ||
*/ | ||
public function setUpOnce($class) | ||
{ | ||
// noop | ||
} | ||
|
||
/** | ||
* Called once on tear down | ||
* | ||
* @param string $class Class being torn down | ||
*/ | ||
public function tearDownOnce($class) | ||
{ | ||
// noop | ||
} | ||
} |
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