diff --git a/system/src/Grav/Console/Gpm/InstallCommand.php b/system/src/Grav/Console/Gpm/InstallCommand.php index bccdb8fb1..caea451b3 100644 --- a/system/src/Grav/Console/Gpm/InstallCommand.php +++ b/system/src/Grav/Console/Gpm/InstallCommand.php @@ -248,6 +248,30 @@ class InstallCommand extends ConsoleCommand } /** + * Check if the passed version information contains next significant release (tilde) operator + * + * Example: returns true for $version: '~2.0' + * + * @param $version + * + * @return bool + */ + public function versionFormatIsNextSignificantRelease($version) { + return substr($version, 0, 1) == '~'; + } + + /** + * Check if the passed version information contains equal or higher operator + * + * Example: returns true for $version: '>=2.0' + * + * @param $version + * + * @return bool + */ + public function versionFormatIsEqualOrHigher($version) { + return substr($version, 0, 2) == '>='; + } /** * Check if two releases are compatible by next significant release diff --git a/tests/unit/Grav/Console/Gpm/InstallCommandTest.php b/tests/unit/Grav/Console/Gpm/InstallCommandTest.php index b16bc6ee3..d25d3d43e 100644 --- a/tests/unit/Grav/Console/Gpm/InstallCommandTest.php +++ b/tests/unit/Grav/Console/Gpm/InstallCommandTest.php @@ -114,6 +114,24 @@ class InstallCommandTest extends \Codeception\TestCase\Test $this->assertTrue(count($dependencies) == 1); $this->assertTrue($dependencies['errors'] == '>=4.0'); + public function testVersionFormatIsNextSignificantRelease() + { + $this->assertFalse($this->installCommand->versionFormatIsNextSignificantRelease('>=1.0')); + $this->assertFalse($this->installCommand->versionFormatIsNextSignificantRelease('>=2.3.4')); + $this->assertFalse($this->installCommand->versionFormatIsNextSignificantRelease('>=2.3.x')); + $this->assertFalse($this->installCommand->versionFormatIsNextSignificantRelease('1.0')); + $this->assertTrue($this->installCommand->versionFormatIsNextSignificantRelease('~2.3.x')); + $this->assertTrue($this->installCommand->versionFormatIsNextSignificantRelease('~2.0')); + } + + public function testVersionFormatIsEqualOrHigher() + { + $this->assertTrue($this->installCommand->versionFormatIsEqualOrHigher('>=1.0')); + $this->assertTrue($this->installCommand->versionFormatIsEqualOrHigher('>=2.3.4')); + $this->assertTrue($this->installCommand->versionFormatIsEqualOrHigher('>=2.3.x')); + $this->assertFalse($this->installCommand->versionFormatIsEqualOrHigher('~2.3.x')); + $this->assertFalse($this->installCommand->versionFormatIsEqualOrHigher('1.0')); + } public function testCheckNextSignificantReleasesAreCompatible() {