-
-
Save svandragt/ad3f543d680adc843a4b to your computer and use it in GitHub Desktop.
Basic testing problem
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
PHP Fatal error: Couldn't run query: | |
SELECT DISTINCT "IntakeType"."ClassName", "IntakeType"."Created", "IntakeType"."LastEdited", "IntakeType"."Title", "IntakeType"."Code", "IntakeType"."ID", CASE WHEN "IntakeType"."ClassName" IS NOT NULL THEN "IntakeType"."ClassName" ELSE 'IntakeType' END AS "RecordClassName" | |
FROM "IntakeType" | |
WHERE ("Code" = 'FIXED') | |
LIMIT 1 | |
Table 'ss_tmpdb5256577.intaketype' doesn't exist in /vagrant/public_html/framework/model/MySQLDatabase.php on line 580 | |
PHP Warning: Cookie 'alternativeDatabaseName' can't be set. The site started outputting content at line 64 in /vagrant/public_html/framework/dev/CliDebugView.php in /vagrant/public_html/framework/control/Cookie.php on line 35 | |
PHP Warning: Cookie 'alternativeDatabaseNameIv' can't be set. The site started outputting content at line 64 in /vagrant/public_html/framework/dev/CliDebugView.php in /vagrant/public_html/framework/control/Cookie.php on line 35 |
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
<?php | |
class CourseDate extends DataObject { | |
public static $has_one = array( | |
'CourseMOA' => 'CourseMOA', | |
); | |
// code that uses coursemoa | |
} |
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
<?php | |
class CourseDateTest extends SapphireTest { | |
public static $fixture_file = 'CourseDateTest.yml'; | |
protected $extraDataObjects = array( | |
'CourseMOA', | |
'IntakeType' | |
); | |
public function testDelete() { | |
$this->assertTrue(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
IntakeType: | |
fixed: | |
ID: 1 | |
Title: Fixed | |
Code: FIXED | |
flexible: | |
ID:2 | |
Title: Flexible | |
Code: FLEXIBLE | |
CourseMOA: | |
uno: | |
ID:3 | |
IntakeType: =>IntakeType.fixed | |
CourseDate: | |
one: | |
CourseMOA: =>CourseMOA.uno |
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
<?php | |
class CourseMOA extends DataObject | |
{ | |
public static $has_one = array( | |
'IntakeType' => 'IntakeType', | |
); | |
public static $has_many = array( | |
'CourseDates' => 'CourseDate', | |
); | |
// [...] | |
public function populateDefaults() | |
{ | |
parent::populateDefaults(); | |
if (class_exists('IntakeType')) { | |
$IntakeTypeFixed = IntakeType::get()->filter('Code', 'FIXED'); | |
if ($IntakeTypeFixed) { | |
$id = $IntakeTypeFixed->first()->ID; | |
$this->IntakeTypeID = $id; | |
} | |
} | |
} | |
} |
yep, I tried changing to DataObject::get('IntakeType')...
but that does not make a difference
DataQuery.php:165 $baseClass = $tableNames[0];
$i = IntakeType::get()->filter('Code', 'FIXED');
works ok because of lazy loading but when trying to get the ID then it still fails later.
Updated the CourseMOA.php with better code but still test fails the same.
Workaround / Solution:
Replace https://gist.github.com/svandragt/ad3f543d680adc843a4b#file-coursemoa-php-L18 with
if (class_exists('IntakeType') && (Security::database_is_ready())) {
Thanks @micmania
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I take out these lines then the test passes: https://gist.github.com/svandragt/ad3f543d680adc843a4b#file-coursemoa-php-L19-L23