From d18ee9748fe8ee012e799b26050f4e5e97e1a385 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 27 Jul 2016 01:18:16 -0700 Subject: [PATCH] CRM-14885 - CRM_Core_CodeGen_FreshnessTest - Add unit-test to ensure DAO's are current --- CRM/Core/CodeGen/Main.php | 20 +++++--- .../CRM/Core/CodeGen/FreshnessTest.php | 46 +++++++++++++++++++ 2 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 tests/phpunit/CRM/Core/CodeGen/FreshnessTest.php diff --git a/CRM/Core/CodeGen/Main.php b/CRM/Core/CodeGen/Main.php index 51b741310d..bb681dc204 100644 --- a/CRM/Core/CodeGen/Main.php +++ b/CRM/Core/CodeGen/Main.php @@ -63,7 +63,7 @@ class CRM_Core_CodeGen_Main { CRM_Core_CodeGen_Util_Smarty::singleton()->setPluginDirs($smartyPluginDirs); - $versionFile = "version.xml"; + $versionFile = $this->phpCodePath . "/xml/version.xml"; $versionXML = CRM_Core_CodeGen_Util_Xml::parse($versionFile); $this->db_version = $versionXML->version_no; $this->buildVersion = preg_replace('/^(\d{1,2}\.\d{1,2})\.(\d{1,2}|\w{4,7})$/i', '$1', $this->db_version); @@ -95,12 +95,6 @@ Alternatively you can get a version of CiviCRM that matches your PHP version exit(); } - $specification = new CRM_Core_CodeGen_Specification(); - $specification->parse($this->schemaPath, $this->buildVersion); - # cheese: - $this->database = $specification->database; - $this->tables = $specification->tables; - foreach ($this->getTasks() as $task) { if (getenv('GENCODE_FORCE') || $task->needsUpdate()) { $task->run(); @@ -114,6 +108,8 @@ Alternatively you can get a version of CiviCRM that matches your PHP version * @throws \Exception */ public function getTasks() { + $this->init(); + $tasks = array(); $tasks[] = new CRM_Core_CodeGen_Config($this); $tasks[] = new CRM_Core_CodeGen_Version($this); @@ -145,4 +141,14 @@ Alternatively you can get a version of CiviCRM that matches your PHP version return $this->sourceDigest; } + protected function init() { + if (!$this->database || !$this->tables) { + $specification = new CRM_Core_CodeGen_Specification(); + $specification->parse($this->schemaPath, $this->buildVersion); + # cheese: + $this->database = $specification->database; + $this->tables = $specification->tables; + } + } + } diff --git a/tests/phpunit/CRM/Core/CodeGen/FreshnessTest.php b/tests/phpunit/CRM/Core/CodeGen/FreshnessTest.php new file mode 100644 index 0000000000..d20903ba79 --- /dev/null +++ b/tests/phpunit/CRM/Core/CodeGen/FreshnessTest.php @@ -0,0 +1,46 @@ +getTasks(); + $names = array(); + foreach ($tasks as $task) { + if ($task instanceof CRM_Core_CodeGen_DAO) { + $names[] = $task->name; + $this->assertFalse($task->needsUpdate(), + "Expect DAO for {$task->name} is up-to-date."); + } + } + + // Pick some example to ensure the loop ran with real values. + $this->assertTrue(in_array('civicrm_contact', $names), + 'Expect the list of tables to include civicrm_contact'); + } + +} -- 2.25.1