From 251ba119885fbc9d760282c4e129ea5a55d22887 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 10 Sep 2024 16:50:53 +1200 Subject: [PATCH] DEP Use PHPUnit 11 --- tests/php/Extension/FluentExtensionTest.php | 4 ++-- .../php/Extension/FluentSiteTreeExtensionTest.php | 7 ++++--- .../Extension/FluentVersionedExtensionTest.php | 4 ++-- .../LocalisedCopyTest/DuplicationTest.php | 9 +++++---- tests/php/Extension/LocalisedVersionsTest.php | 7 ++++--- .../php/Middleware/DetectLocaleMiddlewareTest.php | 15 ++++++++------- tests/php/Middleware/InitStateMiddlewareTest.php | 3 ++- tests/php/Model/LocalDateTimeTest.php | 3 ++- tests/php/Model/LocaleTest.php | 3 ++- .../php/Task/InitialPageLocalisationTaskTest.php | 3 ++- 10 files changed, 33 insertions(+), 25 deletions(-) diff --git a/tests/php/Extension/FluentExtensionTest.php b/tests/php/Extension/FluentExtensionTest.php index 5498f3eb..c131df52 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,11 @@ 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) { diff --git a/tests/php/Extension/FluentSiteTreeExtensionTest.php b/tests/php/Extension/FluentSiteTreeExtensionTest.php index 9962e92a..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)) { @@ -158,13 +159,13 @@ public static 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( @@ -488,8 +489,8 @@ public static 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() 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 7482ae81..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 { diff --git a/tests/php/Extension/LocalisedVersionsTest.php b/tests/php/Extension/LocalisedVersionsTest.php index f13549d1..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 { diff --git a/tests/php/Middleware/DetectLocaleMiddlewareTest.php b/tests/php/Middleware/DetectLocaleMiddlewareTest.php index 98896841..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); @@ -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 cd8d02cf..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); diff --git a/tests/php/Model/LocalDateTimeTest.php b/tests/php/Model/LocalDateTimeTest.php index 0bbb4ee4..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 */ diff --git a/tests/php/Model/LocaleTest.php b/tests/php/Model/LocaleTest.php index 12fcaf41..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); diff --git a/tests/php/Task/InitialPageLocalisationTaskTest.php b/tests/php/Task/InitialPageLocalisationTaskTest.php index fcc19a04..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