Skip to content

Commit

Permalink
Merge pull request #1822 from creative-commoners/pulls/3/phpunit11
Browse files Browse the repository at this point in the history
DEP Use PHPUnit 11
  • Loading branch information
GuySartorelli authored Sep 18, 2024
2 parents f37e693 + f677f86 commit f7f4df8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"silverstripe/vendor-plugin": "^2"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^11.3",
"silverstripe/frameworktest": "^2",
"squizlabs/php_codesniffer": "^3.7",
"silverstripe/standards": "^1",
Expand Down
24 changes: 10 additions & 14 deletions tests/php/LeftAndMainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use stdClass;
use ReflectionObject;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\DataProvider;
use SilverStripe\Core\Manifest\VersionProvider;

class LeftAndMainTest extends FunctionalTest
{
Expand Down Expand Up @@ -218,21 +220,19 @@ public function testDisableHelpLinks()
$this->assertCount(0, $helpLinks);
}

/**
* @dataProvider provideTestCMSVersionNumber
*/
#[DataProvider('provideTestCMSVersionNumber')]
public function testCMSVersionNumber($frameworkVersion, $expected)
{
$versionProvider = $this
->getMockBuilder(VersionProvider::class)
->setMethods(['getModules', 'getModuleVersionFromComposer'])
->onlyMethods(['getModules', 'getModuleVersionFromComposer'])
->getMock();
$data = ['silverstripe/framework' => $frameworkVersion];
$versionProvider->method('getModules')->willReturn($data);
$versionProvider->method('getModuleVersionFromComposer')->willReturn($data);
$leftAndMain = $this
->getMockBuilder(LeftAndMain::class)
->setMethods(['getVersionProvider'])
->onlyMethods(['getVersionProvider'])
->getMock();
$leftAndMain->method('getVersionProvider')->willReturn($versionProvider);
$this->assertSame($expected, $leftAndMain->CMSVersionNumber());
Expand All @@ -241,7 +241,7 @@ public function testCMSVersionNumber($frameworkVersion, $expected)
/**
* @return array
*/
public function provideTestCMSVersionNumber()
public static function provideTestCMSVersionNumber()
{
return [
['4.9.1', '4.9'],
Expand Down Expand Up @@ -290,7 +290,7 @@ public function testValidationResult()
$this->assertSame($result->messages[0]->message, MyTree::INVALID_CONTENT_MESSAGE);
}

public function provideJsonSuccess(): array
public static function provideJsonSuccess(): array
{
return [
[
Expand Down Expand Up @@ -338,9 +338,7 @@ public function provideJsonSuccess(): array
];
}

/**
* @dataProvider provideJsonSuccess
*/
#[DataProvider('provideJsonSuccess')]
public function testJsonSuccess(
int $statusCode,
?array $data,
Expand All @@ -360,7 +358,7 @@ public function testJsonSuccess(
$this->assertSame($expectedBody, $response->getBody());
}

public function provideJsonError(): array
public static function provideJsonError(): array
{
return [
[
Expand Down Expand Up @@ -406,9 +404,7 @@ public function provideJsonError(): array
];
}

/**
* @dataProvider provideJsonError
*/
#[DataProvider('provideJsonError')]
public function testJsonError(
int $statusCode,
?string $errorMessage,
Expand Down
10 changes: 5 additions & 5 deletions tests/php/ModelAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ public function testGetManagedModels()
public function testGetManagedModelTabs()
{
$mock = $this->getMockBuilder(ModelAdminTest\MultiModelAdmin::class)
->setMethods(['getManagedModels'])
->onlyMethods(['getManagedModels'])
->getMock();

// `getManagedModelTabs` relies on `getManagedModels` whose output format has changed within the 4.x line.
// We need to mock `getManagedModels` so it returns both the legacy and updated format.
$mock->expects($this->atLeastOnce())
->method('getManagedModels')
->will($this->returnValue([
->willReturn([
'Player' => [
'dataClass' => Player::class,
'title' => 'Ice Hockey Players'
Expand All @@ -239,7 +239,7 @@ public function testGetManagedModelTabs()
'dataClass' => Player::class,
'title' => 'Cricket Players',
],
]));
]);


$tabs = $mock->getManagedModelTabs()->toNestedArray();
Expand Down Expand Up @@ -386,11 +386,11 @@ public function testGetModelTabForModelClassNoSpec()
// We need to mock `getManagedModels` to test the legacy format.
$mock->expects($this->atLeastOnce())
->method('getManagedModels')
->will($this->returnValue([
->willReturn([
Player::class => [
'title' => 'Rugby Players'
],
]));
]);

$reflectionMethod = new ReflectionMethod($mock, 'getModelTabForModelClass');
$reflectionMethod->setAccessible(true);
Expand Down

0 comments on commit f7f4df8

Please sign in to comment.