Skip to content

Commit

Permalink
BUGFIX Enforcing creation of temp database in SapphireTest->setUp() t…
Browse files Browse the repository at this point in the history
…o avoid writing to production databases. This check should only kick in for single test case runs, as the temp database connection should be set in a dev/tests/all run after the first db-related test anyway. (see #5034) (from r99342)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102462 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu committed Apr 12, 2010
1 parent a09263e commit 43ff00e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion dev/SapphireTest.php
Expand Up @@ -111,7 +111,7 @@ function setUp() {
$fixtureFile = eval("return {$className}::\$fixture_file;"); $fixtureFile = eval("return {$className}::\$fixture_file;");


// Set up fixture // Set up fixture
if($fixtureFile || $this->usesDatabase) { if($fixtureFile || $this->usesDatabase || !self::using_temp_db()) {
if(substr(DB::getConn()->currentDatabase(),0,5) != 'tmpdb') { if(substr(DB::getConn()->currentDatabase(),0,5) != 'tmpdb') {
//echo "Re-creating temp database... "; //echo "Re-creating temp database... ";
self::create_temp_db(); self::create_temp_db();
Expand Down

3 comments on commit 43ff00e

@ntd
Copy link
Contributor

@ntd ntd commented on 43ff00e May 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is when you have tests that do not use the database, then I suppose self::using_temp_db() will return false. In other words this commit makes usesDatabase effectively useless because the database is always created when you do not require it.

@dhensby
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be if(($fixtureFile || $this->usesDatabase) && !self::using_temp_db())

If there's a fixture file or you declare you need a database and there's no temp db active....

@dhensby
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enforcing creation of temp database in SapphireTest->setUp() to avoid writing to production databases

uh oh, who's running test suites on production environments :/

Please sign in to comment.