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 10, 2024
1 parent 8bb4b9e commit 251ba11
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 25 deletions.
4 changes: 2 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,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) {
Expand Down
7 changes: 4 additions & 3 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 @@ -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(
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 @@ -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()
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
9 changes: 5 additions & 4 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
7 changes: 4 additions & 3 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
15 changes: 8 additions & 7 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 Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion 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 Down
3 changes: 2 additions & 1 deletion 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 Down
3 changes: 2 additions & 1 deletion tests/php/Model/LocaleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion tests/php/Task/InitialPageLocalisationTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down

0 comments on commit 251ba11

Please sign in to comment.