Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate to single constant for minimum PHP version #114

Merged
merged 2 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions civicrm.module
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ define('CIVICRM_UF_HEAD', TRUE);
/**
* Minimum required PHP
*
* Note: This duplicates CRM_Upgrade_Form::MINIMUM_PHP_VERSION. The
* duplication helps avoid a dependency-loop. (Reading `Form::MINIMUM_PHP_VERSION`
* Note: This duplicates CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER. The
* duplication helps avoid a dependency-loop. (Reading `CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER`
* requires loading `civicrm.settings.php`, but that triggers a parse-error
* on PHP 5.x.)
*
* @see CRM_Upgrade_Form::MINIMUM_PHP_VERSION
* @see CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER
* @see CiviDrupal\PhpVersionTest::testConstantMatch()
*/
define('CIVICRM_DRUPAL_PHP_MINIMUM', '7.1.0');
Expand Down
10 changes: 6 additions & 4 deletions tests/phpunit/CiviBackdrop/PHPVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@
class PhpVersionTest extends \PHPUnit\Framework\TestCase implements EndToEndInterface {

/**
* CIVICRM_DRUPAL_PHP_MINIMUM (civicrm.module) should match MINIMUM_PHP_VERSION (CRM/Upgrade/Form.php).
* CIVICRM_DRUPAL_PHP_MINIMUM (civicrm.module) should match CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER.
*/
public function testConstantMatch() {
$constantFile = $this->getBackdropModulePath() . '/civicrm.module';
$this->assertFileExists($constantFile);
$content = file_get_contents($constantFile);
if (preg_match(";define\\('CIVICRM_DRUPAL_PHP_MINIMUM', '(.*)'\\);", $content, $m)) {
$this->assertEquals(\CRM_Upgrade_Form::MINIMUM_PHP_VERSION, $m[1]);
$a = preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', \CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER);
$b = preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', $m[1]);
$this->assertEquals($a, $b);
}
else {
$this->fail('Failed to find CIVICRM_DRUPAL_PHP_MINIMUM in ' . $constantFile);
}
}

/**
* "php" requirement (civicrm.info) should match MINIMUM_PHP_VERSION (CRM/Upgrade/Form.php).
* "php" requirement (civicrm.info) should match CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER.
*/
public function testInfoMatch() {
$infoFile = $this->getBackdropModulePath() . '/civicrm.info';
$this->assertFileExists($infoFile);
$info = drupal_parse_info_file($infoFile);
$expectMajorMinor = preg_replace(';^(\d+\.\d+)\..*$;', '\1', \CRM_Upgrade_Form::MINIMUM_PHP_VERSION);
$expectMajorMinor = preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', \CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER);
$this->assertEquals($expectMajorMinor, $info['php']);
}

Expand Down