Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEP Use PHPUnit 11 #473

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/php/Caching/ProxyCacheAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected function getMockCacheInterface()
{
$methods = ['get', 'set', 'has', 'delete', 'getMultiple', 'setMultiple', 'clear', 'deleteMultiple'];
$mock = $this->getMockBuilder(CacheInterface::class)
->setMethods($methods)
->onlyMethods($methods)
->getMock();

return $mock;
Expand Down
4 changes: 2 additions & 2 deletions tests/php/GridFieldArchiveActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ public function testGetArchiveAction()
protected function createGridField()
{
$mock = $this->getMockBuilder(Controller::class)
->setMethods(['Link'])
->onlyMethods(['Link'])
->getMock();
$mock->method('Link')->will($this->returnValue('Test'));
$mock->method('Link')->willReturn('Test');
$form = new Form(
$mock,
'TestForm',
Expand Down
19 changes: 8 additions & 11 deletions tests/php/ReadingModeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
use InvalidArgumentException;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Versioned\ReadingMode;
use PHPUnit\Framework\Attributes\DataProvider;

class ReadingModeTest extends SapphireTest
{
/**
* @dataProvider provideReadingModes()
*
* @param string $readingMode
* @param array $dataQuery
* @param array $queryStringArray
* @param string $queryString
*/
#[DataProvider('provideReadingModes')]
public function testToDataQueryParams($readingMode, $dataQuery, $queryStringArray, $queryString)
{
$this->assertEquals(
Expand All @@ -25,13 +25,12 @@ public function testToDataQueryParams($readingMode, $dataQuery, $queryStringArra
);
}
/**
* @dataProvider provideReadingModes()
*
* @param string $readingMode
* @param array $dataQuery
* @param array $queryStringArray
* @param string $queryString
*/
#[DataProvider('provideReadingModes')]
public function testFromDataQueryParameters($readingMode, $dataQuery, $queryStringArray, $queryString)
{
$this->assertEquals(
Expand All @@ -42,13 +41,12 @@ public function testFromDataQueryParameters($readingMode, $dataQuery, $queryStri
}

/**
* @dataProvider provideReadingModes()
*
* @param string $readingMode
* @param array $dataQuery
* @param array $queryStringArray
* @param string $queryString
*/
#[DataProvider('provideReadingModes')]
public function testToQueryString($readingMode, $dataQuery, $queryStringArray, $queryString)
{
$this->assertEquals(
Expand All @@ -59,13 +57,12 @@ public function testToQueryString($readingMode, $dataQuery, $queryStringArray, $
}

/**
* @dataProvider provideReadingModes()
*
* @param string $readingMode
* @param array $dataQuery
* @param array $queryStringArray
* @param string $queryString
*/
#[DataProvider('provideReadingModes')]
public function testFromQueryString($readingMode, $dataQuery, $queryStringArray, $queryString)
{
$this->assertEquals(
Expand All @@ -88,7 +85,7 @@ public function testFromQueryString($readingMode, $dataQuery, $queryStringArray,
* - query string (string)
* @return array
*/
public function provideReadingModes()
public static function provideReadingModes()
{
return [
// Draft
Expand Down Expand Up @@ -147,16 +144,16 @@ public function provideReadingModes()
}

/**
* @dataProvider provideTestInvalidStage
* @param string $stage
*/
#[DataProvider('provideTestInvalidStage')]
public function testInvalidStage($stage)
{
$this->expectException(\InvalidArgumentException::class);
ReadingMode::validateStage($stage);
}

public function provideTestInvalidStage()
public static function provideTestInvalidStage()
{
return [
[''],
Expand Down
7 changes: 3 additions & 4 deletions tests/php/RecursiveStagesServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SilverStripe\Versioned\Tests\RecursiveStagesServiceTest\GroupObject;
use SilverStripe\Versioned\Tests\RecursiveStagesServiceTest\PrimaryObject;
use SilverStripe\Versioned\Versioned;
use PHPUnit\Framework\Attributes\DataProvider;

class RecursiveStagesServiceTest extends SapphireTest
{
Expand Down Expand Up @@ -51,9 +52,7 @@ public function testStageDiffersRecursiveWithInvalidObject(): void
});
}

/**
* @dataProvider objectsProvider
*/
#[DataProvider('objectsProvider')]
public function testStageDiffersRecursive(string $class, string $identifier, bool $delete, bool $expected): void
{
Versioned::withVersionedMode(function () use ($class, $identifier, $delete, $expected): void {
Expand Down Expand Up @@ -81,7 +80,7 @@ public function testStageDiffersRecursive(string $class, string $identifier, boo
});
}

public function objectsProvider(): array
public static function objectsProvider(): array
{
return [
'primary object (versioned, update)' => [
Expand Down
11 changes: 4 additions & 7 deletions tests/php/VersionedNumberCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SilverStripe\Versioned\Versioned;
use SilverStripe\Versioned\Tests\VersionedTest\TestObject;
use ReflectionMethod;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @internal Only test the right values are returned, not that the cache is actually used.
Expand Down Expand Up @@ -68,7 +69,7 @@ protected function setUp(): void
TestObject::singleton()->flushCache();
}

public function cacheDataProvider()
public static function cacheDataProvider()
{
return [
[Versioned::DRAFT, 'publishedID', false, 'draftVersion'],
Expand All @@ -81,9 +82,7 @@ public function cacheDataProvider()
}


/**
* @dataProvider cacheDataProvider
*/
#[DataProvider('cacheDataProvider')]
public function testVersionNumberCache($stage, $ID, $cache, $expected)
{
$actual = Versioned::get_versionnumber_by_stage(TestObject::class, $stage, VersionedNumberCacheTest::${$ID}, $cache);
Expand All @@ -96,9 +95,7 @@ public function testVersionNumberCache($stage, $ID, $cache, $expected)
}
}

/**
* @dataProvider cacheDataProvider
*/
#[DataProvider('cacheDataProvider')]
public function testPrepopulatedVersionNumberCache($stage, $ID, $cache, $expected)
{
$owner = TestObject::singleton();
Expand Down
Loading