2011-10-27 23:45:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class DeprecationTest_Deprecation extends Deprecation {
|
|
|
|
public static function get_module() {
|
|
|
|
return self::get_calling_module_from_trace(debug_backtrace(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_method() {
|
|
|
|
return self::get_called_method_from_trace(debug_backtrace(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DeprecationTest extends SapphireTest {
|
|
|
|
|
|
|
|
static $originalVersionInfo;
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setUp() {
|
2015-06-10 00:27:54 +02:00
|
|
|
parent::setUp();
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-10-27 23:45:12 +02:00
|
|
|
self::$originalVersionInfo = Deprecation::dump_settings();
|
|
|
|
Deprecation::$notice_level = E_USER_NOTICE;
|
2015-06-10 00:27:54 +02:00
|
|
|
Deprecation::set_enabled(true);
|
2011-10-27 23:45:12 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function tearDown() {
|
2011-10-27 23:45:12 +02:00
|
|
|
Deprecation::restore_settings(self::$originalVersionInfo);
|
2015-06-10 00:27:54 +02:00
|
|
|
parent::tearDown();
|
2011-10-27 23:45:12 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testLesserVersionTriggersNoNotice() {
|
2011-10-27 23:45:12 +02:00
|
|
|
Deprecation::notification_version('1.0.0');
|
2012-11-23 14:55:19 +01:00
|
|
|
$this->assertNull(Deprecation::notice('2.0', 'Deprecation test failed'));
|
2011-10-27 23:45:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-14 02:43:45 +01:00
|
|
|
* @expectedException PHPUnit_Framework_Error
|
2011-10-27 23:45:12 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testEqualVersionTriggersNotice() {
|
2011-10-27 23:45:12 +02:00
|
|
|
Deprecation::notification_version('2.0.0');
|
|
|
|
Deprecation::notice('2.0.0', 'Deprecation test passed');
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testBetaVersionDoesntTriggerNoticeWhenDeprecationDoesntSpecifyReleasenum() {
|
2011-10-29 00:59:41 +02:00
|
|
|
Deprecation::notification_version('2.0.0-beta1');
|
2012-11-23 14:55:19 +01:00
|
|
|
$this->assertNull(Deprecation::notice('2.0', 'Deprecation test failed'));
|
|
|
|
$this->assertNull(Deprecation::notice('2.0.0', 'Deprecation test failed'));
|
2011-10-29 00:59:41 +02:00
|
|
|
}
|
|
|
|
|
2011-10-27 23:45:12 +02:00
|
|
|
/**
|
2012-03-14 02:43:45 +01:00
|
|
|
* @expectedException PHPUnit_Framework_Error
|
2011-10-27 23:45:12 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testGreaterVersionTriggersNotice() {
|
2011-10-27 23:45:12 +02:00
|
|
|
Deprecation::notification_version('3.0.0');
|
2011-10-29 00:59:41 +02:00
|
|
|
Deprecation::notice('2.0', 'Deprecation test passed');
|
2011-10-27 23:45:12 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testNonMatchingModuleNotifcationVersionDoesntAffectNotice() {
|
2011-10-27 23:45:12 +02:00
|
|
|
Deprecation::notification_version('1.0.0');
|
2012-04-14 03:25:40 +02:00
|
|
|
global $project;
|
|
|
|
Deprecation::notification_version('3.0.0', $project);
|
2012-03-24 04:38:57 +01:00
|
|
|
$this->callThatOriginatesFromFramework();
|
2011-10-27 23:45:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-14 02:43:45 +01:00
|
|
|
* @expectedException PHPUnit_Framework_Error
|
2011-10-27 23:45:12 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testMatchingModuleNotifcationVersionAffectsNotice() {
|
2011-10-27 23:45:12 +02:00
|
|
|
Deprecation::notification_version('1.0.0');
|
2012-04-14 03:25:40 +02:00
|
|
|
Deprecation::notification_version('3.0.0', FRAMEWORK_DIR);
|
2012-03-24 04:38:57 +01:00
|
|
|
$this->callThatOriginatesFromFramework();
|
2011-10-27 23:45:12 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testMethodNameCalculation() {
|
2012-07-13 11:37:35 +02:00
|
|
|
$this->assertEquals(DeprecationTest_Deprecation::get_method(), 'DeprecationTest->testMethodNameCalculation');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException PHPUnit_Framework_Error
|
|
|
|
* @expectedExceptionMessage DeprecationTest->testScopeMethod is deprecated. Method scope
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testScopeMethod() {
|
2012-07-13 11:37:35 +02:00
|
|
|
Deprecation::notification_version('2.0.0');
|
|
|
|
Deprecation::notice('2.0.0', 'Method scope', Deprecation::SCOPE_METHOD);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException PHPUnit_Framework_Error
|
|
|
|
* @expectedExceptionMessage DeprecationTest is deprecated. Class scope
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testScopeClass() {
|
2012-07-13 11:37:35 +02:00
|
|
|
Deprecation::notification_version('2.0.0');
|
|
|
|
Deprecation::notice('2.0.0', 'Class scope', Deprecation::SCOPE_CLASS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException PHPUnit_Framework_Error
|
|
|
|
* @expectedExceptionMessage Global scope
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testScopeGlobal() {
|
2012-07-13 11:37:35 +02:00
|
|
|
Deprecation::notification_version('2.0.0');
|
|
|
|
Deprecation::notice('2.0.0', 'Global scope', Deprecation::SCOPE_GLOBAL);
|
|
|
|
}
|
|
|
|
|
2012-03-24 04:38:57 +01:00
|
|
|
protected function callThatOriginatesFromFramework() {
|
2012-04-14 03:25:40 +02:00
|
|
|
$this->assertEquals(DeprecationTest_Deprecation::get_module(), FRAMEWORK_DIR);
|
2012-11-23 14:55:19 +01:00
|
|
|
$this->assertNull(Deprecation::notice('2.0', 'Deprecation test passed'));
|
2011-10-27 23:45:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|