Skip to content

Commit

Permalink
API Stop using deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 2, 2022
1 parent e454db6 commit d10acbf
Show file tree
Hide file tree
Showing 39 changed files with 100 additions and 117 deletions.
2 changes: 1 addition & 1 deletion src/Control/Director.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static function mockRequest(
? $cookies
: Injector::inst()->createWithArgs(Cookie_Backend::class, [$cookies ?: []]);
$newVars['_COOKIE'] = $cookieJar->getAll(false);
Cookie::config()->update('report_errors', false);
Cookie::config()->set('report_errors', false);
Injector::inst()->registerService($cookieJar, Cookie_Backend::class);

// Backup requirements
Expand Down
8 changes: 6 additions & 2 deletions src/Control/Middleware/FlushMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace SilverStripe\Control\Middleware;

use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\BaseKernel;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Flushable;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Kernel;

/**
* Triggers a call to flush() on all implementors of Flushable.
Expand All @@ -14,7 +16,9 @@ class FlushMiddleware implements HTTPMiddleware
{
public function process(HTTPRequest $request, callable $delegate)
{
if (Director::isManifestFlushed()) {
/** @var BaseKernel $kernel */
$kernel = Injector::inst()->get(Kernel::class);
if ((method_exists($kernel, 'isFlushed') && $kernel->isFlushed())) {
// Disable cache when flushing
HTTPCacheControlMiddleware::singleton()->disableCache(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace SilverStripe\Control\Middleware\URLSpecialsMiddleware;

use SilverStripe\Core\BaseKernel;
use SilverStripe\Core\Kernel;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Startup\ScheduledFlushDiscoverer;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;

/**
Expand All @@ -30,11 +30,12 @@ public function scheduleFlush(HTTPRequest $request)
{
$flush = array_key_exists('flush', $request->getVars() ?? []) || ($request->getURL() === 'dev/build');

if (!$flush || Director::isManifestFlushed()) {
/** @var BaseKernel $kernel */
$kernel = Injector::inst()->get(Kernel::class);
if (!$flush || (method_exists($kernel, 'isFlushed') && $kernel->isFlushed())) {
return false;
}

$kernel = Injector::inst()->get(Kernel::class);
ScheduledFlushDiscoverer::scheduleFlush($kernel);

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/Control/RSS/RSSFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function Description()
public function outputToBrowser()
{
$prevState = SSViewer::config()->uninherited('source_file_comments');
SSViewer::config()->update('source_file_comments', false);
SSViewer::config()->set('source_file_comments', false);

$response = Controller::curr()->getResponse();

Expand All @@ -236,7 +236,7 @@ public function outputToBrowser()

$response->addHeader("Content-Type", "application/rss+xml; charset=utf-8");

SSViewer::config()->update('source_file_comments', $prevState);
SSViewer::config()->set('source_file_comments', $prevState);
return $this->renderWith($this->getTemplates());
}

Expand Down
6 changes: 0 additions & 6 deletions src/Core/BaseKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,9 @@ protected function bootErrorHandling()
* Get the environment type
*
* @return string
*
* @deprecated 4.12.0 Use Director::get_environment_type() instead
*/
public function getEnvironment()
{
Deprecation::notice('4.12.0', 'Use Director::get_environment_type() instead');
// Check set
if ($this->enviroment) {
return $this->enviroment;
Expand All @@ -288,12 +285,9 @@ public function getEnvironment()
* Check or update any temporary environment specified in the session.
*
* @return null|string
*
* @deprecated 4.12.0 Use Director::get_session_environment_type() instead
*/
protected function sessionEnvironment()
{
Deprecation::notice('4.12.0', 'Use Director::get_session_environment_type() instead');
if (!$this->booted) {
// session is not initialyzed yet, neither is manifest
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Dev/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static function get_enabled()
// noop
}

private static function get_is_enabled(): bool
public static function get_is_enabled(): bool
{
if (!Director::isDev()) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/Dev/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function setUp(): void

// Disable theme, if necessary
if (static::get_disable_themes()) {
SSViewer::config()->update('theme_enabled', false);
SSViewer::config()->set('theme_enabled', false);
}

// Flush user
Expand Down Expand Up @@ -560,7 +560,7 @@ protected function setUp()

// Disable theme, if necessary
if (static::get_disable_themes()) {
SSViewer::config()->update('theme_enabled', false);
SSViewer::config()->set('theme_enabled', false);
}

// Flush user
Expand Down
12 changes: 6 additions & 6 deletions src/Dev/SapphireTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ protected function setUp(): void
}

if (class_exists(Cookie::class)) {
Cookie::config()->update('report_errors', false);
Cookie::config()->set('report_errors', false);
}

if (class_exists(RootURLController::class)) {
Expand All @@ -356,7 +356,7 @@ protected function setUp(): void

// turn off template debugging
if (class_exists(SSViewer::class)) {
SSViewer::config()->update('source_file_comments', false);
SSViewer::config()->set('source_file_comments', false);
}

// Set up the test mailer
Expand Down Expand Up @@ -1206,7 +1206,7 @@ protected function useTestTheme($themeBaseDir, $theme, $callback)
if (strpos($themeBaseDir ?? '', BASE_PATH) === 0) {
$themeBaseDir = substr($themeBaseDir ?? '', strlen(BASE_PATH));
}
SSViewer::config()->update('theme_enabled', true);
SSViewer::config()->set('theme_enabled', true);
SSViewer::set_themes([$themeBaseDir . '/themes/' . $theme, '$default']);

try {
Expand Down Expand Up @@ -1649,7 +1649,7 @@ protected function setUp()
}

if (class_exists(Cookie::class)) {
Cookie::config()->update('report_errors', false);
Cookie::config()->set('report_errors', false);
}

if (class_exists(RootURLController::class)) {
Expand All @@ -1676,7 +1676,7 @@ protected function setUp()

// turn off template debugging
if (class_exists(SSViewer::class)) {
SSViewer::config()->update('source_file_comments', false);
SSViewer::config()->set('source_file_comments', false);
}

// Set up the test mailer
Expand Down Expand Up @@ -2556,7 +2556,7 @@ protected function useTestTheme($themeBaseDir, $theme, $callback)
if (strpos($themeBaseDir ?? '', BASE_PATH) === 0) {
$themeBaseDir = substr($themeBaseDir ?? '', strlen(BASE_PATH));
}
SSViewer::config()->update('theme_enabled', true);
SSViewer::config()->set('theme_enabled', true);
SSViewer::set_themes([$themeBaseDir . '/themes/' . $theme, '$default']);

try {
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/GridField/GridFieldAddExistingAutocompleter.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function doSearch($gridField, $request)

$json = [];
Config::nest();
SSViewer::config()->update('source_file_comments', false);
SSViewer::config()->set('source_file_comments', false);
$viewer = SSViewer::fromString($this->resultsFormat);
foreach ($results as $result) {
$title = Convert::html2raw($viewer->process($result));
Expand Down
3 changes: 0 additions & 3 deletions src/ORM/Connect/DBSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,9 @@ abstract class DBSchemaManager
/**
* @param string $table
* @param string $class
*
* @deprecated 4.0.1 Will be removed without equivalent functionality
*/
public static function showTableNameWarning($table, $class)
{
Deprecation::notice('4.0.1', 'Will be removed without equivalent functionality');
static::$table_name_warnings[$table] = $class;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/php/Control/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ControllerTest extends FunctionalTest
protected function setUp(): void
{
parent::setUp();
Director::config()->update('alternate_base_url', '/');
Director::config()->set('alternate_base_url', '/');

// Add test theme
$themeDir = substr(__DIR__, strlen(FRAMEWORK_DIR)) . '/ControllerTest/';
Expand Down
4 changes: 4 additions & 0 deletions tests/php/Control/DirectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Environment;
use SilverStripe\Core\Kernel;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;

/**
Expand Down Expand Up @@ -856,6 +857,9 @@ public function testTestIgnoresHashes()

public function testRequestFilterInDirectorTest()
{
if (Deprecation::get_is_enabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$filter = new DirectorTest\TestRequestFilter;

$processor = new RequestProcessor([$filter]);
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Control/Email/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function testGetSwiftMessage()

public function testSetSwiftMessage()
{
Email::config()->update('admin_email', '[email protected]');
Email::config()->set('admin_email', '[email protected]');
DBDatetime::set_mock_now('2017-01-01 07:00:00');
$email = new Email();
$swiftMessage = new Swift_Message();
Expand All @@ -294,7 +294,7 @@ public function testSetSwiftMessage()

public function testAdminEmailApplied()
{
Email::config()->update('admin_email', '[email protected]');
Email::config()->set('admin_email', '[email protected]');
$email = new Email();

$this->assertCount(1, $email->getFrom());
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Control/Email/SwiftMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testSwiftMailer()
$this->assertEquals($swift, $mailer->getSwiftMailer());

SwiftMailer::config()->remove('swift_plugins');
SwiftMailer::config()->update('swift_plugins', [Swift_Plugins_AntiFloodPlugin::class]);
SwiftMailer::config()->merge('swift_plugins', [Swift_Plugins_AntiFloodPlugin::class]);

/** @var Swift_MailTransport $transport */
$transport = $this->getMockBuilder(Swift_MailTransport::class)->getMock();
Expand Down
8 changes: 4 additions & 4 deletions tests/php/Control/Email/SwiftPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function getMailer()

public function testSendAllEmailsTo()
{
Email::config()->update('send_all_emails_to', '[email protected]');
Email::config()->set('send_all_emails_to', '[email protected]');
$email = $this->getEmail();
$this->getMailer()->send($email->getSwiftMessage());
$headers = $email->getSwiftMessage()->getHeaders();
Expand Down Expand Up @@ -68,7 +68,7 @@ public function testSendAllEmailsTo()

public function testSendAllEmailsFrom()
{
Email::config()->update('send_all_emails_from', '[email protected]');
Email::config()->set('send_all_emails_from', '[email protected]');
$email = $this->getEmail();
$this->getMailer()->send($email->getSwiftMessage());

Expand All @@ -88,7 +88,7 @@ public function testSendAllEmailsFrom()

public function testCCAllEmailsTo()
{
Email::config()->update('cc_all_emails_to', '[email protected]');
Email::config()->set('cc_all_emails_to', '[email protected]');
$email = $this->getEmail();
$this->getMailer()->send($email->getSwiftMessage());

Expand All @@ -99,7 +99,7 @@ public function testCCAllEmailsTo()

public function testBCCAllEmailsTo()
{
Email::config()->update('bcc_all_emails_to', '[email protected]');
Email::config()->set('bcc_all_emails_to', '[email protected]');
$email = $this->getEmail();
$this->getMailer()->send($email->getSwiftMessage());

Expand Down
7 changes: 7 additions & 0 deletions tests/php/Control/HTTPRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Middleware\TrustedProxyMiddleware;
use SilverStripe\Control\Session;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;

class HTTPRequestTest extends SapphireTest
Expand Down Expand Up @@ -155,12 +156,18 @@ public function detectMethodDataProvider()
*/
public function testDetectMethod($realMethod, $post, $expected)
{
if (Deprecation::get_is_enabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$actual = HTTPRequest::detect_method($realMethod, $post);
$this->assertEquals($expected, $actual);
}

public function testBadDetectMethod()
{
if (Deprecation::get_is_enabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$this->expectException(\InvalidArgumentException::class);
HTTPRequest::detect_method('POST', ['_method' => 'Boom']);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Control/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testStartUsesSecureCookieNameWithHttpsAndCookieSecureOn()
->setScheme('https');
Cookie::set(session_name(), '1234');
$session = new Session(null); // unstarted session
$session->config()->update('cookie_secure', true);
$session->config()->set('cookie_secure', true);
$session->start($req);
$this->assertEquals(session_name(), $session->config()->get('cookie_name_secure'));
}
Expand Down Expand Up @@ -270,7 +270,7 @@ public function testRequestContainsSessionIdRespectsCookieNameSecure()
->setScheme('https');
$session = new Session(null); // unstarted session
Cookie::set($session->config()->get('cookie_name_secure'), '1234');
$session->config()->update('cookie_secure', true);
$session->config()->set('cookie_secure', true);
$this->assertTrue($session->requestContainsSessionId($req));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/php/Core/ConvertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function testJSON2Obj()
*/
public function testRaw2URL()
{
URLSegmentFilter::config()->update('default_allow_multibyte', false);
URLSegmentFilter::config()->set('default_allow_multibyte', false);
$this->assertEquals('foo', Convert::raw2url('foo'));
$this->assertEquals('foo-and-bar', Convert::raw2url('foo & bar'));
$this->assertEquals('foo-and-bar', Convert::raw2url('foo & bar!'));
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Dev/BacktraceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testIgnoredFunctionArgs()
'args' => ['myarg' => 'myval']
]
];
Backtrace::config()->update(
Backtrace::config()->merge(
'ignore_function_args',
[
['MyClass', 'myIgnoredClassFunction'],
Expand Down Expand Up @@ -101,7 +101,7 @@ public function testFilteredWildCard()
'args' => ['myarg' => 'myval']
]
];
Backtrace::config()->update(
Backtrace::config()->merge(
'ignore_function_args',
[
['*', 'myIgnoredClassFunction'],
Expand Down
7 changes: 6 additions & 1 deletion tests/php/Dev/DeprecationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ class DeprecationTest extends SapphireTest

private $oldHandler = null;

private bool $noticesWereEnabled = false;

protected function setup(): void
{
// Use custom error handler for two reasons:
// - Filter out errors for deprecated class properities unrelated to this unit test
// - Allow the use of expectDeprecation(), which doesn't work with E_USER_DEPRECATION by default
// https://github.com/laminas/laminas-di/pull/30#issuecomment-927585210
parent::setup();
$this->noticesWereEnabled = Deprecation::get_is_enabled();
$this->oldHandler = set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
if ($errno === E_USER_DEPRECATED) {
if (str_contains($errstr, 'SilverStripe\\Dev\\Tests\\DeprecationTest')) {
Expand All @@ -42,7 +45,9 @@ protected function setup(): void

protected function tearDown(): void
{
Deprecation::disable();
if (!$this->noticesWereEnabled) {
Deprecation::disable();
}
set_error_handler($this->oldHandler);
$this->oldHandler = null;
parent::tearDown();
Expand Down
Loading

0 comments on commit d10acbf

Please sign in to comment.