Skip to content

Commit

Permalink
DEP Use PHPUnit 11
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Sep 9, 2024
1 parent 72e2fa6 commit 49e7fb0
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 37 deletions.
5 changes: 3 additions & 2 deletions tests/php/Extension/FluentExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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) {
Expand All @@ -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 [
/**
Expand Down
13 changes: 7 additions & 6 deletions tests/php/Extension/FluentSiteTreeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -116,7 +117,7 @@ public function testGetLocales()
* - page id
* - expected link
*/
public function provideURLTests()
public static function provideURLTests()
{
return [
// Non-domain tests
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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/'],
Expand All @@ -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()
Expand Down Expand Up @@ -521,7 +522,7 @@ public function testPageVisibilityWithFallback($cmsMode, $frontendMode, bool $is
});
}

public function localeFallbackProvider(): array
public static function localeFallbackProvider(): array
{
return [
'Frontend / no inheritance' => [
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Extension/FluentVersionedExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function testLocalisedStageCacheIsUsedForIsLocalisedInLocale()

/** @var FluentVersionedExtension $extension */
$extension = $this->getMockBuilder(FluentVersionedExtension::class)
->setMethods(['findRecordInLocale'])
->onlyMethods(['findRecordInLocale'])
->getMock();
$extension->setOwner($page);

Expand All @@ -142,7 +142,7 @@ public function testIdsInLocaleCacheIsUsedForIsLocalisedInLocale()

/** @var FluentVersionedExtension $extension */
$extension = $this->getMockBuilder(FluentVersionedExtension::class)
->setMethods(['findRecordInLocale'])
->onlyMethods(['findRecordInLocale'])
->getMock();
$extension->setOwner($page);

Expand Down
13 changes: 7 additions & 6 deletions tests/php/Extension/LocalisedCopyTest/DuplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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],
Expand All @@ -248,7 +249,7 @@ public function localesProvider(): array
];
}

public function copyStateProvider(): array
public static function copyStateProvider(): array
{
return [
[false],
Expand Down
11 changes: 6 additions & 5 deletions tests/php/Extension/LocalisedVersionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -217,7 +218,7 @@ public function testArchive(): void
});
}

public function latestVersionsProvider(): array
public static function latestVersionsProvider(): array
{
return [
[null, 6],
Expand All @@ -227,7 +228,7 @@ public function latestVersionsProvider(): array
];
}

public function listVersionsProvider(): array
public static function listVersionsProvider(): array
{
return [
[
Expand Down
17 changes: 9 additions & 8 deletions tests/php/Middleware/DetectLocaleMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -60,14 +61,14 @@ public function testGetPersistKey()
}

/**
* @dataProvider localePriorityProvider
* @param string $url
* @param array $routeParams
* @param array $queryParams
* @param bool $persisted
* @param string $header
* @param string $expected
*/
#[DataProvider('localePriorityProvider')]
public function testGetLocalePriority($url, $routeParams, $queryParams, $persisted, $header, $expected)
{
$request = new HTTPRequest('GET', $url, $queryParams);
Expand All @@ -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
Expand All @@ -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');
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -180,7 +181,7 @@ public function testLocaleIsPersistedFromSession()

$sessionData = [$key => $newLocale];
$sessionMock = $this->getMockBuilder(Session::class)
->setMethods(['set', 'isStarted'])
->onlyMethods(['set', 'isStarted'])
->setConstructorArgs([$sessionData])
->getMock();

Expand All @@ -206,7 +207,7 @@ public function testLocaleIsNotPersistedFromSessionWhenSessionIsNotStarted()

$sessionData = [$key => $newLocale];
$sessionMock = $this->getMockBuilder(Session::class)
->setMethods(['set', 'isStarted'])
->onlyMethods(['set', 'isStarted'])
->setConstructorArgs([$sessionData])
->getMock();

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions tests/php/Middleware/InitStateMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -24,7 +25,7 @@ public function testGetIsFrontend($url, $getVars, $expected)
/**
* @return array[]
*/
public function isFrontendProvider()
public static function isFrontendProvider()
{
return [
['admin', [], false],
Expand Down
5 changes: 3 additions & 2 deletions tests/php/Model/LocalDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 */
Expand All @@ -82,7 +83,7 @@ public function testSwitchLocales($locale, $expectedTime)
});
}

public function provideTestSwitchLocales()
public static function provideTestSwitchLocales()
{
return [
[
Expand Down
Loading

0 comments on commit 49e7fb0

Please sign in to comment.