From ee7d22ee321c41fe4435235250473d382ccd8deb Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 19 Jul 2017 17:38:08 -0700 Subject: [PATCH] CRM_Utils_SQL_SelectTest - Split into smaller test functions --- tests/phpunit/CRM/Utils/SQL/SelectTest.php | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/CRM/Utils/SQL/SelectTest.php b/tests/phpunit/CRM/Utils/SQL/SelectTest.php index 4f6368683d..ba4d8d29dd 100644 --- a/tests/phpunit/CRM/Utils/SQL/SelectTest.php +++ b/tests/phpunit/CRM/Utils/SQL/SelectTest.php @@ -10,13 +10,12 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { $this->assertLike('SELECT * FROM foo bar', $select->toSQL()); } - public function testExecute_OK() { - // We need some SQL query. - $select = CRM_Utils_SQL_Select::from('civicrm_contact') - ->select('count(*) as cnt'); + public function testExecute_OK_fetch() { + $select = CRM_Utils_SQL_Select::from('civicrm_contact')->select('count(*) as cnt'); $this->assertLike('SELECT count(*) as cnt FROM civicrm_contact', $select->toSQL()); - // Try with typical fetch(). + $select = CRM_Utils_SQL_Select::from('civicrm_contact') + ->select('count(*) as cnt'); $rows = 0; $dao = $select->execute(); while ($dao->fetch()) { @@ -24,18 +23,26 @@ class CRM_Utils_SQL_SelectTest extends CiviUnitTestCase { $this->assertTrue(is_numeric($dao->cnt), "Expect query to execute"); } $this->assertEquals(1, $rows); + } - // Try with fetchValue(). + public function testExecute_OK_fetchValue() { + $select = CRM_Utils_SQL_Select::from('civicrm_contact')->select('count(*) as cnt'); + $this->assertLike('SELECT count(*) as cnt FROM civicrm_contact', $select->toSQL()); $this->assertTrue(is_numeric($select->execute()->fetchValue())); + } - // Try with fetchAll() + public function testExecute_OK_fetchAll() { + $select = CRM_Utils_SQL_Select::from('civicrm_contact')->select('count(*) as cnt'); + $this->assertLike('SELECT count(*) as cnt FROM civicrm_contact', $select->toSQL()); $records = $select->execute()->fetchAll(); $this->assertTrue(is_numeric($records[0]['cnt'])); } public function testExecute_Error() { + $select = CRM_Utils_SQL_Select::from('civicrm_contact')->select('snarb;barg'); + try { - CRM_Utils_SQL_Select::from('civicrm_contact')->select('snarb;barg')->execute(); + $select->execute(); $this->fail('Expected an exception'); } catch (PEAR_Exception $e) { -- 2.25.1