From 183585910c9f3387f06420712b55bf3effe32de3 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 9 Sep 2024 17:45:55 +1200 Subject: [PATCH] DEP Use PHPUnit 11 --- composer.json | 6 +- src/Core/Manifest/ClassManifest.php | 2 +- .../Manifest/ClassManifestErrorHandler.php | 2 +- src/Dev/Constraint/SSListContains.php | 5 - .../SSListContainsOnlyMatchingItems.php | 5 - src/Dev/SSListExporter.php | 85 -------------- src/Dev/SapphireTest.php | 30 +++-- tests/php/Control/ControllerTest.php | 2 +- tests/php/Control/DirectorTest.php | 104 ++++++++---------- tests/php/Control/Email/EmailTest.php | 6 +- tests/php/Control/HTTPRequestTest.php | 29 ++++- .../HTTPRequestTestException.php | 10 ++ tests/php/Control/HTTPResponseTest.php | 4 +- .../Middleware/CanonicalURLMiddlewareTest.php | 4 +- .../HTTPCacheControlMiddlewareTest.php | 2 +- tests/php/Control/RequestHandlerTest.php | 34 +++++- .../RequestHandlerTestExcpetion.php | 10 ++ tests/php/Control/SessionTest.php | 2 +- .../Core/Cache/DefaultCacheFactoryTest.php | 2 +- tests/php/Core/ClassInfoTest.php | 4 +- tests/php/Core/ConvertTest.php | 6 +- tests/php/Core/EnvironmentTest.php | 4 +- tests/php/Core/Injector/InjectorTest.php | 2 +- tests/php/Core/Manifest/ClassManifestTest.php | 2 +- .../php/Core/Manifest/ModuleManifestTest.php | 2 +- .../Core/Manifest/ThemeResourceLoaderTest.php | 2 +- tests/php/Core/PathTest.php | 6 +- .../Validation/ConstraintValidatorTest.php | 4 +- tests/php/Dev/BacktraceTest.php | 2 +- tests/php/Dev/CsvBulkLoaderTest.php | 2 +- tests/php/Dev/DeprecationTest.php | 63 +++++------ .../DeprecationTestException.php | 10 ++ tests/php/Dev/DevAdminControllerTest.php | 2 +- tests/php/Dev/SSListContainsOnlyTest.php | 4 +- tests/php/Dev/SSListContainsTest.php | 4 +- tests/php/Dev/SSListExporterTest.php | 86 --------------- tests/php/Dev/SapphireTestTest.php | 32 +++++- .../Dev/Validation/RelationValidationTest.php | 4 +- tests/php/Dev/ViewableDataContainsTest.php | 4 +- .../php/Forms/ConfirmedPasswordFieldTest.php | 8 +- tests/php/Forms/DropdownFieldTest.php | 2 +- tests/php/Forms/FieldsValidatorTest.php | 2 +- tests/php/Forms/FormFieldTest.php | 4 +- tests/php/Forms/FormScaffolderTest.php | 4 +- tests/php/Forms/FormSchemaTest.php | 2 +- tests/php/Forms/FormTest.php | 8 +- .../GridField/GridFieldDeleteActionTest.php | 4 +- .../GridField/GridFieldDetailFormTest.php | 6 +- .../Forms/GridField/GridFieldReadonlyTest.php | 2 +- .../Forms/HTMLEditor/HTMLEditorFieldTest.php | 2 +- .../HTMLEditor/HTMLEditorSanitiserTest.php | 2 +- tests/php/Forms/NumericFieldTest.php | 4 +- tests/php/Forms/PasswordFieldTest.php | 2 +- tests/php/Forms/RequiredFieldsTest.php | 2 +- .../php/Forms/SearchableDropdownTraitTest.php | 4 +- tests/php/Forms/UrlFieldTest.php | 2 +- tests/php/Logging/HTTPOutputHandlerTest.php | 2 +- tests/php/ORM/ArrayListTest.php | 18 +-- tests/php/ORM/Connect/DBQueryBuilderTest.php | 2 +- tests/php/ORM/DBDateTest.php | 2 +- tests/php/ORM/DBDatetimeTest.php | 2 +- tests/php/ORM/DBEnumTest.php | 2 +- tests/php/ORM/DBFieldTest.php | 2 +- tests/php/ORM/DBHTMLTextTest.php | 12 +- tests/php/ORM/DBSchemaManagerTest.php | 2 +- tests/php/ORM/DBTextTest.php | 14 +-- tests/php/ORM/DBTimeTest.php | 2 +- tests/php/ORM/DataListEagerLoadingTest.php | 18 +-- tests/php/ORM/DataListTest.php | 18 +-- tests/php/ORM/DataObjectSchemaTest.php | 6 +- tests/php/ORM/DataObjectTest.php | 4 +- tests/php/ORM/DataQueryTest.php | 35 +++++- .../DataQueryTest/DataQueryTestException.php | 10 ++ tests/php/ORM/EagerLoadedListTest.php | 36 +++--- tests/php/ORM/Filters/EndsWithFilterTest.php | 2 +- .../php/ORM/Filters/ExactMatchFilterTest.php | 4 +- .../php/ORM/Filters/GreaterThanFilterTest.php | 2 +- .../Filters/GreaterThanOrEqualFilterTest.php | 2 +- tests/php/ORM/Filters/LessThanFilterTest.php | 2 +- .../ORM/Filters/LessThanOrEqualFilterTest.php | 2 +- .../ORM/Filters/PartialMatchFilterTest.php | 2 +- .../php/ORM/Filters/StartsWithFilterTest.php | 2 +- tests/php/ORM/HasManyListTest.php | 2 +- tests/php/ORM/HierarchyCachingTest.php | 4 +- tests/php/ORM/ListDecoratorTest.php | 2 +- tests/php/ORM/ManyManyListTest.php | 2 +- tests/php/ORM/ManyManyThroughListTest.php | 8 +- tests/php/ORM/MySQLDatabaseTest.php | 2 +- tests/php/ORM/MySQLiConnectorTest.php | 2 +- tests/php/ORM/SQLSelectTest.php | 14 +-- .../php/ORM/Search/BasicSearchContextTest.php | 6 +- tests/php/ORM/UniqueKey/ServiceTest.php | 2 +- tests/php/Security/MemberTest.php | 2 +- tests/php/Security/Member_GroupSetTest.php | 2 +- tests/php/Security/RememberLoginHashTest.php | 4 +- tests/php/View/AttributesHTMLTest.php | 2 +- tests/php/View/Parsers/HTMLValueTest.php | 2 +- tests/php/View/Parsers/HtmlDiffTest.php | 2 +- .../php/View/Parsers/ShortcodeParserTest.php | 6 +- tests/php/View/SSViewerTest.php | 10 +- tests/php/View/ViewableDataTest.php | 2 +- tests/php/i18n/i18nTest.php | 2 +- 102 files changed, 447 insertions(+), 485 deletions(-) delete mode 100644 src/Dev/SSListExporter.php create mode 100644 tests/php/Control/HTTPRequestTest/HTTPRequestTestException.php create mode 100644 tests/php/Control/RequestHandlerTest/RequestHandlerTestExcpetion.php create mode 100644 tests/php/Dev/DeprecationTest/DeprecationTestException.php delete mode 100644 tests/php/Dev/SSListExporterTest.php create mode 100644 tests/php/ORM/DataQueryTest/DataQueryTestException.php diff --git a/composer.json b/composer.json index b25ea980d90..4e8fed3e73c 100644 --- a/composer.json +++ b/composer.json @@ -32,10 +32,10 @@ "m1/env": "^2.2.0", "masterminds/html5": "^2.7.6", "monolog/monolog": "^3.2.0", - "nikic/php-parser": "^4.15.0", + "nikic/php-parser": "^5.1.0", "psr/container": "^1.1 || ^2.0", "psr/http-message": "^1", - "sebastian/diff": "^4.0", + "sebastian/diff": "^6.0", "silverstripe/config": "^3", "silverstripe/assets": "^3", "silverstripe/vendor-plugin": "^2", @@ -63,7 +63,7 @@ }, "require-dev": { "composer/semver": "^3.4", - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^11.3", "silverstripe/versioned": "^3", "squizlabs/php_codesniffer": "^3.7", "silverstripe/standards": "^1", diff --git a/src/Core/Manifest/ClassManifest.php b/src/Core/Manifest/ClassManifest.php index 0e2887635ab..a89a38f75f6 100644 --- a/src/Core/Manifest/ClassManifest.php +++ b/src/Core/Manifest/ClassManifest.php @@ -302,7 +302,7 @@ public function init($includeTests = false, $forceRegen = false) public function getParser() { if (!$this->parser) { - $this->parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); + $this->parser = (new ParserFactory)->createForHostVersion(); } return $this->parser; diff --git a/src/Core/Manifest/ClassManifestErrorHandler.php b/src/Core/Manifest/ClassManifestErrorHandler.php index d077daa9388..0feb070e8c6 100644 --- a/src/Core/Manifest/ClassManifestErrorHandler.php +++ b/src/Core/Manifest/ClassManifestErrorHandler.php @@ -24,7 +24,7 @@ public function __construct($pathname) $this->pathname = $pathname; } - public function handleError(Error $error) + public function handleError(Error $error): void { $newMessage = sprintf('%s in %s', $error->getRawMessage(), $this->pathname); $error->setRawMessage($newMessage); diff --git a/src/Dev/Constraint/SSListContains.php b/src/Dev/Constraint/SSListContains.php index e9880ee22b6..c1dd4e5927b 100644 --- a/src/Dev/Constraint/SSListContains.php +++ b/src/Dev/Constraint/SSListContains.php @@ -4,7 +4,6 @@ use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\ExpectationFailedException; -use SilverStripe\Dev\SSListExporter; use SilverStripe\Dev\TestOnly; use SilverStripe\ORM\SS_List; use SilverStripe\View\ViewableData; @@ -20,8 +19,6 @@ class SSListContains extends Constraint implements TestOnly */ protected $matches = []; - protected SSListExporter $exporter; - /** * Check if the list has left over items that don't match * @@ -31,8 +28,6 @@ class SSListContains extends Constraint implements TestOnly public function __construct(array $matches) { - $this->exporter = new SSListExporter(); - $this->matches = $matches; } diff --git a/src/Dev/Constraint/SSListContainsOnlyMatchingItems.php b/src/Dev/Constraint/SSListContainsOnlyMatchingItems.php index a08b20f53cb..9824cc7a85e 100644 --- a/src/Dev/Constraint/SSListContainsOnlyMatchingItems.php +++ b/src/Dev/Constraint/SSListContainsOnlyMatchingItems.php @@ -4,7 +4,6 @@ use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\ExpectationFailedException; -use SilverStripe\Dev\SSListExporter; use SilverStripe\Dev\TestOnly; use SilverStripe\ORM\SS_List; @@ -19,8 +18,6 @@ class SSListContainsOnlyMatchingItems extends Constraint implements TestOnly */ private $match; - protected SSListExporter $exporter; - /** * @var ViewableDataContains */ @@ -28,8 +25,6 @@ class SSListContainsOnlyMatchingItems extends Constraint implements TestOnly public function __construct($match) { - $this->exporter = new SSListExporter(); - $this->constraint = new ViewableDataContains($match); $this->match = $match; } diff --git a/src/Dev/SSListExporter.php b/src/Dev/SSListExporter.php deleted file mode 100644 index 96293162f1d..00000000000 --- a/src/Dev/SSListExporter.php +++ /dev/null @@ -1,85 +0,0 @@ -contains($value)) !== false) { - return $className . ' &' . $key; - } - - $list = $value; - $key = $processed->add($value); - $values = ''; - - if ($list->count() > 0) { - foreach ($list as $k => $v) { - $values .= sprintf( - '%s %s ' . "\n", - $whitespace, - $this->recursiveExport($v, $indentation) - ); - } - - $values = "\n" . $values . $whitespace; - } - - return sprintf($className . ' &%s (%s)', $key, $values); - } - - if ($value instanceof ViewableData) { - $className = get_class($value); - $data = $this->toMap($value); - - return sprintf( - '%s %s => %s' . "\n", - $whitespace, - $className, - $this->recursiveExport($data, $indentation + 2, $processed) - ); - } - - - return parent::recursiveExport($value, $indentation, $processed); - } - - /** - * @param ViewableData $object - * @return array - */ - public function toMap(ViewableData $object) - { - return $object->hasMethod('toMap') - ? $object->toMap() - : []; - } -} diff --git a/src/Dev/SapphireTest.php b/src/Dev/SapphireTest.php index b54a58e5554..34c4aec05f3 100644 --- a/src/Dev/SapphireTest.php +++ b/src/Dev/SapphireTest.php @@ -41,6 +41,8 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mailer\Transport\NullTransport; +use ReflectionMethod; +use ReflectionClass; /** * Test case class for the Silverstripe framework. @@ -1212,16 +1214,30 @@ public static function createInvalidArgumentException($argument, $type, $value = } /** - * Returns the annotations for this test. - * - * @return array + * Returns the annotations for this test */ public function getAnnotations(): array { - return TestUtil::parseTestMethodAnnotations( - get_class($this), - $this->getName(false) - ); + $class = get_class($this); + $method = $this->name(); + $ret = []; + foreach (['method', 'class'] as $what) { + if ($what === 'method') { + $reflection = new ReflectionMethod($class, $method); + } else { + $reflection = new ReflectionClass($class); + } + preg_match_all('#@(.*?)\n#s', $reflection->getDocComment(), $annotations); + $ret[$what] = []; + foreach ($annotations[1] as $annotation) { + $parts = explode(' ', $annotation); + $key = array_shift($parts); + $value = implode(' ', $parts); + $ret[$what][$key] ??= []; + $ret[$what][$key][] = $value; + } + } + return $ret; } /** diff --git a/tests/php/Control/ControllerTest.php b/tests/php/Control/ControllerTest.php index 29d520eb6ae..bcb67f9d4ca 100644 --- a/tests/php/Control/ControllerTest.php +++ b/tests/php/Control/ControllerTest.php @@ -462,7 +462,7 @@ public function testJoinLinks() ); } - public function provideNormaliseTrailingSlash(): array + public static function provideNormaliseTrailingSlash(): array { // note 93.184.215.14 is the IP address for example.com return [ diff --git a/tests/php/Control/DirectorTest.php b/tests/php/Control/DirectorTest.php index 1c65b5bb328..8941a85bf9f 100644 --- a/tests/php/Control/DirectorTest.php +++ b/tests/php/Control/DirectorTest.php @@ -40,7 +40,6 @@ protected function setUp(): void ->setForceSSLPatterns([]) ->setForceWWW(null) ->setEnabledEnvs(true); - $this->expectedRedirect = null; } protected function tearDown(): void @@ -221,7 +220,7 @@ public function testIsAbsolute($path, $result) $this->assertEquals($result, Director::is_absolute($path)); } - public function provideAbsolutePaths() + public static function provideAbsolutePaths() { return [ ['C:/something', true], @@ -294,7 +293,7 @@ public function testIsRelativeUrl() /** * @return array */ - public function providerMakeRelative() + public static function providerMakeRelative() { return [ // Resilience to slash position @@ -543,7 +542,7 @@ public function testResetGlobalsAfterTestRequest() ); } - public function providerTestTestRequestCarriesGlobals() + public static function providerTestTestRequestCarriesGlobals() { $tests = []; $fixture = ['somekey' => 'sometestvalue']; @@ -602,11 +601,12 @@ public function testRouteParams() public function testForceWWW() { - $this->expectExceptionRedirect('http://www.mysite.com:9090/some-url'); - Director::mockRequest(function ($request) { - Injector::inst()->registerService($request, HTTPRequest::class); - Director::forceWWW(); - }, 'http://mysite.com:9090/some-url'); + $this->withExpectExceptionRedirect('http://www.mysite.com:9090/some-url', function () { + Director::mockRequest(function ($request) { + Injector::inst()->registerService($request, HTTPRequest::class); + Director::forceWWW(); + }, 'http://mysite.com:9090/some-url'); + }); } public function testPromisedForceWWW() @@ -632,11 +632,12 @@ public function testPromisedForceWWW() public function testForceSSLProtectsEntireSite() { - $this->expectExceptionRedirect('https://www.mysite.com:9090/some-url'); - Director::mockRequest(function ($request) { - Injector::inst()->registerService($request, HTTPRequest::class); - Director::forceSSL(); - }, 'http://www.mysite.com:9090/some-url'); + $this->withExpectExceptionRedirect('https://www.mysite.com:9090/some-url', function () { + Director::mockRequest(function ($request) { + Injector::inst()->registerService($request, HTTPRequest::class); + Director::forceSSL(); + }, 'http://www.mysite.com:9090/some-url'); + }); } public function testPromisedForceSSL() @@ -664,21 +665,23 @@ public function testPromisedForceSSL() public function testForceSSLOnTopLevelPagePattern() { // Expect admin to trigger redirect - $this->expectExceptionRedirect('https://www.mysite.com:9090/admin'); - Director::mockRequest(function (HTTPRequest $request) { - Injector::inst()->registerService($request, HTTPRequest::class); - Director::forceSSL(['/^admin/']); - }, 'http://www.mysite.com:9090/admin'); + $this->withExpectExceptionRedirect('https://www.mysite.com:9090/admin', function () { + Director::mockRequest(function (HTTPRequest $request) { + Injector::inst()->registerService($request, HTTPRequest::class); + Director::forceSSL(['/^admin/']); + }, 'http://www.mysite.com:9090/admin'); + }); } public function testForceSSLOnSubPagesPattern() { // Expect to redirect to security login page - $this->expectExceptionRedirect('https://www.mysite.com:9090/Security/login'); - Director::mockRequest(function (HTTPRequest $request) { - Injector::inst()->registerService($request, HTTPRequest::class); - Director::forceSSL(['/^Security/']); - }, 'http://www.mysite.com:9090/Security/login'); + $this->withExpectExceptionRedirect('https://www.mysite.com:9090/Security/login', function () { + Director::mockRequest(function (HTTPRequest $request) { + Injector::inst()->registerService($request, HTTPRequest::class); + Director::forceSSL(['/^Security/']); + }, 'http://www.mysite.com:9090/Security/login'); + }); } public function testForceSSLWithPatternDoesNotMatchOtherPages() @@ -701,21 +704,23 @@ public function testForceSSLWithPatternDoesNotMatchOtherPages() public function testForceSSLAlternateDomain() { // Ensure that forceSSL throws the appropriate exception - $this->expectExceptionRedirect('https://secure.mysite.com/admin'); - Director::mockRequest(function (HTTPRequest $request) { - Injector::inst()->registerService($request, HTTPRequest::class); - return Director::forceSSL(['/^admin/'], 'secure.mysite.com'); - }, 'http://www.mysite.com:9090/admin'); + $this->withExpectExceptionRedirect('https://secure.mysite.com/admin', function () { + Director::mockRequest(function (HTTPRequest $request) { + Injector::inst()->registerService($request, HTTPRequest::class); + return Director::forceSSL(['/^admin/'], 'secure.mysite.com'); + }, 'http://www.mysite.com:9090/admin'); + }); } public function testForceSSLAlternateDomainWithPort() { // Ensure that forceSSL throws the appropriate exception - $this->expectExceptionRedirect('https://secure.mysite.com:81/admin'); - Director::mockRequest(function (HTTPRequest $request) { - Injector::inst()->registerService($request, HTTPRequest::class); - return Director::forceSSL(['/^admin/'], 'secure.mysite.com:81'); - }, 'http://www.mysite.com:9090/admin'); + $this->withExpectExceptionRedirect('https://secure.mysite.com:81/admin', function () { + Director::mockRequest(function (HTTPRequest $request) { + Injector::inst()->registerService($request, HTTPRequest::class); + return Director::forceSSL(['/^admin/'], 'secure.mysite.com:81'); + }, 'http://www.mysite.com:9090/admin'); + }); } /** @@ -744,40 +749,19 @@ public function testForceSSLandForceWWW() $this->assertEquals(301, $response->getStatusCode()); } - /** - * Set url to redirect to - * - * @var string - */ - protected $expectedRedirect = null; - /** * Expects this test to throw a HTTPResponse_Exception with the given redirect - * - * @param string $url */ - protected function expectExceptionRedirect($url) - { - $this->expectedRedirect = $url; - } - - protected function runTest() + protected function withExpectExceptionRedirect(string $expectedRedirect, callable $callback) { try { $result = parent::runTest(); - if ($this->expectedRedirect) { - $this->fail("Expected to redirect to {$this->expectedRedirect} but no redirect found"); - } - return $result; + $this->fail("Expected to redirect to $expectedRedirect but no redirect found"); } catch (HTTPResponse_Exception $exception) { // Check URL - if ($this->expectedRedirect) { - $url = $exception->getResponse()->getHeader('Location'); - $this->assertEquals($this->expectedRedirect, $url, "Expected to redirect to {$this->expectedRedirect}"); - return null; - } else { - throw $exception; - } + $url = $exception->getResponse()->getHeader('Location'); + $this->assertEquals($expectedRedirect, $url, "Expected to redirect to $expectedRedirect"); + return null; } } diff --git a/tests/php/Control/Email/EmailTest.php b/tests/php/Control/Email/EmailTest.php index 699d910b63f..0ab5940513e 100644 --- a/tests/php/Control/Email/EmailTest.php +++ b/tests/php/Control/Email/EmailTest.php @@ -82,14 +82,14 @@ public function testInvalidEmailAddress($email): void $this->assertFalse(Email::is_valid_address($email)); } - public function provideValidEmailAddresses(): array + public static function provideValidEmailAddresses(): array { return [ ['test@example.com', 'test-123@sub.example.com'], ]; } - public function provideInvalidEmailAddresses(): array + public static function provideInvalidEmailAddresses(): array { return [ ['foo.bar@', '@example.com', 'foo@'], @@ -553,7 +553,7 @@ public function testCreateAddressArray(string|array $address, string $name, arra } } - public function provideCreateAddressArray(): array + public static function provideCreateAddressArray(): array { return [ [ diff --git a/tests/php/Control/HTTPRequestTest.php b/tests/php/Control/HTTPRequestTest.php index 93391c12c75..b2f2b49badd 100644 --- a/tests/php/Control/HTTPRequestTest.php +++ b/tests/php/Control/HTTPRequestTest.php @@ -7,11 +7,35 @@ use SilverStripe\Control\Middleware\TrustedProxyMiddleware; use SilverStripe\Control\Session; use SilverStripe\Dev\SapphireTest; +use SilverStripe\Control\Tests\HTTPRequestTest\HTTPRequestTestException; class HTTPRequestTest extends SapphireTest { protected static $fixture_file = null; + /** + * @param callable|null $oldHandler + */ + private $oldHandler = null; + + protected function setup(): void + { + // Use custom error handler to allow the use of expectException() to catch warnings + // which is required in testWildCardWithFurtherParams(). + // PHPUnit does not support expecting warnings + parent::setup(); + $this->oldHandler = set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) { + throw new HTTPRequestTestException($errstr); + }); + } + + protected function tearDown(): void + { + restore_error_handler(); + $this->oldHandler = null; + parent::tearDown(); + } + public function testMatch() { $request = new HTTPRequest("GET", "admin/crm/add"); @@ -55,7 +79,8 @@ public function testWildCardMatch() */ public function testWildCardWithFurtherParams() { - $this->expectWarning(); + $this->expectException(HTTPRequestTestException::class); + $this->expectExceptionMessage('All URL params after wildcard parameter $@ will be ignored'); $request = new HTTPRequest('GET', 'admin/crm/test'); // all parameters after the first wildcard parameter are ignored $request->match('admin/$Action/$@/$Other/$*', true); @@ -150,7 +175,7 @@ public function detectMethodDataProvider() ]; } - public function setHttpMethodDataProvider() + public static function setHttpMethodDataProvider() { return [ 'POST request' => ['POST','POST'], diff --git a/tests/php/Control/HTTPRequestTest/HTTPRequestTestException.php b/tests/php/Control/HTTPRequestTest/HTTPRequestTestException.php new file mode 100644 index 00000000000..799cfa4d750 --- /dev/null +++ b/tests/php/Control/HTTPRequestTest/HTTPRequestTestException.php @@ -0,0 +1,10 @@ +assertEmpty($response->getHeader('X-Animal')); } - public function providerSanitiseHeaders() + public static function providerSanitiseHeaders() { return [ 'plain text is retained' => ['some arbitrary value1', 'some arbitrary value1'], @@ -65,7 +65,7 @@ public function testSanitiseHeaders(string $expected, string $value) $this->assertSame($expected, $response->getHeader('X-Sanitised')); } - public function providerTestValidStatusCodes() + public static function providerTestValidStatusCodes() { return [ [200, 'OK'], diff --git a/tests/php/Control/Middleware/CanonicalURLMiddlewareTest.php b/tests/php/Control/Middleware/CanonicalURLMiddlewareTest.php index e68af11bae5..17539fdda82 100644 --- a/tests/php/Control/Middleware/CanonicalURLMiddlewareTest.php +++ b/tests/php/Control/Middleware/CanonicalURLMiddlewareTest.php @@ -86,7 +86,7 @@ public function testGetForceBasicAuthToSSL() $this->assertFalse($middleware->getForceBasicAuthToSSL(), 'Explicitly set is returned'); } - public function provideRedirectTrailingSlash() + public static function provideRedirectTrailingSlash() { $testScenarios = []; foreach ([true, false] as $forceRedirect) { @@ -147,7 +147,7 @@ private function performRedirectTest(string $requestURL, CanonicalURLMiddleware } } - public function provideRedirectTrailingSlashIgnorePaths() + public static function provideRedirectTrailingSlashIgnorePaths() { return [ [ diff --git a/tests/php/Control/Middleware/HTTPCacheControlMiddlewareTest.php b/tests/php/Control/Middleware/HTTPCacheControlMiddlewareTest.php index bd9adbfc920..b98d219c345 100644 --- a/tests/php/Control/Middleware/HTTPCacheControlMiddlewareTest.php +++ b/tests/php/Control/Middleware/HTTPCacheControlMiddlewareTest.php @@ -18,7 +18,7 @@ protected function setUp(): void HTTPCacheControlMiddleware::reset(); } - public function provideCacheStates() + public static function provideCacheStates() { return [ ['enableCache', false], diff --git a/tests/php/Control/RequestHandlerTest.php b/tests/php/Control/RequestHandlerTest.php index 98d02406048..f9e2c8a3268 100644 --- a/tests/php/Control/RequestHandlerTest.php +++ b/tests/php/Control/RequestHandlerTest.php @@ -5,6 +5,7 @@ use SilverStripe\Control\Controller; use SilverStripe\Control\Director; use SilverStripe\Control\RequestHandler; +use SilverStripe\Control\Tests\RequestHandlerTest\RequestHandlerTestException; use SilverStripe\Dev\SapphireTest; /** @@ -14,7 +15,30 @@ class RequestHandlerTest extends SapphireTest { protected $usesDatabase = false; - public function provideTestLink(): array + /** + * @param callable|null $oldHandler + */ + private $oldHandler = null; + + protected function setup(): void + { + // Use custom error handler to allow the use of expectException() to catch warnings + // which is required in testLink() and testAbsoluteLink() which expect warnings. + // PHPUnit does not support expecting warnings + parent::setup(); + $this->oldHandler = set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) { + throw new RequestHandlerTestException($errstr); + }); + } + + protected function tearDown(): void + { + restore_error_handler(); + $this->oldHandler = null; + parent::tearDown(); + } + + public static function provideTestLink(): array { return [ // If there's no url segment, there's no link @@ -48,8 +72,8 @@ public function provideTestLink(): array public function testLink(?string $urlSegment, ?string $action, ?string $expected) { if ($urlSegment === null) { - $this->expectWarning(); - $this->expectWarningMessage('Request handler SilverStripe\Control\RequestHandler does not have a url_segment defined. Relying on this link may be an application error'); + $this->expectException(RequestHandlerTestException::class); + $this->expectExceptionMessage('Request handler SilverStripe\Control\RequestHandler does not have a url_segment defined. Relying on this link may be an application error'); } $handler = new RequestHandler(); @@ -73,8 +97,8 @@ public function testLink(?string $urlSegment, ?string $action, ?string $expected public function testAbsoluteLink(?string $urlSegment, ?string $action, ?string $expected) { if ($urlSegment === null) { - $this->expectWarning(); - $this->expectWarningMessage('Request handler SilverStripe\Control\RequestHandler does not have a url_segment defined. Relying on this link may be an application error'); + $this->expectException(RequestHandlerTestException::class); + $this->expectExceptionMessage('Request handler SilverStripe\Control\RequestHandler does not have a url_segment defined. Relying on this link may be an application error'); } $handler = new RequestHandler(); diff --git a/tests/php/Control/RequestHandlerTest/RequestHandlerTestExcpetion.php b/tests/php/Control/RequestHandlerTest/RequestHandlerTestExcpetion.php new file mode 100644 index 00000000000..b23a3d53a80 --- /dev/null +++ b/tests/php/Control/RequestHandlerTest/RequestHandlerTestExcpetion.php @@ -0,0 +1,10 @@ + [ @@ -336,7 +336,7 @@ public function testParseClassSpec($input, $output) ); } - public function provideClassSpecCases() + public static function provideClassSpecCases() { return [ 'Standard class' => [ diff --git a/tests/php/Core/ConvertTest.php b/tests/php/Core/ConvertTest.php index 0eef687a550..ff9743d76dc 100644 --- a/tests/php/Core/ConvertTest.php +++ b/tests/php/Core/ConvertTest.php @@ -426,7 +426,7 @@ public function testMemString2Bytes($memString, $expected) /** * @return array */ - public function memString2BytesProvider() + public static function memString2BytesProvider() { return [ 'infinite' => ['-1', -1], @@ -459,7 +459,7 @@ public function testBytes2MemString($bytes, $expected) /** * @return array */ - public function bytes2MemStringProvider() + public static function bytes2MemStringProvider() { return [ [0, '0B'], @@ -472,7 +472,7 @@ public function bytes2MemStringProvider() ]; } - public function providerTestSlashes() + public static function providerTestSlashes() { return [ ['bob/bob', '/', true, 'bob/bob'], diff --git a/tests/php/Core/EnvironmentTest.php b/tests/php/Core/EnvironmentTest.php index 7f864710b7a..b6c22a8059f 100644 --- a/tests/php/Core/EnvironmentTest.php +++ b/tests/php/Core/EnvironmentTest.php @@ -8,7 +8,7 @@ class EnvironmentTest extends SapphireTest { - public function providerTestPutEnv() + public static function providerTestPutEnv() { return [ ['_ENVTEST_BOOL=true', '_ENVTEST_BOOL', true], @@ -68,7 +68,7 @@ public function testGetVariables() $this->assertEquals('global', $GLOBALS['test']); } - public function provideHasEnv() + public static function provideHasEnv() { $setAsOptions = [ '.env', diff --git a/tests/php/Core/Injector/InjectorTest.php b/tests/php/Core/Injector/InjectorTest.php index cb7f7b24173..5a55f554ebd 100644 --- a/tests/php/Core/Injector/InjectorTest.php +++ b/tests/php/Core/Injector/InjectorTest.php @@ -841,7 +841,7 @@ public function testConvertServicePropertyBackTicks($value, $expected) $this->assertSame($expected, $actual); } - public function provideConvertServicePropertyBackTicks() + public static function provideConvertServicePropertyBackTicks() { return [ ['`INJECTOR_TEST_CSP_A`', 'ABC'], diff --git a/tests/php/Core/Manifest/ClassManifestTest.php b/tests/php/Core/Manifest/ClassManifestTest.php index fa895316e45..17d8e6ad716 100644 --- a/tests/php/Core/Manifest/ClassManifestTest.php +++ b/tests/php/Core/Manifest/ClassManifestTest.php @@ -41,7 +41,7 @@ protected function setUp(): void /** * @return array */ - public function providerTestGetItemPath() + public static function providerTestGetItemPath() { $paths = [ ['CLASSA', 'module/classes/ClassA.php'], diff --git a/tests/php/Core/Manifest/ModuleManifestTest.php b/tests/php/Core/Manifest/ModuleManifestTest.php index 1aaac7c2b8d..bdcc5532d0b 100644 --- a/tests/php/Core/Manifest/ModuleManifestTest.php +++ b/tests/php/Core/Manifest/ModuleManifestTest.php @@ -111,7 +111,7 @@ public function testGetResourcePathOnRoot() /** * @return array */ - public function providerTestGetModuleByPath() + public static function providerTestGetModuleByPath() { return [ ['vendor/silverstripe/modulec/code/VendorClassA.php', 'silverstripe/modulec'], diff --git a/tests/php/Core/Manifest/ThemeResourceLoaderTest.php b/tests/php/Core/Manifest/ThemeResourceLoaderTest.php index 0c4c424f710..285dbdd56bd 100644 --- a/tests/php/Core/Manifest/ThemeResourceLoaderTest.php +++ b/tests/php/Core/Manifest/ThemeResourceLoaderTest.php @@ -316,7 +316,7 @@ protected function removeTestTemplates($templates) } } - public function providerTestGetPath() + public static function providerTestGetPath() { return [ // Legacy theme diff --git a/tests/php/Core/PathTest.php b/tests/php/Core/PathTest.php index 10dff0e8d98..d2c22804d81 100644 --- a/tests/php/Core/PathTest.php +++ b/tests/php/Core/PathTest.php @@ -26,7 +26,7 @@ public function testJoinPaths($args, $expected) * * @return array */ - public function providerTestJoinPaths() + public static function providerTestJoinPaths() { $tests = [ // Single arg @@ -75,7 +75,7 @@ public function testJoinPathsErrors($args, $error) Path::join($args); } - public function providerTestJoinPathsErrors() + public static function providerTestJoinPathsErrors() { return [ [['/base', '../passwd'], 'Can not collapse relative folders'], @@ -97,7 +97,7 @@ public function testNormalise($input, $expected) $this->assertEquals($expected, $output, "Expected $input to be normalised to $expected"); } - public function providerTestNormalise() + public static function providerTestNormalise() { $tests = [ // Windows paths diff --git a/tests/php/Core/Validation/ConstraintValidatorTest.php b/tests/php/Core/Validation/ConstraintValidatorTest.php index 074340cfb73..7bc13ac524c 100644 --- a/tests/php/Core/Validation/ConstraintValidatorTest.php +++ b/tests/php/Core/Validation/ConstraintValidatorTest.php @@ -65,7 +65,7 @@ class ConstraintValidatorTest extends SapphireTest { protected $usesDatabase = false; - public function provideValidate(): array + public static function provideValidate(): array { $scenarios = [ // basic @@ -317,7 +317,7 @@ public function testValidate(mixed $value, Constraint $constraint): void $this->assertFalse(ConstraintValidator::validate($value, $constraint)->isValid()); } - public function provideValidateResults(): array + public static function provideValidateResults(): array { return [ 'single constraint, no field' => [ diff --git a/tests/php/Dev/BacktraceTest.php b/tests/php/Dev/BacktraceTest.php index d1f5fe98d24..edccec105ab 100644 --- a/tests/php/Dev/BacktraceTest.php +++ b/tests/php/Dev/BacktraceTest.php @@ -115,7 +115,7 @@ public function testFilteredWildCard() $this->assertEquals('myval', $filtered[2]['args']['myarg']); } - public function matchesFilterableClassProvider(): array + public static function matchesFilterableClassProvider(): array { return [ [ diff --git a/tests/php/Dev/CsvBulkLoaderTest.php b/tests/php/Dev/CsvBulkLoaderTest.php index c5d384274a0..4026d3ddb05 100644 --- a/tests/php/Dev/CsvBulkLoaderTest.php +++ b/tests/php/Dev/CsvBulkLoaderTest.php @@ -370,7 +370,7 @@ public function testCheckPermissions(string $class, string $file, bool $respectP } } - public function provideCheckPermissions() + public static function provideCheckPermissions() { $scenarios = [ 'Has all permissions' => [ diff --git a/tests/php/Dev/DeprecationTest.php b/tests/php/Dev/DeprecationTest.php index 30d6b2018f3..f61a46a3768 100644 --- a/tests/php/Dev/DeprecationTest.php +++ b/tests/php/Dev/DeprecationTest.php @@ -9,6 +9,7 @@ use SilverStripe\Core\Environment; use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; +use SilverStripe\Dev\Tests\DeprecationTest\DeprecationTestException; use SilverStripe\Dev\Tests\DeprecationTest\DeprecationTestObject; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Kernel; @@ -27,14 +28,14 @@ protected function setup(): void { // Use custom error handler for two reasons: // - Filter out errors for deprecated class properties unrelated to this unit test - // - Allow the use of expectDeprecation(), which doesn't work with E_USER_DEPRECATION by default + // - Allow the use of expectException(), 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::isEnabled(); $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')) { - throw new Deprecated($errstr, $errno, '', 1); + throw new DeprecationTestException($errstr); } else { // Suppress any E_USER_DEPRECATED unrelated to this unit-test return true; @@ -73,8 +74,8 @@ public function testNotice() 'My message.', 'Called from SilverStripe\Dev\Tests\DeprecationTest->testNotice.' ]); - $this->expectDeprecation(); - $this->expectDeprecationMessage($message); + $this->expectException(DeprecationTestException::class); + $this->expectExceptionMessage($message); Deprecation::enable(); $ret = $this->myDeprecatedMethod(); $this->assertSame('abc', $ret); @@ -90,8 +91,8 @@ public function testCallUserFunc() 'My message.', 'Called from SilverStripe\Dev\Tests\DeprecationTest->testCallUserFunc.' ]); - $this->expectDeprecation(); - $this->expectDeprecationMessage($message); + $this->expectException(DeprecationTestException::class); + $this->expectExceptionMessage($message); Deprecation::enable(); $ret = call_user_func([$this, 'myDeprecatedMethod']); $this->assertSame('abc', $ret); @@ -105,8 +106,8 @@ public function testCallUserFuncArray() 'My message.', 'Called from SilverStripe\Dev\Tests\DeprecationTest->testCallUserFuncArray.' ]); - $this->expectDeprecation(); - $this->expectDeprecationMessage($message); + $this->expectException(DeprecationTestException::class); + $this->expectExceptionMessage($message); Deprecation::enable(); $ret = call_user_func_array([$this, 'myDeprecatedMethod'], []); $this->assertSame('abc', $ret); @@ -130,8 +131,8 @@ public function testWithNoReplacementTrue() 'My message.', 'Called from SilverStripe\Dev\Tests\DeprecationTest->testWithNoReplacementTrue.' ]); - $this->expectDeprecation(); - $this->expectDeprecationMessage($message); + $this->expectException(DeprecationTestException::class); + $this->expectExceptionMessage($message); Deprecation::enable(true); $ret = Deprecation::withNoReplacement(function () { return $this->myDeprecatedMethod(); @@ -147,8 +148,8 @@ public function testWithNoReplacementTrueCallUserFunc() 'My message.', 'Called from SilverStripe\Dev\Tests\DeprecationTest->testWithNoReplacementTrueCallUserFunc.' ]); - $this->expectDeprecation(); - $this->expectDeprecationMessage($message); + $this->expectException(DeprecationTestException::class); + $this->expectExceptionMessage($message); Deprecation::enable(true); $ret = Deprecation::withNoReplacement(function () { return call_user_func([$this, 'myDeprecatedMethod']); @@ -164,8 +165,8 @@ public function testNoticeWithNoReplacementTrue() 'My message.', 'Called from PHPUnit\Framework\TestCase->runTest.' ]); - $this->expectDeprecation(); - $this->expectDeprecationMessage($message); + $this->expectException(DeprecationTestException::class); + $this->expectExceptionMessage($message); Deprecation::enable(true); Deprecation::withNoReplacement(function () { Deprecation::notice('123', 'My message.'); @@ -180,8 +181,8 @@ public function testClassWithNoReplacement() 'Some class message.', 'Called from SilverStripe\Dev\Tests\DeprecationTest->testClassWithNoReplacement.' ]); - $this->expectDeprecation(); - $this->expectDeprecationMessage($message); + $this->expectException(DeprecationTestException::class); + $this->expectExceptionMessage($message); Deprecation::enable(true); // using this syntax because my IDE was complaining about DeprecationTestObject not existing // when trying to use `new DeprecationTestObject();` @@ -197,8 +198,8 @@ public function testClassWithInjectorWithNoReplacement() 'Some class message.', 'Called from SilverStripe\Dev\Tests\DeprecationTest->testClassWithInjectorWithNoReplacement.' ]); - $this->expectDeprecation(); - $this->expectDeprecationMessage($message); + $this->expectException(DeprecationTestException::class); + $this->expectExceptionMessage($message); Deprecation::enable(true); Injector::inst()->get(DeprecationTestObject::class); Deprecation::outputNotices(); @@ -229,8 +230,8 @@ public function testConfigGetFirst() 'Config SilverStripe\Dev\Tests\DeprecationTest\DeprecationTestObject.first_config is deprecated.', 'My first config message.' ]); - $this->expectDeprecation(); - $this->expectDeprecationMessage($message); + $this->expectException(DeprecationTestException::class); + $this->expectExceptionMessage($message); Deprecation::enable(); Config::inst()->get(DeprecationTestObject::class, 'first_config'); Deprecation::outputNotices(); @@ -242,8 +243,8 @@ public function testConfigGetSecond() 'Config SilverStripe\Dev\Tests\DeprecationTest\DeprecationTestObject.second_config is deprecated.', 'My second config message.' ]); - $this->expectDeprecation(); - $this->expectDeprecationMessage($message); + $this->expectException(DeprecationTestException::class); + $this->expectExceptionMessage($message); Deprecation::enable(); Config::inst()->get(DeprecationTestObject::class, 'second_config'); Deprecation::outputNotices(); @@ -252,8 +253,8 @@ public function testConfigGetSecond() public function testConfigGetThird() { $message = 'Config SilverStripe\Dev\Tests\DeprecationTest\DeprecationTestObject.third_config is deprecated.'; - $this->expectDeprecation(); - $this->expectDeprecationMessage($message); + $this->expectException(DeprecationTestException::class); + $this->expectExceptionMessage($message); Deprecation::enable(); Config::inst()->get(DeprecationTestObject::class, 'third_config'); Deprecation::outputNotices(); @@ -265,8 +266,8 @@ public function testConfigSet() 'Config SilverStripe\Dev\Tests\DeprecationTest\DeprecationTestObject.first_config is deprecated.', 'My first config message.' ]); - $this->expectDeprecation(); - $this->expectDeprecationMessage($message); + $this->expectException(DeprecationTestException::class); + $this->expectExceptionMessage($message); Deprecation::enable(); Config::modify()->set(DeprecationTestObject::class, 'first_config', 'abc'); Deprecation::outputNotices(); @@ -278,14 +279,14 @@ public function testConfigMerge() 'Config SilverStripe\Dev\Tests\DeprecationTest\DeprecationTestObject.array_config is deprecated.', 'My array config message.' ]); - $this->expectDeprecation(); - $this->expectDeprecationMessage($message); + $this->expectException(DeprecationTestException::class); + $this->expectExceptionMessage($message); Deprecation::enable(); Config::modify()->merge(DeprecationTestObject::class, 'array_config', ['abc']); Deprecation::outputNotices(); } - public function provideConfigVsEnv() + public static function provideConfigVsEnv() { return [ // env var not set - config setting is respected @@ -391,7 +392,7 @@ private function runConfigVsEnvTest(string $varName, $envVal, bool $configVal, b $this->assertSame($expected, $result); } - public function provideVarAsBoolean() + public static function provideVarAsBoolean() { return [ [ @@ -448,7 +449,7 @@ public function testVarAsBoolean($rawValue, bool $expected) $this->assertSame($expected, $reflectionVarAsBoolean->invoke(null, $rawValue)); } - public function provideIsEnabled() + public static function provideIsEnabled() { return [ 'dev, explicitly enabled' => [ diff --git a/tests/php/Dev/DeprecationTest/DeprecationTestException.php b/tests/php/Dev/DeprecationTest/DeprecationTestException.php new file mode 100644 index 00000000000..7d5e3e4ffa5 --- /dev/null +++ b/tests/php/Dev/DeprecationTest/DeprecationTestException.php @@ -0,0 +1,10 @@ +exporter = new SSListExporter(); - } - - public function provideClassesForExport() - { - return [ - [ArrayList::class, false], - [DataObject::class, false], - [DataList::class, Member::class], - [ArrayData::class, false] - ]; - } - - /** - * @dataProvider provideClassesForExport() - * @param $className - * @param $constructorParam - */ - public function testExportStartsWithClassName($className, $constructorParam) - { - $obj = $constructorParam - ? $className::create($constructorParam) - : $className::create(); - - $export = ltrim($this->exporter->export($obj) ?? ''); - - $this->assertStringStartsWith(get_class($obj), $export, 'Export should start with object\'s class name'); - } - - - /** - * @testdox toMap() returns DataObjects's data - */ - public function testToMapReturnsDataOfDataObjects() - { - $data = [ - 'ID' => 5, - 'Foo' => 'Bar', - 'Baz' => 'Boom', - 'One' => 'Two' - ]; - - $map = $this->exporter->toMap(DataObject::create($data, DataObject::CREATE_HYDRATED)); - - $this->assertEquals($data, $map, 'Map should match data passed to DataObject'); - } - - /** - * @testdox toMap() returns ArrayData's data - */ - public function testToMapReturnsDataOfArrayData() - { - $data = [ - 'Foo' => 'Bar', - 'Baz' => 'Boom', - 'One' => 'Two' - ]; - - $map = $this->exporter->toMap(ArrayData::create($data)); - - $this->assertEquals($data, $map, 'Map should match data passed to ArrayData'); - } -} diff --git a/tests/php/Dev/SapphireTestTest.php b/tests/php/Dev/SapphireTestTest.php index 3b571c3c1ae..5b11e8e7110 100644 --- a/tests/php/Dev/SapphireTestTest.php +++ b/tests/php/Dev/SapphireTestTest.php @@ -8,13 +8,16 @@ use SilverStripe\Security\Member; use SilverStripe\Security\Permission; +/** + * @sometag This is a test annotation used in the testGetAnnotations test + */ class SapphireTestTest extends SapphireTest { /** * @return array */ - public function provideResolveFixturePath() + public static function provideResolveFixturePath() { return [ 'sameDirectory' => [ @@ -230,4 +233,31 @@ public function testAssertListEqualsFailsOnNonEqualLists($matches, $itemsForList $this->assertListEquals($matches, $list); } + + /** + * This test intentionally has non-sensical annotations to test the parser + * + * @lorem ipsum + * @param $one something + * @param $two else + */ + public function testGetAnnotations(): void + { + $this->assertSame([ + 'method' => [ + 'lorem' => [ + 'ipsum' + ], + 'param' => [ + '$one something', + '$two else', + ], + ], + 'class' => [ + 'sometag' => [ + 'This is a test annotation used in the testGetAnnotations test' + ], + ], + ], $this->getAnnotations()); + } } diff --git a/tests/php/Dev/Validation/RelationValidationTest.php b/tests/php/Dev/Validation/RelationValidationTest.php index 04f57c4af41..c052505a668 100644 --- a/tests/php/Dev/Validation/RelationValidationTest.php +++ b/tests/php/Dev/Validation/RelationValidationTest.php @@ -67,7 +67,7 @@ public function testIgnoredClass(string $class, ?string $relation, array $config $this->assertEquals($expected, $result); } - public function validateCasesProvider(): array + public static function validateCasesProvider(): array { return [ 'correct setup' => [ @@ -272,7 +272,7 @@ public function validateCasesProvider(): array ]; } - public function ignoredClassesProvider(): array + public static function ignoredClassesProvider(): array { return [ 'class default' => [ diff --git a/tests/php/Dev/ViewableDataContainsTest.php b/tests/php/Dev/ViewableDataContainsTest.php index fcf93c26e06..de4b0072d55 100644 --- a/tests/php/Dev/ViewableDataContainsTest.php +++ b/tests/php/Dev/ViewableDataContainsTest.php @@ -15,7 +15,7 @@ class ViewableDataContainsTest extends SapphireTest 'Surname' => 'Schommer' ]; - public function provideMatchesForList() + public static function provideMatchesForList() { return [ [ @@ -31,7 +31,7 @@ public function provideMatchesForList() } - public function provideInvalidMatchesForList() + public static function provideInvalidMatchesForList() { return [ [ diff --git a/tests/php/Forms/ConfirmedPasswordFieldTest.php b/tests/php/Forms/ConfirmedPasswordFieldTest.php index 971ad371672..dc110b3449e 100644 --- a/tests/php/Forms/ConfirmedPasswordFieldTest.php +++ b/tests/php/Forms/ConfirmedPasswordFieldTest.php @@ -208,7 +208,7 @@ public function testLengthValidation($minLength, $maxLength, $expectValid, $expe /** * @return array[] */ - public function lengthValidationProvider() + public static function lengthValidationProvider() { return [ 'valid: within min and max' => [3, 8, true], @@ -403,7 +403,7 @@ public function testSetCanBeEmptySaveInto(bool $generateRandomPasswordOnEmpty, ? $this->assertSame($expected, $field->Value()); } - public function provideSetCanBeEmptySaveInto(): array + public static function provideSetCanBeEmptySaveInto(): array { return [ [ @@ -430,7 +430,7 @@ public function testSetCanBeEmptyRightTitle() $this->assertNotEmpty($passwordField->RightTitle()); } - public function provideRequired() + public static function provideRequired() { return [ 'can be empty' => [true], @@ -448,7 +448,7 @@ public function testRequired(bool $canBeEmpty) $this->assertSame(!$canBeEmpty, $field->Required()); } - public function provideChildFieldsAreRequired() + public static function provideChildFieldsAreRequired() { return [ 'not required' => [ diff --git a/tests/php/Forms/DropdownFieldTest.php b/tests/php/Forms/DropdownFieldTest.php index 88603aa7550..ba3c0237344 100644 --- a/tests/php/Forms/DropdownFieldTest.php +++ b/tests/php/Forms/DropdownFieldTest.php @@ -424,7 +424,7 @@ public function testDropdownWithArrayValues($value) /** * @return array */ - public function arrayValueProvider() + public static function arrayValueProvider() { return [ [[]], diff --git a/tests/php/Forms/FieldsValidatorTest.php b/tests/php/Forms/FieldsValidatorTest.php index 8c958bcd348..773ef59e82e 100644 --- a/tests/php/Forms/FieldsValidatorTest.php +++ b/tests/php/Forms/FieldsValidatorTest.php @@ -12,7 +12,7 @@ class FieldsValidatorTest extends SapphireTest { protected $usesDatabase = false; - public function provideValidation() + public static function provideValidation() { return [ 'missing values arent invalid' => [ diff --git a/tests/php/Forms/FormFieldTest.php b/tests/php/Forms/FormFieldTest.php index 21b4a01283a..945c826d532 100644 --- a/tests/php/Forms/FormFieldTest.php +++ b/tests/php/Forms/FormFieldTest.php @@ -228,7 +228,7 @@ public function testAttributesHTML() /** * Covering all potential inputs for Convert::raw2xml */ - public function escapeHtmlDataProvider() + public static function escapeHtmlDataProvider() { return [ [''], @@ -661,7 +661,7 @@ public function testNameToLabel($name, $expected) /** * @return array[] */ - public function nameToLabelProvider() + public static function nameToLabelProvider() { return [ ['TotalAmount', 'Total amount'], diff --git a/tests/php/Forms/FormScaffolderTest.php b/tests/php/Forms/FormScaffolderTest.php index 9116bc82de5..c02d7a3724f 100644 --- a/tests/php/Forms/FormScaffolderTest.php +++ b/tests/php/Forms/FormScaffolderTest.php @@ -171,7 +171,7 @@ public function testGetFormFields() $this->assertFalse($fields->hasTabSet(), 'getFrontEndFields() doesnt produce a TabSet by default'); } - public function provideScaffoldRelationFormFields() + public static function provideScaffoldRelationFormFields() { $scenarios = [ 'ignore no relations' => [ @@ -271,7 +271,7 @@ public function testScaffoldRestrictRelations(): void $this->assertSame(['Tags'], $fields->column('Name')); } - public function provideTabs(): array + public static function provideTabs(): array { return [ 'only main tab' => [ diff --git a/tests/php/Forms/FormSchemaTest.php b/tests/php/Forms/FormSchemaTest.php index c032f3a5372..57137827686 100644 --- a/tests/php/Forms/FormSchemaTest.php +++ b/tests/php/Forms/FormSchemaTest.php @@ -66,7 +66,7 @@ public function testGetSchemaException(string $field, bool $expectException): vo $formSchema->getSchema($form); } - public function provideGetSchemaException(): array + public static function provideGetSchemaException(): array { return [ [ diff --git a/tests/php/Forms/FormTest.php b/tests/php/Forms/FormTest.php index 8b97293443a..12829666b01 100644 --- a/tests/php/Forms/FormTest.php +++ b/tests/php/Forms/FormTest.php @@ -68,7 +68,7 @@ protected function setUp(): void /** * @return array */ - public function boolDataProvider() + public static function boolDataProvider() { return [ [false], @@ -76,7 +76,7 @@ public function boolDataProvider() ]; } - public function formMessageDataProvider() + public static function formMessageDataProvider() { return [ [ @@ -100,7 +100,7 @@ public function formMessageDataProvider() ]; } - public function formMessageExceptionsDataProvider() + public static function formMessageExceptionsDataProvider() { return [ [ @@ -732,7 +732,7 @@ public function testDisableSecurityTokenAcceptsSubmissionWithoutToken(): void ); } - public function provideFormsSet() + public static function provideFormsSet() { return [ 'with security token' => diff --git a/tests/php/Forms/GridField/GridFieldDeleteActionTest.php b/tests/php/Forms/GridField/GridFieldDeleteActionTest.php index 8786d20bdad..6091d543241 100644 --- a/tests/php/Forms/GridField/GridFieldDeleteActionTest.php +++ b/tests/php/Forms/GridField/GridFieldDeleteActionTest.php @@ -235,7 +235,7 @@ public function testMenuGroup() $this->assertNull($group, 'A menu group does not exist when the user cannot delete'); } - public function provideHandleActionThrowsException() + public static function provideHandleActionThrowsException() { return [ 'unlinks relation' => [true], @@ -267,7 +267,7 @@ public function testHandleActionThrowsException(bool $unlinkRelation) $component->handleAction($gridField, $secondArg, ['RecordID' => 1], []); } - public function provideGetRemoveActionThrowsException() + public static function provideGetRemoveActionThrowsException() { return [ 'removes relation' => [true], diff --git a/tests/php/Forms/GridField/GridFieldDetailFormTest.php b/tests/php/Forms/GridField/GridFieldDetailFormTest.php index 34c1848c1d9..9862cfd08c3 100644 --- a/tests/php/Forms/GridField/GridFieldDetailFormTest.php +++ b/tests/php/Forms/GridField/GridFieldDetailFormTest.php @@ -496,7 +496,7 @@ public function testRedirectMissingRecords() $this->autoFollowRedirection = $origAutoFollow; } - public function provideGetRecordFromRequestFindExisting() + public static function provideGetRecordFromRequestFindExisting() { return [ 'No records' => [ @@ -538,7 +538,7 @@ public function testGetRecordFromRequestFindExisting(array $data, bool $hasRecor $this->assertSame($hasRecord, (bool) $reflectionMethod->invoke($component, $gridField, $request)); } - public function provideGetRecordFromRequestCreateNew() + public static function provideGetRecordFromRequestCreateNew() { // Note that in all of these scenarios a new record gets created, so it *shouldn't* matter what's already in there. return [ @@ -574,7 +574,7 @@ public function testGetRecordFromRequestCreateNew(array $data) $this->assertEquals(new ArrayDataWithID(['ID' => 0]), $reflectionMethod->invoke($component, $gridField, $request)); } - public function provideGetRecordFromRequestWithoutData() + public static function provideGetRecordFromRequestWithoutData() { // Note that in all of these scenarios a new record gets created, so it *shouldn't* matter what's already in there. return [ diff --git a/tests/php/Forms/GridField/GridFieldReadonlyTest.php b/tests/php/Forms/GridField/GridFieldReadonlyTest.php index 27b51096f4c..299c6ea0708 100644 --- a/tests/php/Forms/GridField/GridFieldReadonlyTest.php +++ b/tests/php/Forms/GridField/GridFieldReadonlyTest.php @@ -33,7 +33,7 @@ class GridFieldReadonlyTest extends SapphireTest Cheerleader::class, ]; - public function provideReadOnlyTransformation(): array + public static function provideReadOnlyTransformation(): array { return [ [ diff --git a/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php b/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php index f17b1fe124e..247a61da750 100644 --- a/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php +++ b/tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php @@ -215,7 +215,7 @@ public function testReadonlyField() ); } - public function provideTestValueEntities() + public static function provideTestValueEntities() { return [ "ampersand" => [ diff --git a/tests/php/Forms/HTMLEditor/HTMLEditorSanitiserTest.php b/tests/php/Forms/HTMLEditor/HTMLEditorSanitiserTest.php index ee3d9980212..bbd413ebe7f 100644 --- a/tests/php/Forms/HTMLEditor/HTMLEditorSanitiserTest.php +++ b/tests/php/Forms/HTMLEditor/HTMLEditorSanitiserTest.php @@ -11,7 +11,7 @@ class HTMLEditorSanitiserTest extends FunctionalTest { - public function provideSanitise(): array + public static function provideSanitise(): array { return [ [ diff --git a/tests/php/Forms/NumericFieldTest.php b/tests/php/Forms/NumericFieldTest.php index ca6a08af74a..a01115e736f 100644 --- a/tests/php/Forms/NumericFieldTest.php +++ b/tests/php/Forms/NumericFieldTest.php @@ -55,7 +55,7 @@ public function testSetValue($locale, $scale, $input, $output) /** * Test formatting of numbers */ - public function dataForTestSetValue() + public static function dataForTestSetValue() { return [ // de @@ -124,7 +124,7 @@ public function testNullSet() $this->assertEquals(0, $field->dataValue()); } - public function dataForTestSubmittedValue() + public static function dataForTestSubmittedValue() { return [ ['de_DE', 0, '13000', 13000, '13.000'], diff --git a/tests/php/Forms/PasswordFieldTest.php b/tests/php/Forms/PasswordFieldTest.php index 4dfb4a38c89..d3c019f7cb4 100644 --- a/tests/php/Forms/PasswordFieldTest.php +++ b/tests/php/Forms/PasswordFieldTest.php @@ -8,7 +8,7 @@ class PasswordFieldTest extends SapphireTest { - public function boolDataProvider() + public static function boolDataProvider() { return [ [false], diff --git a/tests/php/Forms/RequiredFieldsTest.php b/tests/php/Forms/RequiredFieldsTest.php index 5c080cfc9f9..07c362da3d0 100644 --- a/tests/php/Forms/RequiredFieldsTest.php +++ b/tests/php/Forms/RequiredFieldsTest.php @@ -290,7 +290,7 @@ public function testFieldIsRequired() ); } - public function provideHasOneRelationFieldInterfaceValidation(): array + public static function provideHasOneRelationFieldInterfaceValidation(): array { return [ [ diff --git a/tests/php/Forms/SearchableDropdownTraitTest.php b/tests/php/Forms/SearchableDropdownTraitTest.php index d3796cfa239..a3ebca8432c 100644 --- a/tests/php/Forms/SearchableDropdownTraitTest.php +++ b/tests/php/Forms/SearchableDropdownTraitTest.php @@ -121,7 +121,7 @@ public function testGetValueArray(mixed $value, string|array $expected): void $this->assertSame($expected, $field->getValueArray()); } - public function provideGetValueArray(): array + public static function provideGetValueArray(): array { return [ 'empty' => [ @@ -219,7 +219,7 @@ public function testGetSchemaDataDefaults(): void $this->assertFalse($schema['searchable']); } - public function provideLazyLoadedDoesntCallGetSource() + public static function provideLazyLoadedDoesntCallGetSource() { $methodsToCall = [ 'Field', diff --git a/tests/php/Forms/UrlFieldTest.php b/tests/php/Forms/UrlFieldTest.php index 72cd2efb4d1..c8ac9da3925 100644 --- a/tests/php/Forms/UrlFieldTest.php +++ b/tests/php/Forms/UrlFieldTest.php @@ -8,7 +8,7 @@ class UrlFieldTest extends SapphireTest { - public function provideValidate(): array + public static function provideValidate(): array { return [ [ diff --git a/tests/php/Logging/HTTPOutputHandlerTest.php b/tests/php/Logging/HTTPOutputHandlerTest.php index e72eaf95aa0..ec1f3b0cc7c 100644 --- a/tests/php/Logging/HTTPOutputHandlerTest.php +++ b/tests/php/Logging/HTTPOutputHandlerTest.php @@ -57,7 +57,7 @@ public function testDevConfig() $this->assertInstanceOf(DetailedErrorFormatter::class, $handler->getFormatter()); } - public function provideShouldShowError() + public static function provideShouldShowError() { $provide = []; // See https://www.php.net/manual/en/errorfunc.constants.php diff --git a/tests/php/ORM/ArrayListTest.php b/tests/php/ORM/ArrayListTest.php index 235222da31c..188a3a6dd95 100644 --- a/tests/php/ORM/ArrayListTest.php +++ b/tests/php/ORM/ArrayListTest.php @@ -118,7 +118,7 @@ function ($item) use (&$count, $test) { $this->assertEquals($list->Count(), $count); } - public function limitDataProvider(): array + public static function limitDataProvider(): array { $all = [ ['Key' => 1], ['Key' => 2], ['Key' => 3] ]; list($one, $two, $three) = $all; @@ -343,7 +343,7 @@ public function testMap() ); } - public function provideFindWithSearchfilters() + public static function provideFindWithSearchfilters() { $objects = $this->getFilterWithSearchfiltersObjects(); return [ @@ -984,7 +984,7 @@ public function testFilterNullComparisons(mixed $objectValue, mixed $filterValue $this->assertCount($doesMatch ? 1 : 0, $list); } - public function provideFilterNullComparisons() + public static function provideFilterNullComparisons() { // This is for backwards compatibility, since arraylist used to just do a straight == comparison // Everything that passes here would have passed a $objectValue == $filterValue comparison previously @@ -1149,7 +1149,7 @@ private function getFilterWithSearchfiltersObjects() ]; } - public function provideFilterWithSearchfilters() + public static function provideFilterWithSearchfilters() { // Note that search filter tests here are to test syntax and to ensure all supported search filters // work with arraylist - but we don't need to test every possible edge case here, @@ -1321,7 +1321,7 @@ public function testFilterWithSearchfilters(array $args, array $objects, array $ $this->assertEquals(array_column($expected, 'ID'), $list->column('ID')); } - public function provideFilterAnyWithSearchfilters() + public static function provideFilterAnyWithSearchfilters() { $objects = $this->getFilterWithSearchfiltersObjects(); return [ @@ -1378,7 +1378,7 @@ public function testFilterAnyWithSearchfilters(array $args, array $objects, arra $this->assertEquals(array_column($expected, 'ID'), $list->column('ID')); } - public function provideFilterAny() + public static function provideFilterAny() { $list = new ArrayList( [ @@ -1650,7 +1650,7 @@ public function testMultipleExcludeThreeArguments() $this->assertEquals($expected, $list->toArray()); } - public function provideExcludeWithSearchfilters() + public static function provideExcludeWithSearchfilters() { // If it's included in the filter test, then it's excluded in the exclude test, // so we can just use the same scenarios and reverse the expected results. @@ -1682,7 +1682,7 @@ public function testExcludeWithSearchfilters(array $args, array $objects, array $this->assertEquals($expected, $list->toArray()); } - public function provideExcludeAnyWithSearchfilters() + public static function provideExcludeAnyWithSearchfilters() { // If it's included in the filterAny test, then it's excluded in the excludeAny test, // so we can just use the same scenarios and reverse the expected results. @@ -1714,7 +1714,7 @@ public function testExcludeAnyWithSearchfilters(array $args, array $objects, arr $this->assertEquals($expected, $list->toArray()); } - public function provideExcludeAny() + public static function provideExcludeAny() { // If it's included in the filterAny test, then it's excluded in the excludeAny test, // so we can just use the same scenarios and reverse the expected results. diff --git a/tests/php/ORM/Connect/DBQueryBuilderTest.php b/tests/php/ORM/Connect/DBQueryBuilderTest.php index 20645c40f01..78052effa51 100644 --- a/tests/php/ORM/Connect/DBQueryBuilderTest.php +++ b/tests/php/ORM/Connect/DBQueryBuilderTest.php @@ -11,7 +11,7 @@ class DBQueryBuilderTest extends SapphireTest { protected $usesDatabase = false; - public function provideShouldBuildTraceComment(): array + public static function provideShouldBuildTraceComment(): array { return [ [ diff --git a/tests/php/ORM/DBDateTest.php b/tests/php/ORM/DBDateTest.php index d91360155cc..7e58141180b 100644 --- a/tests/php/ORM/DBDateTest.php +++ b/tests/php/ORM/DBDateTest.php @@ -362,7 +362,7 @@ public function testModify($adjustment, $expected) /** * @return array[] */ - public function modifyProvider() + public static function modifyProvider() { return [ ['+1 day', '2019-03-04'], diff --git a/tests/php/ORM/DBDatetimeTest.php b/tests/php/ORM/DBDatetimeTest.php index 71b24be225b..5af5bd93c62 100644 --- a/tests/php/ORM/DBDatetimeTest.php +++ b/tests/php/ORM/DBDatetimeTest.php @@ -283,7 +283,7 @@ public function testModify($adjustment, $expected) /** * @return array[] */ - public function modifyProvider() + public static function modifyProvider() { return [ ['+1 day', '2019-03-04 12:00:00'], diff --git a/tests/php/ORM/DBEnumTest.php b/tests/php/ORM/DBEnumTest.php index c0d1f71c0b1..6367214438f 100644 --- a/tests/php/ORM/DBEnumTest.php +++ b/tests/php/ORM/DBEnumTest.php @@ -31,7 +31,7 @@ public function testParse(?string $expectedDefault, bool $expectedNullifyEmpty, $this->assertEquals($expectedNullifyEmpty, $enum->getNullifyEmpty()); } - public function provideParse() + public static function provideParse() { return [ // standard syntax - double quotes diff --git a/tests/php/ORM/DBFieldTest.php b/tests/php/ORM/DBFieldTest.php index cb1cb0ae727..874af3a1b2f 100644 --- a/tests/php/ORM/DBFieldTest.php +++ b/tests/php/ORM/DBFieldTest.php @@ -226,7 +226,7 @@ public function testPrepValueForDBArrayValue($dbFieldName, $scalarValueOnly, $ex $this->assertEquals($scalarValueOnly, $dbField->scalarValueOnly()); } - public function dataProviderPrepValueForDBArrayValue() + public static function dataProviderPrepValueForDBArrayValue() { return [ [DBBigInt::class, true], diff --git a/tests/php/ORM/DBHTMLTextTest.php b/tests/php/ORM/DBHTMLTextTest.php index 8ab5b8bcdb6..fba3e9dc58f 100644 --- a/tests/php/ORM/DBHTMLTextTest.php +++ b/tests/php/ORM/DBHTMLTextTest.php @@ -45,7 +45,7 @@ protected function tearDown(): void /** * Test {@link Text->LimitCharacters()} */ - public function providerLimitCharacters() + public static function providerLimitCharacters() { // HTML characters are stripped safely return [ @@ -72,7 +72,7 @@ public function testLimitCharacters($originalValue, $expectedValue) /** * @return array */ - public function providerLimitCharactersToClosestWord() + public static function providerLimitCharactersToClosestWord() { // HTML is converted safely to plain text return [ @@ -111,7 +111,7 @@ public function testLimitCharactersToClosestWord($originalValue, $limit, $expect $this->assertEquals($expectedValue, $result); } - public function providerSummary() + public static function providerSummary() { return [ [ @@ -199,7 +199,7 @@ public function testSummaryEndings() - public function providerFirstSentence() + public static function providerFirstSentence() { return [ // Same behaviour as DBTextTest @@ -251,7 +251,7 @@ public function testCreate() $this->assertEquals(['a'], $field->getWhitelist()); } - public function providerToPlain() + public static function providerToPlain() { return [ [ @@ -292,7 +292,7 @@ public function testToPlain($html, $plain) * * @return array */ - public function providerContextSummary() + public static function providerContextSummary() { return [ [ diff --git a/tests/php/ORM/DBSchemaManagerTest.php b/tests/php/ORM/DBSchemaManagerTest.php index f6b5da381ab..43e645eb6cb 100644 --- a/tests/php/ORM/DBSchemaManagerTest.php +++ b/tests/php/ORM/DBSchemaManagerTest.php @@ -12,7 +12,7 @@ class DBSchemaManagerTest extends SapphireTest { protected $usesDatabase = false; - public function provideCanCheckAndRepairTable() + public static function provideCanCheckAndRepairTable() { return [ // not ignored, but globally not allowed diff --git a/tests/php/ORM/DBTextTest.php b/tests/php/ORM/DBTextTest.php index cb2f0fa487c..7094b479bbe 100644 --- a/tests/php/ORM/DBTextTest.php +++ b/tests/php/ORM/DBTextTest.php @@ -33,7 +33,7 @@ protected function tearDown(): void /** * Test {@link Text->LimitCharacters()} */ - public function providerLimitCharacters() + public static function providerLimitCharacters() { // Plain text values always encoded safely // HTML stored in non-html fields is treated literally. @@ -62,7 +62,7 @@ public function testLimitCharacters($originalValue, $expectedValue) /** * @return array */ - public function providerLimitCharactersToClosestWord() + public static function providerLimitCharactersToClosestWord() { return [ // Standard words limited, ellipsis added if truncated @@ -107,7 +107,7 @@ public function testLimitCharactersToClosestWord($originalValue, $limit, $expect /** * Test {@link Text->LimitWordCount()} */ - public function providerLimitWordCount() + public static function providerLimitWordCount() { return [ // Standard words limited, ellipsis added if truncated @@ -152,7 +152,7 @@ public function testLimitWordCount($originalValue, $limit, $expectedValue) /** */ - public function providerLimitSentences() + public static function providerLimitSentences() { return [ ['', 2, ''], @@ -184,7 +184,7 @@ public function testLimitSentences($originalValue, $limit, $expectedValue) $this->assertEquals($expectedValue, $result); } - public function providerFirstSentence() + public static function providerFirstSentence() { return [ ['', ''], @@ -220,7 +220,7 @@ public function testFirstSentence($originalValue, $expectedValue) * * @return array */ - public function providerContextSummary() + public static function providerContextSummary() { return [ [ @@ -279,7 +279,7 @@ public function providerContextSummary() * * @return array */ - public function providerSummary() + public static function providerSummary() { return [ 'simple test' => [ diff --git a/tests/php/ORM/DBTimeTest.php b/tests/php/ORM/DBTimeTest.php index fa2420c5f8f..df06d6efb1a 100644 --- a/tests/php/ORM/DBTimeTest.php +++ b/tests/php/ORM/DBTimeTest.php @@ -16,7 +16,7 @@ protected function setUp(): void i18n::set_locale('en_NZ'); } - public function dataTestParse() + public static function dataTestParse() { return [ // Test am-pm conversion diff --git a/tests/php/ORM/DataListEagerLoadingTest.php b/tests/php/ORM/DataListEagerLoadingTest.php index 13c2460c8f8..dacc68a44ba 100644 --- a/tests/php/ORM/DataListEagerLoadingTest.php +++ b/tests/php/ORM/DataListEagerLoadingTest.php @@ -180,7 +180,7 @@ public function testEagerLoadRelations(string $iden, array $eagerLoad, int $expe $this->assertSame($expected, $selectCount); } - public function provideEagerLoadRelations(): array + public static function provideEagerLoadRelations(): array { return [ // Include the lazy-loaded expectation here, since if the number @@ -779,7 +779,7 @@ public function testEagerLoadRelationsEmpty(string $eagerLoadRelation, int $expe $this->assertSame($expectedNumQueries, $numQueries); } - public function provideEagerLoadRelationsEmpty(): array + public static function provideEagerLoadRelationsEmpty(): array { return [ 'has_one' => [ @@ -841,7 +841,7 @@ public function testEagerLoadInvalidRelationException(string $eagerLoadRelation) EagerLoadObject::get()->eagerLoad($eagerLoadRelation)->toArray(); } - public function provideEagerLoadInvalidRelationException(): array + public static function provideEagerLoadInvalidRelationException(): array { return [ [ @@ -887,7 +887,7 @@ private function validateEagerLoadManyManyExtraFields($relationList): void } } - public function provideEagerLoadManyManyExtraFields(): array + public static function provideEagerLoadManyManyExtraFields(): array { return [ [ @@ -936,7 +936,7 @@ private function validateEagerLoadManyManyThroughJoinRecords($relationList): voi } } - public function provideEagerLoadManyManyThroughJoinRecords(): array + public static function provideEagerLoadManyManyThroughJoinRecords(): array { return [ [ @@ -1251,7 +1251,7 @@ public function testEagerLoadingEmptyRelations(string $iden, string $eagerLoad): } } - public function provideEagerLoadingEmptyRelations(): array + public static function provideEagerLoadingEmptyRelations(): array { return [ [ @@ -1362,7 +1362,7 @@ public function testInvalidAssociativeArray(): void EagerLoadObject::get()->eagerLoad(['HasManyEagerLoadObjects' => 'HasManyEagerLoadObjects']); } - public function provideNoLimitEagerLoadingQuery(): array + public static function provideNoLimitEagerLoadingQuery(): array { // Note we don't test has_one or belongs_to because those don't accept a callback at all. return [ @@ -1407,7 +1407,7 @@ public function testNoLimitEagerLoadingQuery(string $relation, string $relationT EagerLoadObject::get()->eagerLoad([$relation => $callback])->toArray(); } - public function provideCannotManipulateUnaryRelationQuery(): array + public static function provideCannotManipulateUnaryRelationQuery(): array { return [ 'has_one' => [ @@ -1458,7 +1458,7 @@ public function testManipulatingEagerloadingQueryNoReturn(): void ])->toArray(); } - public function provideManipulatingEagerloadingQuery(): array + public static function provideManipulatingEagerloadingQuery(): array { return [ 'nested has_many' => [ diff --git a/tests/php/ORM/DataListTest.php b/tests/php/ORM/DataListTest.php index b5fbdf63a64..399140b6ea0 100755 --- a/tests/php/ORM/DataListTest.php +++ b/tests/php/ORM/DataListTest.php @@ -89,7 +89,7 @@ public function testFilterDataObjectByCreatedDate() $this->assertEquals(2, count($list ?? [])); } - public function provideDefaultCaseSensitivity() + public static function provideDefaultCaseSensitivity() { return [ [ @@ -203,7 +203,7 @@ public function testListCreationSortAndLimit() $this->assertEquals(['Joe', 'Phil'], $list->limit(2, 1)->column('Name')); } - public function limitDataProvider(): array + public static function limitDataProvider(): array { return [ 'no limit' => [null, 0, 3], @@ -304,7 +304,7 @@ public function testSql() $this->assertSQLEquals($expected, $list->sql($parameters)); } - public function provideJoin() + public static function provideJoin() { return [ [ @@ -680,7 +680,7 @@ public function testSortWithCompositeSyntax() public function testSortInvalidParameters() { $this->expectException(InvalidArgumentException::class); - $this->expectDeprecationMessage('Fans is not a linear relation on model SilverStripe\ORM\Tests\DataObjectTest\Player'); + $this->expectExceptionMessage('Fans is not a linear relation on model SilverStripe\ORM\Tests\DataObjectTest\Player'); $list = Team::get(); $list->sort('Founder.Fans.Surname'); // Can't sort on has_many } @@ -2005,7 +2005,7 @@ public function testRawSqlOrderBy(string $sort, string $type): void Team::get()->orderBy($sort)->column('ID'); } - public function provideRawSqlSortException(): array + public static function provideRawSqlSortException(): array { return [ ['Title', 'valid|valid'], @@ -2047,7 +2047,7 @@ public function testSortDirectionValidationTwoArgs(string $direction, string $ty Team::get()->sort('Title', $direction)->column('ID'); } - public function provideSortDirectionValidationTwoArgs(): array + public static function provideSortDirectionValidationTwoArgs(): array { return [ ['ASC', 'valid'], @@ -2080,7 +2080,7 @@ public function testSortScalarValues(mixed $emtpyValue, string $type): void $this->assertSame(['Subteam 1'], $list->limit(1)->column('Title')); } - public function provideSortScalarValues(): array + public static function provideSortScalarValues(): array { return [ ['', 'empty-scalar'], @@ -2274,7 +2274,7 @@ public function testRelation(string $parentClass, string $relation, ?array $expe } } - public function provideRelation() + public static function provideRelation() { return [ 'many_many' => [ @@ -2326,7 +2326,7 @@ public function testCreateDataObject(string $dataClass, string $realClass, array } } - public function provideCreateDataObject() + public static function provideCreateDataObject() { return [ 'no ClassName' => [ diff --git a/tests/php/ORM/DataObjectSchemaTest.php b/tests/php/ORM/DataObjectSchemaTest.php index daa14152f68..6ec273e2c68 100644 --- a/tests/php/ORM/DataObjectSchemaTest.php +++ b/tests/php/ORM/DataObjectSchemaTest.php @@ -168,7 +168,7 @@ public function testFieldSpec(array $args, array $expected): void $this->assertEquals($expected, $schema->fieldSpecs(...$args)); } - public function provideFieldSpec(): array + public static function provideFieldSpec(): array { return [ 'just pass a class' => [ @@ -409,7 +409,7 @@ public function testHasOneComponent(string $class, string $component, string $ex $this->assertSame($expected, DataObject::getSchema()->hasOneComponent($class, $component)); } - public function provideHasOneComponent(): array + public static function provideHasOneComponent(): array { return [ [ @@ -446,7 +446,7 @@ public function testHasOneComponentHandlesMultipleRelations(string $class, strin ); } - public function provideHasOneComponentHandlesMultipleRelations(): array + public static function provideHasOneComponentHandlesMultipleRelations(): array { return [ [ diff --git a/tests/php/ORM/DataObjectTest.php b/tests/php/ORM/DataObjectTest.php index 5bb51505dcb..5a51ecf2d89 100644 --- a/tests/php/ORM/DataObjectTest.php +++ b/tests/php/ORM/DataObjectTest.php @@ -113,7 +113,7 @@ public function testSingleton($inst, $defaultValue, $altDefaultValue) } } - public function provideSingletons() + public static function provideSingletons() { // because PHPUnit evaluates test providers *before* setUp methods // any extensions added in the setUp methods won't be available @@ -2674,7 +2674,7 @@ public function testSettersAndGettersAreRespected() $this->assertSame('SOME VALUE', $obj->MyTestField); } - public function provideTestGetDatabaseBackedField() + public static function provideTestGetDatabaseBackedField() { return [ ['Captain.IsRetired', 'Captain.IsRetired'], diff --git a/tests/php/ORM/DataQueryTest.php b/tests/php/ORM/DataQueryTest.php index b0cfc9103ae..679561396b2 100644 --- a/tests/php/ORM/DataQueryTest.php +++ b/tests/php/ORM/DataQueryTest.php @@ -10,6 +10,7 @@ use SilverStripe\ORM\Queries\SQLSelect; use SilverStripe\ORM\Tests\DataQueryTest\ObjectE; use SilverStripe\Security\Member; +use SilverStripe\ORM\Tests\DataQueryTest\DataQueryTestException; class DataQueryTest extends SapphireTest { @@ -35,6 +36,28 @@ class DataQueryTest extends SapphireTest SQLSelectTest\TestChild::class, ]; + /** + * @param callable|null $oldHandler + */ + private $oldHandler = null; + + protected function setup(): void + { + // Use custom error handler to allow the use of expectException() to catch errors + // which is required in testFieldCollision(). PHPUnit does not support expecting errors + parent::setup(); + $this->oldHandler = set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) { + throw new DataQueryTestException($errstr); + }); + } + + protected function tearDown(): void + { + restore_error_handler(); + $this->oldHandler = null; + parent::tearDown(); + } + public function testSortByJoinedFieldRetainsSourceInformation() { $bar = new DataQueryTest\ObjectC(); @@ -56,7 +79,7 @@ public function testSortByJoinedFieldRetainsSourceInformation() $this->assertEquals('Foo', $result['Title']); } - public function provideJoins() + public static function provideJoins() { return [ [ @@ -116,7 +139,7 @@ public function testApplyRelationMultiRelational(string $relation): void $this->assertStringContainsString($joinAliasWithQuotes . '."MultiRelationalClass" = "DataQueryTest_ObjectHasMultiRelationalHasMany"."ClassName"', $dq->sql()); } - public function provideApplyRelationMultiRelational(): array + public static function provideApplyRelationMultiRelational(): array { return [ 'relation1' => [ @@ -215,7 +238,7 @@ public function testRelationOrderWithCustomJoin() $this->assertTrue(true); } - public function provideFieldCollision() + public static function provideFieldCollision() { return [ 'allow collisions' => [true], @@ -235,8 +258,8 @@ public function testFieldCollision($allowCollisions) if ($allowCollisions) { $this->assertSQLContains('THEN "DataQueryTest_B"."Title" WHEN COALESCE(NULL, 1) AS "Title" IS NOT NULL THEN COALESCE(NULL, 1) AS "Title" ELSE NULL END AS "Title"', $dataQuery->sql()); } else { - $this->expectError(); - $this->expectErrorMessageMatches('/^Bad collision item /'); + $this->expectException(DataQueryTestException::class); + $this->expectExceptionMessageMatches('/^Bad collision item /'); } $dataQuery->getFinalisedQuery(); @@ -604,7 +627,7 @@ public function testExistsCreatesFunctionalQueries() ); } - public function provideWith() + public static function provideWith() { return [ // Simple scenarios to test auto-join functionality diff --git a/tests/php/ORM/DataQueryTest/DataQueryTestException.php b/tests/php/ORM/DataQueryTest/DataQueryTestException.php new file mode 100644 index 00000000000..cc15815b945 --- /dev/null +++ b/tests/php/ORM/DataQueryTest/DataQueryTestException.php @@ -0,0 +1,10 @@ +addRow($row); } - public function provideAddRowBadID() + public static function provideAddRowBadID() { return [ [['ID' => null]], @@ -286,7 +286,7 @@ public function testIteration(string $dataListClass): void $this->iterate($list, $rows, array_column($rows, 'ID')); } - public function provideIteration() + public static function provideIteration() { return [ [DataList::class], @@ -354,7 +354,7 @@ public function testFilter( $this->iterate($list, $rows, array_column($rows, 'ID')); } - public function provideFilter(): array + public static function provideFilter(): array { $rows = $this->getBasicRecordRows(); return [ @@ -575,7 +575,7 @@ public function testFilterAnyWithSearchfilters(array $filter, array $expectedIDs $this->iterate($list, $rows, array_column($rows, 'ID')); } - public function provideFilterAnyWithSearchFilters() + public static function provideFilterAnyWithSearchFilters() { return [ // test a couple of search filters @@ -618,7 +618,7 @@ public function provideFilterAnyWithSearchFilters() ]; } - public function provideExcludeWithSearchfilters() + public static function provideExcludeWithSearchfilters() { // If it's included in the filter test, then it's excluded in the exclude test, // so we can just use the same scenarios and reverse the expected results. @@ -665,7 +665,7 @@ public function testExcludeWithSearchfilters(array $filter, array $expectedIDs): $this->iterate($list, $rows, array_column($rows, 'ID')); } - public function provideExcludeAnyWithSearchfilters() + public static function provideExcludeAnyWithSearchfilters() { // If it's included in the filterAny test, then it's excluded in the excludeAny test, // so we can just use the same scenarios and reverse the expected results. @@ -737,7 +737,7 @@ public function testFilterByWrongNumArgs(...$args) $list->filter(...$args); } - public function provideFilterByWrongNumArgs() + public static function provideFilterByWrongNumArgs() { return [ 0 => [], @@ -768,7 +768,7 @@ public function testLimitAndOffset($length, $offset, $expectedCount, $expectExce $this->assertCount($expectedCount, $list->limit($length, $offset)->toArray()); } - public function provideLimitAndOffset(): array + public static function provideLimitAndOffset(): array { return [ 'no limit' => [null, 0, 3], @@ -1162,7 +1162,7 @@ public function testSortInvalidParameters(string $sort, string $type): void /** * @see DataListTest::provideRawSqlSortException() */ - public function provideSortInvalidParameters(): array + public static function provideSortInvalidParameters(): array { return [ ['Title', 'valid'], @@ -1203,7 +1203,7 @@ public function testSortDirectionValidationTwoArgs(string $direction, string $ty $this->getListWithRecords(Team::class)->sort('Title', $direction)->column('ID'); } - public function provideSortDirectionValidationTwoArgs(): array + public static function provideSortDirectionValidationTwoArgs(): array { return [ ['ASC', 'valid'], @@ -1236,7 +1236,7 @@ public function testSortScalarValues(mixed $emtpyValue, string $type): void $this->assertSame(['Subteam 1'], $list->limit(1)->column('Title')); } - public function provideSortScalarValues(): array + public static function provideSortScalarValues(): array { return [ ['', 'empty-scalar'], @@ -1261,7 +1261,7 @@ public function testSortNull(): void $this->assertSame($order, $list->column('ID')); } - public function provideSortMatchesDataList() + public static function provideSortMatchesDataList() { // These will be used to make fixtures // We don't use a fixtures yaml file here because we want a full DataList of only @@ -1500,7 +1500,7 @@ public function testFilterAnyAggregate() $list->filterAny(['Players.Count()' => 2]); } - public function provideCantFilterByRelation() + public static function provideCantFilterByRelation() { return [ 'many_many' => [ @@ -1544,7 +1544,7 @@ public function testFilterByNull(string $filterMethod, array $filter, array $exp $this->assertListEquals($expected, $filteredList); } - public function provideFilterByNull() + public static function provideFilterByNull() { return [ 'Filter by null email' => [ @@ -1812,7 +1812,7 @@ public function testExcludeOnFilter(array $filter, array $exclude, array $expect $this->assertListEquals($expected, $list->sort('Name')); } - public function provideExcludeOnFilter() + public static function provideExcludeOnFilter() { return [ [ @@ -2139,7 +2139,7 @@ public function testRelationEagerLoaded(string $parentClass, string $relation, ? } } - public function provideRelation() + public static function provideRelation() { return [ 'many_many' => [ @@ -2214,7 +2214,7 @@ public function testCreateDataObject(string $dataClass, string $realClass, array } } - public function provideCreateDataObject() + public static function provideCreateDataObject() { return [ 'no ClassName' => [ @@ -2325,7 +2325,7 @@ public function testGetExtraDataBadListType(string $listClass) $list->getExtraData('Teams', 1); } - public function provideGetExtraDataBadListType() + public static function provideGetExtraDataBadListType() { return [ [HasManyList::class], diff --git a/tests/php/ORM/Filters/EndsWithFilterTest.php b/tests/php/ORM/Filters/EndsWithFilterTest.php index d8825d26c4c..b02e91ed2a6 100644 --- a/tests/php/ORM/Filters/EndsWithFilterTest.php +++ b/tests/php/ORM/Filters/EndsWithFilterTest.php @@ -10,7 +10,7 @@ class EndsWithFilterTest extends SapphireTest { - public function provideMatches() + public static function provideMatches() { $scenarios = [ // without modifiers diff --git a/tests/php/ORM/Filters/ExactMatchFilterTest.php b/tests/php/ORM/Filters/ExactMatchFilterTest.php index 61cf04d42df..67685c4ed0f 100644 --- a/tests/php/ORM/Filters/ExactMatchFilterTest.php +++ b/tests/php/ORM/Filters/ExactMatchFilterTest.php @@ -31,7 +31,7 @@ public function testUsePlaceholders(?bool $expectedID, ?bool $expectedTitle, boo $this->assertSame($expectedTitle, $titleQueryUsesPlaceholders); } - public function provideUsePlaceholders(): array + public static function provideUsePlaceholders(): array { $ids = [1, 2, 3]; $taskTitles = array_map(fn($i) => "Task $i", $ids); @@ -96,7 +96,7 @@ private function usesPlaceholders(callable $fn): array return [$idQueryUsesPlaceholders, $titleQueryUsesPlaceholders]; } - public function provideMatches() + public static function provideMatches() { $scenarios = [ // without modifiers diff --git a/tests/php/ORM/Filters/GreaterThanFilterTest.php b/tests/php/ORM/Filters/GreaterThanFilterTest.php index 6a7bcf284cc..a01d6c4a034 100644 --- a/tests/php/ORM/Filters/GreaterThanFilterTest.php +++ b/tests/php/ORM/Filters/GreaterThanFilterTest.php @@ -9,7 +9,7 @@ class GreaterThanFilterTest extends SapphireTest { - public function provideMatches() + public static function provideMatches() { $scenarios = [ // without modifiers diff --git a/tests/php/ORM/Filters/GreaterThanOrEqualFilterTest.php b/tests/php/ORM/Filters/GreaterThanOrEqualFilterTest.php index c93f3a8a9e0..a36d838e236 100644 --- a/tests/php/ORM/Filters/GreaterThanOrEqualFilterTest.php +++ b/tests/php/ORM/Filters/GreaterThanOrEqualFilterTest.php @@ -9,7 +9,7 @@ class GreaterThanOrEqualFilterTest extends SapphireTest { - public function provideMatches() + public static function provideMatches() { $scenarios = [ // without modifiers diff --git a/tests/php/ORM/Filters/LessThanFilterTest.php b/tests/php/ORM/Filters/LessThanFilterTest.php index ac8f5fa4e1f..f81586c4b10 100644 --- a/tests/php/ORM/Filters/LessThanFilterTest.php +++ b/tests/php/ORM/Filters/LessThanFilterTest.php @@ -9,7 +9,7 @@ class LessThanFilterTest extends SapphireTest { - public function provideMatches() + public static function provideMatches() { $scenarios = [ // without modifiers diff --git a/tests/php/ORM/Filters/LessThanOrEqualFilterTest.php b/tests/php/ORM/Filters/LessThanOrEqualFilterTest.php index 30a0f3078a1..794da303fdb 100644 --- a/tests/php/ORM/Filters/LessThanOrEqualFilterTest.php +++ b/tests/php/ORM/Filters/LessThanOrEqualFilterTest.php @@ -9,7 +9,7 @@ class LessThanOrEqualFilterTest extends SapphireTest { - public function provideMatches() + public static function provideMatches() { $scenarios = [ // without modifiers diff --git a/tests/php/ORM/Filters/PartialMatchFilterTest.php b/tests/php/ORM/Filters/PartialMatchFilterTest.php index f4ad899427d..170cb405866 100644 --- a/tests/php/ORM/Filters/PartialMatchFilterTest.php +++ b/tests/php/ORM/Filters/PartialMatchFilterTest.php @@ -10,7 +10,7 @@ class PartialMatchFilterTest extends SapphireTest { - public function provideMatches() + public static function provideMatches() { $scenarios = [ // without modifiers diff --git a/tests/php/ORM/Filters/StartsWithFilterTest.php b/tests/php/ORM/Filters/StartsWithFilterTest.php index 855020f53a6..6b8b3ddc9ee 100644 --- a/tests/php/ORM/Filters/StartsWithFilterTest.php +++ b/tests/php/ORM/Filters/StartsWithFilterTest.php @@ -10,7 +10,7 @@ class StartsWithFilterTest extends SapphireTest { - public function provideMatches() + public static function provideMatches() { $scenarios = [ // without modifiers diff --git a/tests/php/ORM/HasManyListTest.php b/tests/php/ORM/HasManyListTest.php index 143412b1007..082ea17d92d 100644 --- a/tests/php/ORM/HasManyListTest.php +++ b/tests/php/ORM/HasManyListTest.php @@ -214,7 +214,7 @@ public function testForForeignIDPlaceholders(bool $config, bool $useInt, bool $e $this->assertSame($expectedIDs, $newCommentsList->column('ID')); } - public function provideForForeignIDPlaceholders(): array + public static function provideForForeignIDPlaceholders(): array { return [ 'config false' => [ diff --git a/tests/php/ORM/HierarchyCachingTest.php b/tests/php/ORM/HierarchyCachingTest.php index 8070fbe26d7..395cbda513d 100644 --- a/tests/php/ORM/HierarchyCachingTest.php +++ b/tests/php/ORM/HierarchyCachingTest.php @@ -43,7 +43,7 @@ public static function setUpBeforeClass(): void ); } - public function cacheNumChildrenDataProvider() + public static function cacheNumChildrenDataProvider() { return [ [TestObject::class, 'obj1', false, 0, 'childless object should have a numChildren of 0'], @@ -78,7 +78,7 @@ public function testNumChildrenCache($className, $identifier, $cache, $expected, } } - public function prepopulateCacheNumChildrenDataProvider() + public static function prepopulateCacheNumChildrenDataProvider() { return [ [ diff --git a/tests/php/ORM/ListDecoratorTest.php b/tests/php/ORM/ListDecoratorTest.php index e0c011a9009..a2a59b0520c 100644 --- a/tests/php/ORM/ListDecoratorTest.php +++ b/tests/php/ORM/ListDecoratorTest.php @@ -95,7 +95,7 @@ public function testSort($input) /** * @return array[] */ - public function filterProvider() + public static function filterProvider() { return [ ['Name', 'Bob'], diff --git a/tests/php/ORM/ManyManyListTest.php b/tests/php/ORM/ManyManyListTest.php index f29856568bc..1336a7e2717 100644 --- a/tests/php/ORM/ManyManyListTest.php +++ b/tests/php/ORM/ManyManyListTest.php @@ -639,7 +639,7 @@ public function testForForeignIDPlaceholders(bool $config, bool $useInt, bool $e $this->assertEqualsCanonicalizing($expectedIDs, $newPlayersList->column('ID')); } - public function provideForForeignIDPlaceholders(): array + public static function provideForForeignIDPlaceholders(): array { return [ 'config false' => [ diff --git a/tests/php/ORM/ManyManyThroughListTest.php b/tests/php/ORM/ManyManyThroughListTest.php index 187e3023da2..3871ec11fe5 100644 --- a/tests/php/ORM/ManyManyThroughListTest.php +++ b/tests/php/ORM/ManyManyThroughListTest.php @@ -113,7 +113,7 @@ public function testSorting($sort, $expected) /** * @return array[] */ - public function sortingProvider() + public static function sortingProvider() { return [ 'nothing passed (default)' => [ @@ -163,7 +163,7 @@ public function sortingProvider() ]; } - public function provideAdd(): array + public static function provideAdd(): array { return [ [ @@ -207,7 +207,7 @@ public function testAdd(string $parentClass, string $joinClass, string $joinProp $this->assertEquals('new join record', $newItem->$joinProperty->Title); } - public function provideRemove(): array + public static function provideRemove(): array { return [ [ @@ -576,7 +576,7 @@ public function testForForeignIDPlaceholders(bool $config, bool $useInt, bool $e $this->assertEqualsCanonicalizing($expectedIDs, $newItemsList->column('ID')); } - public function provideForForeignIDPlaceholders(): array + public static function provideForForeignIDPlaceholders(): array { return [ 'config false' => [ diff --git a/tests/php/ORM/MySQLDatabaseTest.php b/tests/php/ORM/MySQLDatabaseTest.php index 51461040e4c..47226eaec1c 100644 --- a/tests/php/ORM/MySQLDatabaseTest.php +++ b/tests/php/ORM/MySQLDatabaseTest.php @@ -113,7 +113,7 @@ public function testAffectedRows() $this->assertEquals(1, DB::affected_rows()); } - public function provideSupportsCte() + public static function provideSupportsCte() { return [ // mysql unsupported diff --git a/tests/php/ORM/MySQLiConnectorTest.php b/tests/php/ORM/MySQLiConnectorTest.php index 8da8b65dd1b..ab4a48e17b4 100644 --- a/tests/php/ORM/MySQLiConnectorTest.php +++ b/tests/php/ORM/MySQLiConnectorTest.php @@ -107,7 +107,7 @@ public function testConnectionCollationControl($charset, $defaultCollation, $cus unset($cset, $connection, $connector, $config); } - public function charsetProvider() + public static function charsetProvider() { return [ ['ascii', 'ascii_general_ci', 'ascii_bin'], diff --git a/tests/php/ORM/SQLSelectTest.php b/tests/php/ORM/SQLSelectTest.php index d915a676c29..08eeeabefc6 100755 --- a/tests/php/ORM/SQLSelectTest.php +++ b/tests/php/ORM/SQLSelectTest.php @@ -74,7 +74,7 @@ public function testUnlimitedRowCount() } } - public function provideIsEmpty() + public static function provideIsEmpty() { return [ [ @@ -118,7 +118,7 @@ public function testEmptyQueryReturnsNothing() $this->assertSQLEquals('', $query->sql($parameters)); } - public function provideSelectFrom() + public static function provideSelectFrom() { return [ [ @@ -818,7 +818,7 @@ public function testLimitSetFromClauseString() $this->assertEquals(10, $limit['start']); } - public function provideParameterisedJoinSQL() + public static function provideParameterisedJoinSQL() { return [ [ @@ -865,7 +865,7 @@ public function testParameterisedJoinSQL($joinMethod, $joinType) $query->execute(); } - public function provideUnion() + public static function provideUnion() { return [ // Note that a default (null) UNION is identical to a DISTINCT UNION @@ -954,7 +954,7 @@ public function testBaseTableAliases() ); } - public function provideWith() + public static function provideWith() { // Each of these examples shows it working with aliased implicit columns, and with explicit CTE columns. // Most of these examples are derived from https://dev.mysql.com/doc/refman/8.4/en/with.html @@ -1328,7 +1328,7 @@ public function testMultipleWithDuplicateName() $select->addWith('cte', new SQLSelect()); } - public function subqueryProvider() + public static function subqueryProvider() { return [ 'no-explicit-alias-string' => ['( SELECT DISTINCT "SQLSelectTest_DO"."ClassName" FROM "SQLSelectTest_DO") AS "FINAL"'], @@ -1353,7 +1353,7 @@ public function testSubqueries($subquery) ); } - public function addFromProvider() + public static function addFromProvider() { return [ 'string' => [ diff --git a/tests/php/ORM/Search/BasicSearchContextTest.php b/tests/php/ORM/Search/BasicSearchContextTest.php index 58c97aacd03..61d9fea4208 100644 --- a/tests/php/ORM/Search/BasicSearchContextTest.php +++ b/tests/php/ORM/Search/BasicSearchContextTest.php @@ -96,7 +96,7 @@ public function testResultSetFilterReturnsExpectedCount() $this->assertEquals(1, $results->Count()); } - public function provideApplySearchFilters() + public static function provideApplySearchFilters() { $idFilter = new ExactMatchFilter('ID'); $idFilter->setModifiers(['nocase']); @@ -146,7 +146,7 @@ public function testApplySearchFilters(array $searchParams, ?array $filters, arr $this->assertSame($expected, $reflectionApplySearchFilters->invoke($context, $searchParams)); } - public function provideGetGeneralSearchFilterTerm() + public static function provideGetGeneralSearchFilterTerm() { return [ 'defaults to case-insensitive partial match' => [ @@ -190,7 +190,7 @@ public function testGetGeneralSearchFilterTerm(?string $filterType, ?SearchFilte $this->assertSame($expected, $reflectionGetGeneralSearchFilterTerm->invoke($context, 'MyField')); } - public function provideGetQuery() + public static function provideGetQuery() { // Note that the search TERM is the same for both scenarios, // but because the search FIELD is different, we get different results. diff --git a/tests/php/ORM/UniqueKey/ServiceTest.php b/tests/php/ORM/UniqueKey/ServiceTest.php index d0e78a969ae..f96137f0127 100644 --- a/tests/php/ORM/UniqueKey/ServiceTest.php +++ b/tests/php/ORM/UniqueKey/ServiceTest.php @@ -40,7 +40,7 @@ public function testUniqueKey(int $id, string $class, bool $extraKeys, string $e } } - public function uniqueKeysProvider(): array + public static function uniqueKeysProvider(): array { return [ [1, River::class, false, 'River-1-8d3310e232f75a01f5a0c9344655263d'], diff --git a/tests/php/Security/MemberTest.php b/tests/php/Security/MemberTest.php index cea9ab172ef..875b8848ab5 100644 --- a/tests/php/Security/MemberTest.php +++ b/tests/php/Security/MemberTest.php @@ -1837,7 +1837,7 @@ public function testMapInCMSGroups(array $groupFixtures, array $groupCodes, arra $this->assertEqualsCanonicalizing($expectedUsers, $result->keys()); } - public function provideMapInCMSGroups() + public static function provideMapInCMSGroups() { // Note: "ADMIN User" is not from the fixtures, that user is created by $this->logInWithPermission('ADMIN') return [ diff --git a/tests/php/Security/Member_GroupSetTest.php b/tests/php/Security/Member_GroupSetTest.php index a7992a1464a..f57e833148d 100644 --- a/tests/php/Security/Member_GroupSetTest.php +++ b/tests/php/Security/Member_GroupSetTest.php @@ -37,7 +37,7 @@ public function testForForeignIDPlaceholders(bool $config, bool $useInt, bool $e $this->assertEqualsCanonicalizing($expectedIDs, $newGroupList->column('ID')); } - public function provideForForeignIDPlaceholders(): array + public static function provideForForeignIDPlaceholders(): array { return [ 'config false' => [ diff --git a/tests/php/Security/RememberLoginHashTest.php b/tests/php/Security/RememberLoginHashTest.php index ced2991af5d..d5d45a0d6cc 100644 --- a/tests/php/Security/RememberLoginHashTest.php +++ b/tests/php/Security/RememberLoginHashTest.php @@ -32,7 +32,7 @@ protected function setUp(): void ]; } - public function clearScenarios() + public static function clearScenarios() { return [ 'logout across devices' => [true, 'current', ['secondary'], ['current', 'other']], @@ -132,7 +132,7 @@ public function testRenew($replaceToken) } } - public function provideRenew(): array + public static function provideRenew(): array { return [ [true], diff --git a/tests/php/View/AttributesHTMLTest.php b/tests/php/View/AttributesHTMLTest.php index 36f48b89a69..177e2009567 100644 --- a/tests/php/View/AttributesHTMLTest.php +++ b/tests/php/View/AttributesHTMLTest.php @@ -8,7 +8,7 @@ class AttributesHTMLTest extends SapphireTest { - public function provideGetAttribute(): array + public static function provideGetAttribute(): array { return [ 'empty string' => ['test', '', 'Empty string is not converted to a different falsy value'], diff --git a/tests/php/View/Parsers/HTMLValueTest.php b/tests/php/View/Parsers/HTMLValueTest.php index 52563498ace..d4db76b9696 100644 --- a/tests/php/View/Parsers/HTMLValueTest.php +++ b/tests/php/View/Parsers/HTMLValueTest.php @@ -161,7 +161,7 @@ public function testValidHTMLInNoscriptTags() } } - public function provideOnlyStripIntendedTags(): array + public static function provideOnlyStripIntendedTags(): array { return [ [ diff --git a/tests/php/View/Parsers/HtmlDiffTest.php b/tests/php/View/Parsers/HtmlDiffTest.php index d89723cdd2f..35344294290 100644 --- a/tests/php/View/Parsers/HtmlDiffTest.php +++ b/tests/php/View/Parsers/HtmlDiffTest.php @@ -67,7 +67,7 @@ public function testEndOfLineDoesntNeedHandling() $this->assertSame($expected, $differ->diffToArray($from, $to)); } - public function provideCompareHtml(): array + public static function provideCompareHtml(): array { return [ [ diff --git a/tests/php/View/Parsers/ShortcodeParserTest.php b/tests/php/View/Parsers/ShortcodeParserTest.php index 2853232d202..1119edb9c01 100644 --- a/tests/php/View/Parsers/ShortcodeParserTest.php +++ b/tests/php/View/Parsers/ShortcodeParserTest.php @@ -79,7 +79,7 @@ public function testNotRegisteredShortcode() ); } - public function simpleTagDataProvider() + public static function simpleTagDataProvider() { return [ ['[test_shortcode]'], @@ -103,7 +103,7 @@ public function testSimpleTag($test) $this->assertEquals('test_shortcode', $this->tagName, $test); } - public function oneArgumentDataProvider() + public static function oneArgumentDataProvider() { return [ ['[test_shortcode foo="bar"]'], @@ -138,7 +138,7 @@ public function testMultipleArguments() $this->assertEquals('test_shortcode', $this->tagName); } - public function emptyArgumentsDataProvider() + public static function emptyArgumentsDataProvider() { return [ ['[test_shortcode foo=""]'], diff --git a/tests/php/View/SSViewerTest.php b/tests/php/View/SSViewerTest.php index f1eb6d76bed..d51d1669973 100644 --- a/tests/php/View/SSViewerTest.php +++ b/tests/php/View/SSViewerTest.php @@ -567,7 +567,7 @@ public function testCurrentScopeLoopWith() $this->assertEquals("SubKid1SubKid2Number6", $result, "Loop in current scope works"); } - public function provideArgumentTypes() + public static function provideArgumentTypes() { return [ [ @@ -706,7 +706,7 @@ public function testLoopWhitespace() ); } - public function typePreservationDataProvider() + public static function typePreservationDataProvider() { return [ // Null @@ -1034,7 +1034,7 @@ public function testIfBlocks() ); } - public function provideIfBlockWithIterable(): array + public static function provideIfBlockWithIterable(): array { $scenarios = [ 'empty array' => [ @@ -1387,7 +1387,7 @@ public function testCastingHelpers() ); } - public function provideLoop(): array + public static function provideLoop(): array { return [ 'nested array and iterator' => [ @@ -1431,7 +1431,7 @@ public function testLoop(iterable $iterable, string $template, string $expected) $this->assertEqualIgnoringWhitespace($expected, $this->render($template, $data)); } - public function provideCountIterable(): array + public static function provideCountIterable(): array { $scenarios = [ 'empty array' => [ diff --git a/tests/php/View/ViewableDataTest.php b/tests/php/View/ViewableDataTest.php index 9f24042cd6b..cf377736e74 100644 --- a/tests/php/View/ViewableDataTest.php +++ b/tests/php/View/ViewableDataTest.php @@ -284,7 +284,7 @@ public function testDynamicData() $this->assertSame($obj, $viewableData->abc); } - public function provideWrapArrayInObj(): array + public static function provideWrapArrayInObj(): array { return [ 'empty array' => [ diff --git a/tests/php/i18n/i18nTest.php b/tests/php/i18n/i18nTest.php index 79882c9407f..a471ecfe911 100644 --- a/tests/php/i18n/i18nTest.php +++ b/tests/php/i18n/i18nTest.php @@ -426,7 +426,7 @@ public function testTranslate() ); } - public function pluralisationDataProvider() + public static function pluralisationDataProvider() { return [ // English - 2 plural forms