changed 'acceptedVersions' identifier to semantic versioner

This commit is contained in:
Taras Machyshyn
2015-02-05 15:04:51 +02:00
parent fd072520a9
commit 1c51125e66
4 changed files with 106 additions and 38 deletions
+14 -14
View File
@@ -22,9 +22,10 @@
namespace Espo\Core\Upgrades\Actions;
use Espo\Core\Utils\Util,
Espo\Core\Utils\Json,
Espo\Core\Exceptions\Error;
use Espo\Core\Utils\Util;
use Espo\Core\Utils\Json;
use Espo\Core\Exceptions\Error;
use vierbergenlars\SemVer;
abstract class Base
{
@@ -195,25 +196,24 @@ abstract class Base
return true;
}
$currentVersion = $this->getConfig()->get('version');
if (is_string($version)) {
$version = (array) $version;
}
$currentVersion = $this->getConfig()->get('version');
$semver = new SemVer\version($currentVersion);
foreach ($version as $strVersion) {
$strVersion = trim($strVersion);
if ($strVersion == $currentVersion) {
return true;
$isInRange = false;
try {
$isInRange = $semver->satisfies(new SemVer\expression($strVersion));
} catch (\Exception $e) {
$GLOBALS['log']->error('Installer [acceptableVersions]: '.$e->getMessage().'.');
}
$strVersion = str_replace('\\', '', $strVersion);
$strVersion = preg_quote($strVersion);
$strVersion = str_replace('\\*', '+', $strVersion);
if (preg_match('/^'.$strVersion.'/', $currentVersion)) {
if ($isInRange) {
return true;
}
}
+2 -1
View File
@@ -7,7 +7,8 @@
"zendframework/zend-mail": "2.*",
"zendframework/zend-ldap": "2.*",
"monolog/monolog": "1.*",
"yzalis/identicon": "*"
"yzalis/identicon": "*",
"vierbergenlars/php-semver": "~3.0"
},
"autoload": {
"psr-0": {
Generated
+58 -13
View File
@@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "f17c147afb6a73d470f740a590b15041",
"hash": "1926d800cde8320d3e495952c46d5f9a",
"packages": [
{
"name": "doctrine/annotations",
@@ -669,6 +669,58 @@
],
"time": "2014-02-16 18:18:25"
},
{
"name": "vierbergenlars/php-semver",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/vierbergenlars/php-semver.git",
"reference": "4dc35f3804f3b127ad557b8b2255c03204dec951"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vierbergenlars/php-semver/zipball/4dc35f3804f3b127ad557b8b2255c03204dec951",
"reference": "4dc35f3804f3b127ad557b8b2255c03204dec951",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"simpletest/simpletest": "1.1.*"
},
"bin": [
"bin/semver",
"bin/update-versions"
],
"type": "library",
"autoload": {
"psr-0": {
"vierbergenlars\\SemVer\\": "src/",
"vierbergenlars\\LibJs\\": "src/"
},
"classmap": [
"src/vierbergenlars/SemVer/internal.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Lars Vierbergen",
"email": "vierbergenlars@gmail.com"
}
],
"description": "The Semantic Versioner for PHP",
"keywords": [
"semantic",
"semver",
"versioning"
],
"time": "2013-12-21 17:10:13"
},
{
"name": "yzalis/identicon",
"version": "1.1.0",
@@ -1540,18 +1592,11 @@
"time": "2014-01-07 13:28:54"
}
],
"aliases": [
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [
],
"stability-flags": [],
"prefer-stable": false,
"platform": [
],
"platform-dev": [
]
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
+32 -10
View File
@@ -48,6 +48,8 @@ class BaseTest extends \PHPUnit_Framework_TestCase
)
);
protected $currentVersion = '11.5.2';
protected function setUp()
{
$this->objects['container'] = $this->getMockBuilder('\Espo\Core\Container')->disableOriginalConstructor()->getMock();
@@ -56,6 +58,8 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$this->objects['config'] = $this->getMockBuilder('\Espo\Core\Utils\Config')->disableOriginalConstructor()->getMock();
$this->objects['fileManager'] = $this->getMockBuilder('\Espo\Core\Utils\File\Manager')->disableOriginalConstructor()->getMock();
$GLOBALS['log'] = $this->getMockBuilder('\Espo\Core\Utils\Log')->disableOriginalConstructor()->getMock();
$map = array(
array('config', $this->objects['config']),
array('fileManager', $this->objects['fileManager']),
@@ -163,23 +167,33 @@ class BaseTest extends \PHPUnit_Framework_TestCase
return array(
array( '11.5.2' ),
array( array('11.5.2') ),
array( array('1.4', '11.5.2') ),
array( '11.*' ),
array( '11\.*' ),
array( '11.5*' ),
// array( ),
array( array('1.4', '11.5.2')),
array( '11.*', ),
array( '11.5.*', ),
array( '~11.5', ),
array( '~11', ),
array( '^11.1', ),
array( '^11', ),
array( '11.1 - 11.9', ),
array( '>=11.1', ),
array( '<=12', ),
array( '>=11 <=12', ),
);
}
/**
* @dataProvider acceptableData
*/
public function testIsAcceptable($version)
public function testIsAcceptable($version, $currentVersion = null)
{
if (!isset($currentVersion)) {
$currentVersion = $this->currentVersion;
}
$this->objects['config']
->expects($this->once())
->method('get')
->will($this->returnValue('11.5.2'));
->will($this->returnValue($currentVersion));
$this->reflection->setProperty('data', array('manifest' => array('acceptableVersions' => $version)));
$this->assertTrue( $this->reflection->invokeMethod('isAcceptable') );
@@ -196,21 +210,29 @@ class BaseTest extends \PHPUnit_Framework_TestCase
public function acceptableDataFalse()
{
return array(
array( '1.*' ),
array( '1.*', ),
array( '11\.*', ),
array( '11\.5\.2', ),
array( '11.5*', ),
array( '11.1-11.9', ),
);
}
/**
* @dataProvider acceptableDataFalse
*/
public function testIsAcceptableFalse($version)
public function testIsAcceptableFalse($version, $currentVersion = null)
{
if (!isset($currentVersion)) {
$currentVersion = $this->currentVersion;
}
$this->setExpectedException('\Espo\Core\Exceptions\Error');
$this->objects['config']
->expects($this->once())
->method('get')
->will($this->returnValue('11.5.2'));
->will($this->returnValue($currentVersion));
$this->reflection->setProperty('data', array('manifest' => array('acceptableVersions' => $version)));
$this->assertFalse( $this->reflection->invokeMethod('isAcceptable', array()) );