ENHANCEMENT: Allow Deprecation::notice() to be called without passing release number.

This commit is contained in:
Sam Minnee 2011-10-29 11:59:41 +13:00
parent 95b6490ffa
commit 4c93c3be19
2 changed files with 13 additions and 4 deletions

View File

@ -110,6 +110,9 @@ class Deprecation {
public static function notice($atVersion, $string = '') {
if(!Director::isDev()) return;
// If you pass #.#, assume #.#.0
if(preg_match('/^[0-9]+\.[0-9]+$/', $atVersion)) $atVersion .= '.0';
$checkVersion = self::$version;
// Getting a backtrace is slow, so we only do it if we need it
$backtrace = null;

View File

@ -25,23 +25,29 @@ class DeprecationTest extends SapphireTest {
function testLesserVersionTriggersNoNotice() {
Deprecation::notification_version('1.0.0');
Deprecation::notice('2.0.0', 'Deprecation test failed');
Deprecation::notice('2.0', 'Deprecation test failed');
}
/**
* @expectedException PHPUnit_Framework_Error_Notice
* @expectedException PHPUnit_Framework_Error_Notice
*/
function testEqualVersionTriggersNotice() {
Deprecation::notification_version('2.0.0');
Deprecation::notice('2.0.0', 'Deprecation test passed');
}
function testBetaVersionDoesntTriggerNoticeWhenDeprecationDoesntSpecifyReleasenum() {
Deprecation::notification_version('2.0.0-beta1');
Deprecation::notice('2.0', 'Deprecation test failed');
Deprecation::notice('2.0.0', 'Deprecation test failed');
}
/**
* @expectedException PHPUnit_Framework_Error_Notice
*/
function testGreaterVersionTriggersNotice() {
Deprecation::notification_version('3.0.0');
Deprecation::notice('2.0.0', 'Deprecation test passed');
Deprecation::notice('2.0', 'Deprecation test passed');
}
function testNonMatchingModuleNotifcationVersionDoesntAffectNotice() {
@ -61,7 +67,7 @@ class DeprecationTest extends SapphireTest {
protected function callThatOriginatesFromSapphire() {
$this->assertEquals(DeprecationTest_Deprecation::get_module(), 'sapphire');
Deprecation::notice('2.0.0', 'Deprecation test passed');
Deprecation::notice('2.0', 'Deprecation test passed');
}
function testMethodNameCalculation() {