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

View File

@ -25,7 +25,7 @@ class DeprecationTest extends SapphireTest {
function testLesserVersionTriggersNoNotice() { function testLesserVersionTriggersNoNotice() {
Deprecation::notification_version('1.0.0'); Deprecation::notification_version('1.0.0');
Deprecation::notice('2.0.0', 'Deprecation test failed'); Deprecation::notice('2.0', 'Deprecation test failed');
} }
/** /**
@ -36,12 +36,18 @@ class DeprecationTest extends SapphireTest {
Deprecation::notice('2.0.0', 'Deprecation test passed'); 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 * @expectedException PHPUnit_Framework_Error_Notice
*/ */
function testGreaterVersionTriggersNotice() { function testGreaterVersionTriggersNotice() {
Deprecation::notification_version('3.0.0'); Deprecation::notification_version('3.0.0');
Deprecation::notice('2.0.0', 'Deprecation test passed'); Deprecation::notice('2.0', 'Deprecation test passed');
} }
function testNonMatchingModuleNotifcationVersionDoesntAffectNotice() { function testNonMatchingModuleNotifcationVersionDoesntAffectNotice() {
@ -61,7 +67,7 @@ class DeprecationTest extends SapphireTest {
protected function callThatOriginatesFromSapphire() { protected function callThatOriginatesFromSapphire() {
$this->assertEquals(DeprecationTest_Deprecation::get_module(), 'sapphire'); $this->assertEquals(DeprecationTest_Deprecation::get_module(), 'sapphire');
Deprecation::notice('2.0.0', 'Deprecation test passed'); Deprecation::notice('2.0', 'Deprecation test passed');
} }
function testMethodNameCalculation() { function testMethodNameCalculation() {