MNT Resolve deprecation warnings in tests (#11364)

This commit is contained in:
Guy Sartorelli 2024-09-11 12:16:59 +12:00 committed by GitHub
parent 9e6ecde87c
commit de515d3bbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 13 deletions

View File

@ -2,7 +2,7 @@
namespace SilverStripe\Core\Tests; namespace SilverStripe\Core\Tests;
use ReflectionProperty; use ReflectionClass;
use SilverStripe\Core\Environment; use SilverStripe\Core\Environment;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
@ -142,9 +142,8 @@ class EnvironmentTest extends SapphireTest
$this->assertSame($expected, Environment::hasEnv($name)); $this->assertSame($expected, Environment::hasEnv($name));
// unset the value // unset the value
$reflectionEnv = new ReflectionProperty(Environment::class, 'env'); $reflectionEnv = new ReflectionClass(Environment::class);
$reflectionEnv->setAccessible(true); $reflectionEnv->setStaticPropertyValue('env', array_diff($reflectionEnv->getStaticPropertyValue('env'), [$name => $value]));
$reflectionEnv->setValue(array_diff($reflectionEnv->getValue(), [$name => $value]));
unset($_ENV[$name]); unset($_ENV[$name]);
unset($_SERVER[$name]); unset($_SERVER[$name]);
putenv("$name"); putenv("$name");

View File

@ -3,7 +3,7 @@
namespace SilverStripe\Core\Tests; namespace SilverStripe\Core\Tests;
use BadMethodCallException; use BadMethodCallException;
use ReflectionProperty; use ReflectionClass;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Tests\ExtensionTest\NamedExtension; use SilverStripe\Core\Tests\ExtensionTest\NamedExtension;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
@ -15,9 +15,8 @@ class ExtensionTest extends SapphireTest
{ {
parent::setUp(); parent::setUp();
// Reset extra_methods so that when we set NamedExtension to null it re-evaluates which methods are available // Reset extra_methods so that when we set NamedExtension to null it re-evaluates which methods are available
$reflectionProperty = new ReflectionProperty(DataObject::class, 'extra_methods'); $reflectionClass = new ReflectionClass(DataObject::class);
$reflectionProperty->setAccessible(true); $reflectionClass->setStaticPropertyValue('extra_methods', []);
$reflectionProperty->setValue([]);
// Add named extension config like we would in yaml // Add named extension config like we would in yaml
Config::modify()->merge(DataObject::class, 'extensions', ['NamedExtension' => NamedExtension::class]); Config::modify()->merge(DataObject::class, 'extensions', ['NamedExtension' => NamedExtension::class]);
} }

View File

@ -3,8 +3,8 @@
namespace SilverStripe\Logging\Tests; namespace SilverStripe\Logging\Tests;
use Monolog\Handler\HandlerInterface; use Monolog\Handler\HandlerInterface;
use ReflectionClass;
use ReflectionMethod; use ReflectionMethod;
use ReflectionProperty;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\Deprecation;
@ -156,8 +156,7 @@ class HTTPOutputHandlerTest extends SapphireTest
) { ) {
$reflectionShouldShow = new ReflectionMethod(HTTPOutputHandler::class, 'shouldShowError'); $reflectionShouldShow = new ReflectionMethod(HTTPOutputHandler::class, 'shouldShowError');
$reflectionShouldShow->setAccessible(true); $reflectionShouldShow->setAccessible(true);
$reflectionTriggeringError = new ReflectionProperty(Deprecation::class, 'isTriggeringError'); $reflectionDeprecation = new ReflectionClass(Deprecation::class);
$reflectionTriggeringError->setAccessible(true);
$cliShouldShowOrig = Deprecation::shouldShowForCli(); $cliShouldShowOrig = Deprecation::shouldShowForCli();
$httpShouldShowOrig = Deprecation::shouldShowForHttp(); $httpShouldShowOrig = Deprecation::shouldShowForHttp();
@ -171,7 +170,7 @@ class HTTPOutputHandlerTest extends SapphireTest
Deprecation::setShouldShowForCli(true); Deprecation::setShouldShowForCli(true);
Deprecation::setShouldShowForHttp($shouldShow); Deprecation::setShouldShowForHttp($shouldShow);
} }
$reflectionTriggeringError->setValue($triggeringError); $reflectionDeprecation->setStaticPropertyValue('isTriggeringError', $triggeringError);
$mockHandler = $this->getMockBuilder(HTTPOutputHandler::class)->onlyMethods(['isCli'])->getMock(); $mockHandler = $this->getMockBuilder(HTTPOutputHandler::class)->onlyMethods(['isCli'])->getMock();
$mockHandler->method('isCli')->willReturn($isCli); $mockHandler->method('isCli')->willReturn($isCli);
@ -181,6 +180,6 @@ class HTTPOutputHandlerTest extends SapphireTest
Deprecation::setShouldShowForCli($cliShouldShowOrig); Deprecation::setShouldShowForCli($cliShouldShowOrig);
Deprecation::setShouldShowForHttp($httpShouldShowOrig); Deprecation::setShouldShowForHttp($httpShouldShowOrig);
$reflectionTriggeringError->setValue($triggeringErrorOrig); $reflectionDeprecation->setStaticPropertyValue('isTriggeringError', $triggeringErrorOrig);
} }
} }