2011-10-27 23:45:12 +02:00
|
|
|
<?php
|
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Dev\Tests;
|
|
|
|
|
|
|
|
use PHPUnit_Framework_Error;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\Deprecation;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2016-10-14 03:30:05 +02:00
|
|
|
use SilverStripe\Dev\Tests\DeprecationTest\TestDeprecation;
|
2011-10-27 23:45:12 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class DeprecationTest extends SapphireTest
|
|
|
|
{
|
2011-10-27 23:45:12 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
static $originalVersionInfo;
|
2011-10-27 23:45:12 +02:00
|
|
|
|
2017-03-24 04:00:54 +01:00
|
|
|
protected function setUp()
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
self::$originalVersionInfo = Deprecation::dump_settings();
|
|
|
|
Deprecation::$notice_level = E_USER_NOTICE;
|
|
|
|
Deprecation::set_enabled(true);
|
|
|
|
}
|
2011-10-27 23:45:12 +02:00
|
|
|
|
2017-03-24 04:00:54 +01:00
|
|
|
protected function tearDown()
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
Deprecation::restore_settings(self::$originalVersionInfo);
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
2011-10-27 23:45:12 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testLesserVersionTriggersNoNotice()
|
|
|
|
{
|
|
|
|
Deprecation::notification_version('1.0.0');
|
|
|
|
$this->assertNull(Deprecation::notice('2.0', 'Deprecation test failed'));
|
|
|
|
}
|
2011-10-27 23:45:12 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
2012-03-14 02:43:45 +01:00
|
|
|
* @expectedException PHPUnit_Framework_Error
|
2016-12-16 05:34:21 +01:00
|
|
|
*/
|
|
|
|
public function testEqualVersionTriggersNotice()
|
|
|
|
{
|
|
|
|
Deprecation::notification_version('2.0.0');
|
|
|
|
Deprecation::notice('2.0.0', 'Deprecation test passed');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBetaVersionDoesntTriggerNoticeWhenDeprecationDoesntSpecifyReleasenum()
|
|
|
|
{
|
|
|
|
Deprecation::notification_version('2.0.0-beta1');
|
|
|
|
$this->assertNull(Deprecation::notice('2.0', 'Deprecation test failed'));
|
|
|
|
$this->assertNull(Deprecation::notice('2.0.0', 'Deprecation test failed'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-14 02:43:45 +01:00
|
|
|
* @expectedException PHPUnit_Framework_Error
|
2016-12-16 05:34:21 +01:00
|
|
|
*/
|
|
|
|
public function testGreaterVersionTriggersNotice()
|
|
|
|
{
|
|
|
|
Deprecation::notification_version('3.0.0');
|
|
|
|
Deprecation::notice('2.0', 'Deprecation test passed');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNonMatchingModuleNotifcationVersionDoesntAffectNotice()
|
|
|
|
{
|
|
|
|
Deprecation::notification_version('1.0.0');
|
|
|
|
global $project;
|
|
|
|
Deprecation::notification_version('3.0.0', $project);
|
|
|
|
$this->callThatOriginatesFromFramework();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-14 02:43:45 +01:00
|
|
|
* @expectedException PHPUnit_Framework_Error
|
2016-12-16 05:34:21 +01:00
|
|
|
*/
|
|
|
|
public function testMatchingModuleNotifcationVersionAffectsNotice()
|
|
|
|
{
|
|
|
|
Deprecation::notification_version('1.0.0');
|
|
|
|
Deprecation::notification_version('3.0.0', FRAMEWORK_DIR);
|
|
|
|
$this->callThatOriginatesFromFramework();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMethodNameCalculation()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
TestDeprecation::get_method(),
|
|
|
|
static::class.'->testMethodNameCalculation'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException PHPUnit_Framework_Error
|
|
|
|
* @expectedExceptionMessage DeprecationTest->testScopeMethod is deprecated. Method scope
|
|
|
|
*/
|
|
|
|
public function testScopeMethod()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public function testScopeClass()
|
|
|
|
{
|
|
|
|
Deprecation::notification_version('2.0.0');
|
|
|
|
Deprecation::notice('2.0.0', 'Class scope', Deprecation::SCOPE_CLASS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException PHPUnit_Framework_Error
|
|
|
|
* @expectedExceptionMessage Global scope
|
|
|
|
*/
|
|
|
|
public function testScopeGlobal()
|
|
|
|
{
|
|
|
|
Deprecation::notification_version('2.0.0');
|
|
|
|
Deprecation::notice('2.0.0', 'Global scope', Deprecation::SCOPE_GLOBAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function callThatOriginatesFromFramework()
|
|
|
|
{
|
2017-03-14 03:20:51 +01:00
|
|
|
$this->assertEquals('silverstripe/framework', TestDeprecation::get_module()->getName());
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertNull(Deprecation::notice('2.0', 'Deprecation test passed'));
|
|
|
|
}
|
2011-10-27 23:45:12 +02:00
|
|
|
}
|