From 49e7fb0653c276e42c2eed3ba83cda12c0b1a195 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 10 Sep 2024 11:29:17 +1200 Subject: [PATCH] DEP Use PHPUnit 11 --- tests/php/Extension/FluentExtensionTest.php | 5 +++-- .../Extension/FluentSiteTreeExtensionTest.php | 13 +++++++------ .../Extension/FluentVersionedExtensionTest.php | 4 ++-- .../LocalisedCopyTest/DuplicationTest.php | 13 +++++++------ tests/php/Extension/LocalisedVersionsTest.php | 11 ++++++----- .../Middleware/DetectLocaleMiddlewareTest.php | 17 +++++++++-------- .../php/Middleware/InitStateMiddlewareTest.php | 5 +++-- tests/php/Model/LocalDateTimeTest.php | 5 +++-- tests/php/Model/LocaleTest.php | 5 +++-- .../Task/InitialPageLocalisationTaskTest.php | 5 +++-- 10 files changed, 46 insertions(+), 37 deletions(-) diff --git a/tests/php/Extension/FluentExtensionTest.php b/tests/php/Extension/FluentExtensionTest.php index f6671d4f..993dbe3c 100644 --- a/tests/php/Extension/FluentExtensionTest.php +++ b/tests/php/Extension/FluentExtensionTest.php @@ -19,6 +19,7 @@ use TractorCow\Fluent\Tests\Extension\FluentExtensionTest\TestRelationPage; use TractorCow\Fluent\Tests\Extension\FluentExtensionTest\UnlocalisedChild; use TractorCow\Fluent\Tests\Extension\Stub\FluentStubObject; +use PHPUnit\Framework\Attributes\DataProvider; class FluentExtensionTest extends SapphireTest { @@ -283,12 +284,12 @@ public function testLocalisedCopyClassNameChange(): void /** * Ensure that records can be sorted in their locales * - * @dataProvider sortRecordProvider * @param string $locale * @param string[] $sortArgs * @param string[] $expected * @group exclude-from-travis */ + #[DataProvider('sortRecordProvider')] public function testLocalisedFieldsCanBeSorted($locale, array $sortArgs, $expected, $useOrderBy = false) { FluentState::singleton()->withState(function (FluentState $newState) use ($locale, $sortArgs, $expected, $useOrderBy) { @@ -307,7 +308,7 @@ public function testLocalisedFieldsCanBeSorted($locale, array $sortArgs, $expect /** * @return array[] Keys: Locale, sorting arguments, expected titles in result */ - public function sortRecordProvider() + public static function sortRecordProvider() { return [ /** diff --git a/tests/php/Extension/FluentSiteTreeExtensionTest.php b/tests/php/Extension/FluentSiteTreeExtensionTest.php index dac0d88e..515edb5a 100644 --- a/tests/php/Extension/FluentSiteTreeExtensionTest.php +++ b/tests/php/Extension/FluentSiteTreeExtensionTest.php @@ -24,6 +24,7 @@ use TractorCow\Fluent\Model\Locale; use TractorCow\Fluent\Model\RecordLocale; use TractorCow\Fluent\State\FluentState; +use PHPUnit\Framework\Attributes\DataProvider; // Skip if pages module not installed if (!class_exists(SiteTree::class)) { @@ -116,7 +117,7 @@ public function testGetLocales() * - page id * - expected link */ - public function provideURLTests() + public static function provideURLTests() { return [ // Non-domain tests @@ -158,13 +159,13 @@ public function provideURLTests() /** * Test that URLS for pages are generated correctly * - * @dataProvider provideURLTests * @param string $domain * @param string $locale * @param bool $prefixDisabled * @param string $pageName * @param string $url */ + #[DataProvider('provideURLTests')] public function testFluentURLs(?string $domain, string $locale, bool $prefixDisabled, string $pageName, string $url) { FluentState::singleton()->withState( @@ -313,8 +314,8 @@ public function testUpdateCMSActionsDrafted() * @param string $localeCode * @param string $fixture * @param string $expected - * @dataProvider localePrefixUrlProvider */ + #[DataProvider('localePrefixUrlProvider')] public function testAddLocalePrefixToUrlSegment(string $localeCode, string $fixture, string $expected) { FluentState::singleton()->withState( @@ -473,7 +474,7 @@ public function testHomeNotVisibleInCMSOneConfigExact() /** * @return array[] */ - public function localePrefixUrlProvider() + public static function localePrefixUrlProvider() { return [ 'locale_with_domain' => ['en_US', 'about', 'http://www.example.com/usa/'], @@ -488,8 +489,8 @@ public function localePrefixUrlProvider() * @param bool $isFrontend * @param int $expected * @throws ValidationException - * @dataProvider localeFallbackProvider */ + #[DataProvider('localeFallbackProvider')] public function testPageVisibilityWithFallback($cmsMode, $frontendMode, bool $isFrontend, int $expected) { Config::modify() @@ -521,7 +522,7 @@ public function testPageVisibilityWithFallback($cmsMode, $frontendMode, bool $is }); } - public function localeFallbackProvider(): array + public static function localeFallbackProvider(): array { return [ 'Frontend / no inheritance' => [ diff --git a/tests/php/Extension/FluentVersionedExtensionTest.php b/tests/php/Extension/FluentVersionedExtensionTest.php index 6beccc0f..64a72239 100644 --- a/tests/php/Extension/FluentVersionedExtensionTest.php +++ b/tests/php/Extension/FluentVersionedExtensionTest.php @@ -116,7 +116,7 @@ public function testLocalisedStageCacheIsUsedForIsLocalisedInLocale() /** @var FluentVersionedExtension $extension */ $extension = $this->getMockBuilder(FluentVersionedExtension::class) - ->setMethods(['findRecordInLocale']) + ->onlyMethods(['findRecordInLocale']) ->getMock(); $extension->setOwner($page); @@ -142,7 +142,7 @@ public function testIdsInLocaleCacheIsUsedForIsLocalisedInLocale() /** @var FluentVersionedExtension $extension */ $extension = $this->getMockBuilder(FluentVersionedExtension::class) - ->setMethods(['findRecordInLocale']) + ->onlyMethods(['findRecordInLocale']) ->getMock(); $extension->setOwner($page); diff --git a/tests/php/Extension/LocalisedCopyTest/DuplicationTest.php b/tests/php/Extension/LocalisedCopyTest/DuplicationTest.php index 8c53604f..7468ea2e 100644 --- a/tests/php/Extension/LocalisedCopyTest/DuplicationTest.php +++ b/tests/php/Extension/LocalisedCopyTest/DuplicationTest.php @@ -5,6 +5,7 @@ use SilverStripe\Dev\SapphireTest; use TractorCow\Fluent\Extension\FluentExtension; use TractorCow\Fluent\State\FluentState; +use PHPUnit\Framework\Attributes\DataProvider; class DuplicationTest extends SapphireTest { @@ -47,8 +48,8 @@ protected function setUp(): void * desired outcome: no additional changes * * @param bool $active - * @dataProvider copyStateProvider */ + #[DataProvider('copyStateProvider')] public function testCreateWithDefinedRelation(bool $active): void { FluentState::singleton()->withState(function (FluentState $state) use ($active): void { @@ -89,8 +90,8 @@ public function testCreateWithDefinedRelation(bool $active): void * @param string $locale * @param bool $duplicated * @param bool $active - * @dataProvider localesProvider */ + #[DataProvider('localesProvider')] public function testEditWithDefinedRelation(string $locale, bool $duplicated, bool $active): void { FluentState::singleton()->withState(function (FluentState $state) use ($locale, $duplicated, $active): void { @@ -132,8 +133,8 @@ public function testEditWithDefinedRelation(string $locale, bool $duplicated, bo * desired outcome: no additional changes * * @param bool $active - * @dataProvider copyStateProvider */ + #[DataProvider('copyStateProvider')] public function testCreateWithInheritedRelation(bool $active): void { FluentState::singleton()->withState(function (FluentState $state) use ($active): void { @@ -185,8 +186,8 @@ public function testCreateWithInheritedRelation(bool $active): void * @param string $locale * @param bool $duplicated * @param bool $active - * @dataProvider localesProvider */ + #[DataProvider('localesProvider')] public function testEditWithInheritedRelation(string $locale, bool $duplicated, bool $active): void { FluentState::singleton()->withState(function (FluentState $state) use ($locale, $duplicated, $active): void { @@ -238,7 +239,7 @@ public function testEditWithInheritedRelation(string $locale, bool $duplicated, }); } - public function localesProvider(): array + public static function localesProvider(): array { return [ ['en_NZ', false, true], @@ -248,7 +249,7 @@ public function localesProvider(): array ]; } - public function copyStateProvider(): array + public static function copyStateProvider(): array { return [ [false], diff --git a/tests/php/Extension/LocalisedVersionsTest.php b/tests/php/Extension/LocalisedVersionsTest.php index 1794e2f4..2eb24d9e 100644 --- a/tests/php/Extension/LocalisedVersionsTest.php +++ b/tests/php/Extension/LocalisedVersionsTest.php @@ -7,6 +7,7 @@ use TractorCow\Fluent\Extension\FluentVersionedExtension; use TractorCow\Fluent\State\FluentState; use TractorCow\Fluent\Tests\Extension\Stub\FluentDataObject; +use PHPUnit\Framework\Attributes\DataProvider; /** * Class LocalisedVersionsTest @@ -94,8 +95,8 @@ protected function setUp(): void /** * @param string|null $locale * @param int $expected - * @dataProvider latestVersionsProvider */ + #[DataProvider('latestVersionsProvider')] public function testGetLatestVersion(?string $locale, int $expected): void { FluentState::singleton()->withState(function (FluentState $state) use ($locale, $expected): void { @@ -114,8 +115,8 @@ public function testGetLatestVersion(?string $locale, int $expected): void /** * @param string|null $locale * @param int $expected - * @dataProvider latestVersionsProvider */ + #[DataProvider('latestVersionsProvider')] public function testGetVersionNumberByStage(?string $locale, int $expected): void { FluentState::singleton()->withState(function (FluentState $state) use ($locale, $expected): void { @@ -134,8 +135,8 @@ public function testGetVersionNumberByStage(?string $locale, int $expected): voi /** * @param string|null $locale * @param int $expected - * @dataProvider listVersionsProvider */ + #[DataProvider('listVersionsProvider')] public function testGetAllVersions(?string $locale, array $expected): void { FluentState::singleton()->withState(function (FluentState $state) use ($locale, $expected): void { @@ -217,7 +218,7 @@ public function testArchive(): void }); } - public function latestVersionsProvider(): array + public static function latestVersionsProvider(): array { return [ [null, 6], @@ -227,7 +228,7 @@ public function latestVersionsProvider(): array ]; } - public function listVersionsProvider(): array + public static function listVersionsProvider(): array { return [ [ diff --git a/tests/php/Middleware/DetectLocaleMiddlewareTest.php b/tests/php/Middleware/DetectLocaleMiddlewareTest.php index bf1f4e6c..1934a555 100644 --- a/tests/php/Middleware/DetectLocaleMiddlewareTest.php +++ b/tests/php/Middleware/DetectLocaleMiddlewareTest.php @@ -14,6 +14,7 @@ use TractorCow\Fluent\Model\Domain; use TractorCow\Fluent\Model\Locale; use TractorCow\Fluent\State\FluentState; +use PHPUnit\Framework\Attributes\DataProvider; class DetectLocaleMiddlewareTest extends SapphireTest { @@ -60,7 +61,6 @@ public function testGetPersistKey() } /** - * @dataProvider localePriorityProvider * @param string $url * @param array $routeParams * @param array $queryParams @@ -68,6 +68,7 @@ public function testGetPersistKey() * @param string $header * @param string $expected */ + #[DataProvider('localePriorityProvider')] public function testGetLocalePriority($url, $routeParams, $queryParams, $persisted, $header, $expected) { $request = new HTTPRequest('GET', $url, $queryParams); @@ -88,7 +89,7 @@ public function testGetLocalePriority($url, $routeParams, $queryParams, $persist /** * @return array[] List of tests with arguments: $url, $routeParams, $queryParams, $persisted, $header, $expected */ - public function localePriorityProvider() + public static function localePriorityProvider() { return [/* // First priority: controller routing params @@ -113,7 +114,7 @@ public function testLocaleIsAlwaysPersistedEvenIfNotSetByTheMiddleware() /** @var DetectLocaleMiddleware|PHPUnit_Framework_MockObject_MockObject $middleware */ $middleware = $this->getMockBuilder(DetectLocaleMiddleware::class) - ->setMethods(['getLocale', 'setPersistLocale']) + ->onlyMethods(['getLocale', 'setPersistLocale']) ->getMock(); $middleware->expects($this->never())->method('getLocale'); @@ -134,7 +135,7 @@ public function testLocaleIsOnlyPersistedWhenSet() /** @var DetectLocaleMiddleware|PHPUnit_Framework_MockObject_MockObject $middleware */ $middleware = $this->getMockBuilder(DetectLocaleMiddleware::class) - ->setMethods(['getLocale', 'setPersistLocale']) + ->onlyMethods(['getLocale', 'setPersistLocale']) ->getMock(); $middleware->expects($this->once())->method('getLocale')->willReturn(null); @@ -154,7 +155,7 @@ public function testLocaleIsPersistedFromCookie() $sessionData = []; $sessionMock = $this->getMockBuilder(Session::class) - ->setMethods(['set', 'getAll']) + ->onlyMethods(['set', 'getAll']) ->setConstructorArgs([$sessionData]) ->getMock(); $sessionMock->expects($this->once())->method('set')->with($key, $newLocale); @@ -180,7 +181,7 @@ public function testLocaleIsPersistedFromSession() $sessionData = [$key => $newLocale]; $sessionMock = $this->getMockBuilder(Session::class) - ->setMethods(['set', 'isStarted']) + ->onlyMethods(['set', 'isStarted']) ->setConstructorArgs([$sessionData]) ->getMock(); @@ -206,7 +207,7 @@ public function testLocaleIsNotPersistedFromSessionWhenSessionIsNotStarted() $sessionData = [$key => $newLocale]; $sessionMock = $this->getMockBuilder(Session::class) - ->setMethods(['set', 'isStarted']) + ->onlyMethods(['set', 'isStarted']) ->setConstructorArgs([$sessionData]) ->getMock(); @@ -237,7 +238,7 @@ public function testLocaleIsNotPersistedFromCookieWhenPersistCookieFalse() // // $sessionData = [$key => $newLocale]; // $sessionMock = $this->getMockBuilder(Session::class) - // ->setMethods(['set']) + // ->onlyMethods(['set']) // ->setConstructorArgs([$sessionData]) // ->getMock(); // $sessionMock->expects($this->once())->method('set')->with($key, $this->globalDefaultLocale); diff --git a/tests/php/Middleware/InitStateMiddlewareTest.php b/tests/php/Middleware/InitStateMiddlewareTest.php index 3989c35b..6f7192e4 100644 --- a/tests/php/Middleware/InitStateMiddlewareTest.php +++ b/tests/php/Middleware/InitStateMiddlewareTest.php @@ -5,15 +5,16 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\Control\HTTPRequest; use TractorCow\Fluent\Middleware\InitStateMiddleware; +use PHPUnit\Framework\Attributes\DataProvider; class InitStateMiddlewareTest extends SapphireTest { /** - * @dataProvider isFrontendProvider * @param string $url * @param array $getVars * @param string $expected */ + #[DataProvider('isFrontendProvider')] public function testGetIsFrontend($url, $getVars, $expected) { $request = new HTTPRequest('GET', $url, $getVars); @@ -24,7 +25,7 @@ public function testGetIsFrontend($url, $getVars, $expected) /** * @return array[] */ - public function isFrontendProvider() + public static function isFrontendProvider() { return [ ['admin', [], false], diff --git a/tests/php/Model/LocalDateTimeTest.php b/tests/php/Model/LocalDateTimeTest.php index db2448cb..65ff7b2a 100644 --- a/tests/php/Model/LocalDateTimeTest.php +++ b/tests/php/Model/LocalDateTimeTest.php @@ -10,6 +10,7 @@ use TractorCow\Fluent\Model\LocalDateTime; use TractorCow\Fluent\Model\Locale; use TractorCow\Fluent\State\FluentState; +use PHPUnit\Framework\Attributes\DataProvider; class LocalDateTimeTest extends SapphireTest { @@ -69,9 +70,9 @@ public function testSetValue() /** * Test all DB locales * - * @dataProvider provideTestSwitchLocales * @param $locales */ + #[DataProvider('provideTestSwitchLocales')] public function testSwitchLocales($locale, $expectedTime) { /** @var DBDatetime|FluentDateTimeExtension $date */ @@ -82,7 +83,7 @@ public function testSwitchLocales($locale, $expectedTime) }); } - public function provideTestSwitchLocales() + public static function provideTestSwitchLocales() { return [ [ diff --git a/tests/php/Model/LocaleTest.php b/tests/php/Model/LocaleTest.php index 24d95f7c..4bd22a5b 100644 --- a/tests/php/Model/LocaleTest.php +++ b/tests/php/Model/LocaleTest.php @@ -10,6 +10,7 @@ use TractorCow\Fluent\Model\Domain; use TractorCow\Fluent\Model\Locale; use TractorCow\Fluent\State\FluentState; +use PHPUnit\Framework\Attributes\DataProvider; class LocaleTest extends SapphireTest { @@ -65,11 +66,11 @@ public function testGetDefaultWithCurrentDomainArgument() } /** - * @dataProvider isLocaleProvider * @param string $locale * @param string $input * @param bool $expected */ + #[DataProvider('isLocaleProvider')] public function testIsLocale($locale, $input, $expected) { $localeObj = Locale::create()->setField('Locale', $locale); @@ -79,7 +80,7 @@ public function testIsLocale($locale, $input, $expected) /** * @return array[] */ - public function isLocaleProvider() + public static function isLocaleProvider() { return [ ['en_NZ', 'en_NZ', true], diff --git a/tests/php/Task/InitialPageLocalisationTaskTest.php b/tests/php/Task/InitialPageLocalisationTaskTest.php index 664528e5..627ede38 100644 --- a/tests/php/Task/InitialPageLocalisationTaskTest.php +++ b/tests/php/Task/InitialPageLocalisationTaskTest.php @@ -10,6 +10,7 @@ use TractorCow\Fluent\Model\Locale; use TractorCow\Fluent\State\FluentState; use TractorCow\Fluent\Task\InitialPageLocalisationTask; +use PHPUnit\Framework\Attributes\DataProvider; class InitialPageLocalisationTaskTest extends SapphireTest { @@ -30,8 +31,8 @@ protected function setUp(): void * @param int $limit * @param array $localised * @param array $published - * @dataProvider publishStateProvider */ + #[DataProvider('publishStateProvider')] public function testInitialPageLocalisation(bool $publish, int $limit, array $localised, array $published): void { // Check base records @@ -105,7 +106,7 @@ public function testInitialPageLocalisation(bool $publish, int $limit, array $lo $this->assertEquals($published, $pages); } - public function publishStateProvider(): array + public static function publishStateProvider(): array { return [ [