Skip to content

Commit

Permalink
Update test to support for 8.0.19 change
Browse files Browse the repository at this point in the history
Update test following Eileen comments
  • Loading branch information
seamuslee001 committed May 19, 2020
1 parent 8e268ef commit c30d25c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions tests/phpunit/CRM/Logging/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
*/
class CRM_Logging_SchemaTest extends CiviUnitTestCase {

protected $databaseVersion;

public function setUp() {
$this->databaseVersion = CRM_Utils_SQL::getDatabaseVersion();
parent::setUp();
}

Expand All @@ -18,6 +21,7 @@ public function setUp() {
public function tearDown() {
$schema = new CRM_Logging_Schema();
$schema->disableLogging();
$this->databaseVersion = NULL;
parent::tearDown();
$this->quickCleanup(['civicrm_contact'], TRUE);
$schema->dropAllLogTables();
Expand Down Expand Up @@ -241,7 +245,9 @@ public function testColumnInfo() {
$this->assertEquals('42', $ci['test_varchar']['LENGTH']);

$this->assertEquals('int', $ci['test_integer']['DATA_TYPE']);
$this->assertEquals('8', $ci['test_integer']['LENGTH']);
if (!$this->isMySQL8()) {
$this->assertEquals('8', $ci['test_integer']['LENGTH']);
}
$this->assertEquals('YES', $ci['test_integer']['IS_NULLABLE']);

$this->assertEquals('decimal', $ci['test_decimal']['DATA_TYPE']);
Expand Down Expand Up @@ -282,7 +288,9 @@ public function testLengthChange() {
$schema->fixSchemaDifferences();
$ci = \Civi::$statics['CRM_Logging_Schema']['columnSpecs'];
// length should increase
$this->assertEquals(6, $ci['log_civicrm_test_length_change']['test_integer']['LENGTH']);
if (!$this->isMySQL8()) {
$this->assertEquals(6, $ci['log_civicrm_test_length_change']['test_integer']['LENGTH']);
}
$this->assertEquals('22,2', $ci['log_civicrm_test_length_change']['test_decimal']['LENGTH']);
CRM_Core_DAO::executeQuery(
"ALTER TABLE civicrm_test_length_change
Expand All @@ -292,7 +300,9 @@ public function testLengthChange() {
$schema->fixSchemaDifferences();
$ci = \Civi::$statics['CRM_Logging_Schema']['columnSpecs'];
// length should not decrease
$this->assertEquals(6, $ci['log_civicrm_test_length_change']['test_integer']['LENGTH']);
if (!$this->isMySQL8()) {
$this->assertEquals(6, $ci['log_civicrm_test_length_change']['test_integer']['LENGTH']);
}
$this->assertEquals('22,2', $ci['log_civicrm_test_length_change']['test_decimal']['LENGTH']);
}

Expand All @@ -312,4 +322,12 @@ public function testEnumChange() {
$this->assertEquals("'A','B','C','D'", $ci['civicrm_test_enum_change']['test_enum']['ENUM_VALUES']);
}

/**
* Determine if we are running on MySQL 8 version 8.0.19 or later.
*
* @return bool
*/
protected function isMySQL8() {
return (bool) (version_compare($this->databaseVersion, '8.0.19', '>=') && stripos($this->databaseVersion, 'mariadb') === FALSE);
}
}

0 comments on commit c30d25c

Please sign in to comment.