Commit 0a08acb8 authored by Bas de Nooijer's avatar Bas de Nooijer

- improved phpdoc

- added check methods to Solarium_Version
- added new tests for Solarium_Version
parent f2bba9c6
......@@ -126,9 +126,9 @@ class Solarium_Configurable
}
/**
* Get an option value
* Get an option value by name
*
* If the options is empty or not set a NULL value will be returned.
* If the option is empty or not set a NULL value will be returned.
*
* @param string $name
* @return mixed
......
......@@ -38,7 +38,7 @@
* Solarium specific exception
*
* All exceptions thrown by Solarium are of this type. This way you can easily
* catch Solarium exception and keep them separate from you own exceptions.
* catch Solarium exception and keep them separate from your own exceptions.
*
* @package Solarium
*/
......
......@@ -47,9 +47,89 @@ class Solarium_Version
/**
* Version number of the Solarium library
*
* The version is built up in this format: major.minor.mini
*
* A major release is used for significant release with architectural
* changes and changes that might break backwards compatibility
*
* A minor release adds and enhances features, and might also contain
* bugfixes. It should be backwards compatible, or the incompatibilities
* should be clearly documented with the release.
*
* A mini release only contains bugfixes to existing features and is always
* backwards compatible.
*
* If you develop your application to a specific Solarium version it is best
* to check for that exact major and minor version, leaving the mini version
* open to allow for upgrades in case of bugfixes.
*
* @see checkExact()
* @see checkMinimal()
*
* @var string
*/
const VERSION = '0.1-dev';
const VERSION = '1.2.3';
/**
* Check for an exact version
*
* This method can check for all three versioning levels, but they are
* optional. If you only care for major and minor versions you can use
* something like '1.0' as input. Or '1' if you only want to check a major
* version.
*
* For each level that is checked the input has to be exactly the same as
* the actual version. Some examples:
*
* The if the version is 1.2.3 the following checks would return true:
* - 1 (only major version is checked)
* - 1.2 (only major and minor version are checked)
* - 1.2.3 (full version is checked)
*
* These values will return false:
* - 1.0 (lower)
* - 1.2.4 (higher)
*
*
* @internal a string compare is used instead of version_compare because
* version_compare returns false for a compare of 1.0.0 with 1.0
*
* @param string $version
* @return boolean
*/
static public function checkExact($version)
{
return (substr(self::VERSION,0,strlen($version)) == $version);
}
/**
* Check for a minimal version
*
* This method can check for all three versioning levels, but they are
* optional. If you only care for major and minor versions you can use
* something like '1.0' as input. Or '1' if you only want to check a major
* version.
*
* For each level that is checked the actual value needs to be the same or
* higher. Some examples:
*
* The if the version is 1.2.3 the following checks would return true:
* - 1.2.3 (the same)
* - 1 (the actual version is higher)
*
* These values will return false:
* - 2 (the actual version is lower)
* - 1.3 (the actual version is lower)
*
* @param string $version
* @return boolean
*/
static public function checkMinimal($version)
{
return version_compare(self::VERSION, $version, '>=');
}
}
\ No newline at end of file
......@@ -38,4 +38,62 @@ class Solarium_VersionTest extends PHPUnit_Framework_TestCase
$this->assertNotNull($version);
}
public function testCheckExact()
{
$this->assertTrue(
Solarium_Version::checkExact(Solarium_Version::VERSION)
);
}
public function testCheckExactPartial()
{
$this->assertTrue(
Solarium_Version::checkExact(substr(Solarium_Version::VERSION,0,1))
);
}
public function testCheckExactLower()
{
$this->assertFalse(
Solarium_Version::checkExact('0.1')
);
}
public function testCheckExactHigher()
{
$this->assertFalse(
Solarium_Version::checkExact('99.0')
);
}
public function testCheckMinimal()
{
$this->assertTrue(
Solarium_Version::checkMinimal(Solarium_Version::VERSION)
);
}
public function testCheckMinimalPartial()
{
$version = substr(Solarium_Version::VERSION,0,1);
$this->assertTrue(
Solarium_Version::checkMinimal($version)
);
}
public function testCheckMinimalLower()
{
$this->assertTrue(
Solarium_Version::checkMinimal('0.1.0')
);
}
public function testCheckMinimalHigher()
{
$this->assertFalse(
Solarium_Version::checkMinimal('99.0')
);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment