From ad498e1bea4f23eeaaddb3a94da3ca85ee68a4eb Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 1 Jul 2016 12:44:56 +1000 Subject: [PATCH] Fix up Tests and add in return statements --- CRM/Core/BAO/SchemaHandler.php | 3 ++- .../CRM/Core/BAO/SchemaHandlerTest.php | 26 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CRM/Core/BAO/SchemaHandler.php b/CRM/Core/BAO/SchemaHandler.php index c5ddefba10..107c945d6d 100644 --- a/CRM/Core/BAO/SchemaHandler.php +++ b/CRM/Core/BAO/SchemaHandler.php @@ -630,8 +630,9 @@ MODIFY {$columnName} varchar( $length ) if ($dao->fetch()) { CRM_Core_DAO::executeQuery("ALTER TABLE {$table_name} DROP FOREIGN KEY {$constraint_name}", array()); + return TRUE; } - + return FALSE; } } diff --git a/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php b/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php index 90089fb1ca..93f43130a2 100644 --- a/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php +++ b/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php @@ -148,19 +148,27 @@ class CRM_Core_BAO_SchemaHandlerTest extends CiviUnitTestCase { } } + /** + * @return array + */ + public function foreignKeyTests() { + $keys = array(); + $keys[] = array('civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_email_id'); + $keys[] = array('civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_id'); + return $keys; + } + /** * Test to see if we can drop foreign key * + * @dataProvider foreignKeyTests */ - public function testSafeDropForeignKey() { - $tests = array('FK_civicrm_mailing_recipients_email_id', 'FK_civicrm_mailing_recipients_id'); - foreach ($tests as $test) { - if ($test == 'FK_civicrm_mailing_recipients_id') { - $this->assertFalse(CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mailing_recipients', $test)); - } - else { - $this->assertTrue(CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mailing_recipients', $test)); - } + public function testSafeDropForeignKey($tableName, $key) { + if ($key == 'FK_civicrm_mailing_recipients_id') { + $this->assertFalse(CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mailing_recipients', $key)); + } + else { + $this->assertTrue(CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mailing_recipients', $key)); } } -- 2.25.1