Skip to content

Commit 9e49bb5

Browse files
Merge pull request #601 from creative-commoners/pulls/6/phpunit11
DEP Use PHPUnit 11
2 parents b7af2d2 + f8222fb commit 9e49bb5

18 files changed

+85
-90
lines changed

tests/Auth/HandlerTest.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use SilverStripe\GraphQL\Tests\Fake\BrutalAuthenticatorFake;
99
use SilverStripe\GraphQL\Tests\Fake\FalsyAuthenticatorFake;
1010
use SilverStripe\GraphQL\Tests\Fake\PushoverAuthenticatorFake;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1112

1213
/**
1314
* @package silverstripe-graphql
@@ -65,7 +66,6 @@ public function testGetAuthenticator()
6566

6667
/**
6768
* Test that an exception is thrown if an authenticator is configured that doesn't implement the interface
68-
*
6969
*/
7070
public function testExceptionThrownWhenAuthenticatorDoesNotImplementAuthenticatorInterface()
7171
{
@@ -80,8 +80,8 @@ public function testExceptionThrownWhenAuthenticatorDoesNotImplementAuthenticato
8080
*
8181
* @param array $authenticators
8282
* @param string $expected
83-
* @dataProvider prioritisedAuthenticatorProvider
8483
*/
84+
#[DataProvider('prioritisedAuthenticatorProvider')]
8585
public function testAuthenticatorsCanBePrioritised($authenticators, $expected)
8686
{
8787
Handler::config()->set('authenticators', $authenticators);
@@ -92,7 +92,7 @@ public function testAuthenticatorsCanBePrioritised($authenticators, $expected)
9292
/**
9393
* @return array
9494
*/
95-
public function prioritisedAuthenticatorProvider()
95+
public static function prioritisedAuthenticatorProvider()
9696
{
9797
return [
9898
[
@@ -128,7 +128,6 @@ public function prioritisedAuthenticatorProvider()
128128

129129
/**
130130
* Ensure that an failed authentication attempt throws an exception
131-
*
132131
*/
133132
public function testFailedAuthenticationThrowsException()
134133
{
@@ -142,7 +141,6 @@ public function testFailedAuthenticationThrowsException()
142141
* Ensure that when a falsy value is returned from an authenticator (when it should throw
143142
* an exception on failure) that a sensible default message is used in a ValidationException
144143
* instead.
145-
*
146144
*/
147145
public function testFailedAuthenticationWithFalsyReturnValueThrowsDefaultException()
148146
{

tests/ControllerTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
use SilverStripe\Dev\SapphireTest;
1010
use SilverStripe\GraphQL\Controller;
1111
use SilverStripe\ORM\DB;
12+
use PHPUnit\Framework\Attributes\DataProvider;
1213

1314
class ControllerTest extends SapphireTest
1415
{
1516
protected $usesDatabase = false;
1617

17-
public function providePrepareBacktrace()
18+
public static function providePrepareBacktrace()
1819
{
1920
$querySource = <<<'GRAPHQL'
2021
query ReadFiles($filter: FakeInputType!) {
@@ -152,9 +153,7 @@ public function providePrepareBacktrace()
152153
];
153154
}
154155

155-
/**
156-
* @dataProvider providePrepareBacktrace
157-
*/
156+
#[DataProvider('providePrepareBacktrace')]
158157
public function testPrepareBacktrace(array $trace, array $expected)
159158
{
160159
$controller = new Controller(__FUNCTION__);

tests/Middleware/CSRFMiddlewareTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use SilverStripe\GraphQL\Middleware\CSRFMiddleware;
77
use SilverStripe\Security\SecurityToken;
88

9-
class CSRFMiddlewareTest extends BaseMiddlewareProcessTest
9+
class CSRFMiddlewareTest extends MiddlewareProcessTestBase
1010
{
1111
private bool $securityTokenWasEnabled = false;
1212

tests/Middleware/BaseMiddlewareProcessTest.php renamed to tests/Middleware/MiddlewareProcessTestBase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use SilverStripe\GraphQL\Middleware\QueryMiddleware;
1010
use SilverStripe\GraphQL\Schema\Schema as SchemaSchema;
1111

12-
abstract class BaseMiddlewareProcessTest extends SapphireTest
12+
abstract class MiddlewareProcessTestBase extends SapphireTest
1313
{
1414
/**
1515
* @var callable

tests/Modules/AssetAdmin/ReadFileUsageQueryCreatorTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use SilverStripe\Dev\SapphireTest;
1111
use Silverstripe\Assets\Dev\TestAssetStore;
1212
use SilverStripe\GraphQL\Schema\Schema;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1314

1415
/**
1516
* Most of the search functionality is covered in {@link FileFilterInputTypeCreatorTest}
@@ -38,7 +39,7 @@ protected function tearDown(): void
3839
parent::tearDown();
3940
}
4041

41-
public function fileUsageDataProvider()
42+
public static function fileUsageDataProvider()
4243
{
4344
return [
4445
[File::class, 'rootfile', 2, 'rootfile file is used twice'],
@@ -50,12 +51,12 @@ public function fileUsageDataProvider()
5051
}
5152

5253
/**
53-
* @dataProvider fileUsageDataProvider
5454
* @param string $class
5555
* @param string $fixture
5656
* @param int|false $expectedCount
5757
* @param $message
5858
*/
59+
#[DataProvider('fileUsageDataProvider')]
5960
public function testUsageCount(string $class, string $fixture, $expectedCount, $message)
6061
{
6162
$id = $this->idFromFixture($class, $fixture);

tests/Modules/CMS/LinkablePluginTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use SilverStripe\GraphQL\Schema\Field\ModelQuery;
1111
use SilverStripe\GraphQL\Schema\Schema;
1212
use SilverStripe\GraphQL\Schema\SchemaConfig;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1314

1415
class LinkablePluginTest extends SapphireTest
1516
{
@@ -24,8 +25,8 @@ protected function setUp(): void
2425

2526
/**
2627
* @param bool $list
27-
* @dataProvider provideApply
2828
*/
29+
#[DataProvider('provideApply')]
2930
public function testApply(bool $list)
3031
{
3132
$query = new ModelQuery(
@@ -102,7 +103,7 @@ public function testResolver()
102103
}
103104

104105

105-
public function provideApply()
106+
public static function provideApply()
106107
{
107108
return [
108109
[true],

tests/PersistedQuery/HTTPProviderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testSchemaMapping()
3333
public function testHTTPRequests()
3434
{
3535
$mock = $this->getMockBuilder(HTTPClient::class)
36-
->setMethods(['getURL'])
36+
->onlyMethods(['getURL'])
3737
->getMock();
3838
$mock->expects($this->once())
3939
->method('getURL')

tests/Schema/AbstractTypeRegistryTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use ReflectionObject;
1212
use stdClass;
1313
use SilverStripe\Control\Session;
14+
use PHPUnit\Framework\Attributes\DataProvider;
1415

1516
class AbstractTypeRegistryTest extends SapphireTest
1617
{
@@ -50,9 +51,7 @@ public function testRebuildOnMissingPath()
5051
);
5152
}
5253

53-
/**
54-
* @dataProvider provideRebuildOnMissing
55-
*/
54+
#[DataProvider('provideRebuildOnMissing')]
5655
public function testRebuildOnMissing(
5756
bool $controller,
5857
bool $autobuild,
@@ -93,7 +92,7 @@ public function testRebuildOnMissing(
9392
$this->assertSame($expected, $canRebuildOnMissingMethod->invoke($registry));
9493
}
9594

96-
public function provideRebuildOnMissing(): array
95+
public static function provideRebuildOnMissing(): array
9796
{
9897
// controller = current controller is a GraphQLController
9998
// autobuild = if autobuild is enabled

tests/Schema/DataObject/Plugin/DBFieldArgs/DBDateArgsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testApply()
3232
public function testResolve()
3333
{
3434
$fake = $this->getMockBuilder(DBDate::class)
35-
->setMethods(['Nice'])
35+
->onlyMethods(['Nice'])
3636
->getMock();
3737
$fake->expects($this->once())
3838
->method('Nice');

tests/Schema/DataObject/Plugin/DBFieldArgs/DBDatetimeArgsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testApply()
3333
public function testResolve()
3434
{
3535
$fake = $this->getMockBuilder(DBDatetime::class)
36-
->setMethods(['Time'])
36+
->onlyMethods(['Time'])
3737
->getMock();
3838
$fake->expects($this->once())
3939
->method('Time');

tests/Schema/DataObject/Plugin/DBFieldArgs/DBFieldArgsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class DBFieldArgsTest extends SapphireTest
1313
public function testBaseFormatResolver()
1414
{
1515
$fake = $this->getMockBuilder(DBText::class)
16-
->setMethods(['FirstSentence'])
16+
->onlyMethods(['FirstSentence'])
1717
->getMock();
1818
$fake->expects($this->once())
1919
->method('FirstSentence');

tests/Schema/DataObject/Plugin/DBFieldArgs/DBHTMLTextArgsTest.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,20 @@ public function testApply()
3333
public function testResolve()
3434
{
3535
$fake = $this->getMockBuilder(DBHTMLText::class)
36-
->setMethods(['setProcessShortcodes'])
36+
->onlyMethods(['setProcessShortcodes'])
3737
->getMock();
38-
$fake->expects($this->exactly(4))
38+
$matcher = $this->exactly(4);
39+
$fake->expects($matcher)
3940
->method('setProcessShortcodes')
40-
->withConsecutive([true], [false], [false], [true]);
41+
->willReturnCallback(function (bool $process) use ($fake, $matcher) {
42+
match ($matcher->numberOfInvocations()) {
43+
1 => $this->assertSame(true, $process),
44+
2 => $this->assertSame(false, $process),
45+
3 => $this->assertSame(false, $process),
46+
4 => $this->assertSame(true, $process),
47+
};
48+
return $fake;
49+
});
4150

4251
$trueConfig = new SchemaConfig();
4352
$trueConfig->set('modelConfig.DataObject', ['parseShortcodes' => true]);

tests/Schema/DataObject/Plugin/DBFieldArgs/DBTextArgsTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testApply()
3232
public function testResolve()
3333
{
3434
$fake = $this->getMockBuilder(DBText::class)
35-
->setMethods(['FirstParagraph'])
35+
->onlyMethods(['FirstParagraph'])
3636
->getMock();
3737
$fake->expects($this->once())
3838
->method('FirstParagraph');
@@ -44,7 +44,7 @@ public function testResolve()
4444
DBTextArgs::resolve($fake, ['format' => 'FirstParagraph', 'limit' => 5], []);
4545

4646
$fake = $this->getMockBuilder(DBText::class)
47-
->setMethods(['LimitSentences'])
47+
->onlyMethods(['LimitSentences'])
4848
->getMock();
4949
$fake->expects($this->once())
5050
->method('LimitSentences')

tests/Schema/DataObject/Plugin/DBFieldArgs/DBTimeArgsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testApply()
3333
public function testResolve()
3434
{
3535
$fake = $this->getMockBuilder(DBTime::class)
36-
->setMethods(['Nice'])
36+
->onlyMethods(['Nice'])
3737
->getMock();
3838
$fake->expects($this->once())
3939
->method('Nice');

tests/Schema/DataObject/Plugin/FiltersTest.php

+17-15
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@
1515
use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\NotEqualFilter;
1616
use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\StartsWithFilter;
1717
use SilverStripe\ORM\ArrayList;
18+
use PHPUnit\Framework\Attributes\DataProvider;
1819

1920
class FiltersTest extends SapphireTest
2021
{
21-
private array $values = [
22+
/**
23+
* @internal
24+
*/
25+
private static array $values = [
2226
'string' => 'test',
2327
'array' => ['a', 'b'],
2428
'number' => 42,
2529
'null' => null
2630
];
2731

28-
/**
29-
* @dataProvider filterArgumentsProvider
30-
*/
32+
#[DataProvider('filterArgumentsProvider')]
3133
public function testFilterArguments(FieldFilterInterface $filter, string $identifier, array $params): void
3234
{
3335
$this->assertEquals($identifier, $filter->getIdentifier());
@@ -40,58 +42,58 @@ public function testFilterArguments(FieldFilterInterface $filter, string $identi
4042
}
4143
}
4244

43-
public function filterArgumentsProvider(): array
45+
public static function filterArgumentsProvider(): array
4446
{
4547
return [
4648
[
4749
new ContainsFilter(),
4850
'contains',
49-
array_slice($this->values, 0, 2, true)
51+
array_slice(FiltersTest::$values, 0, 2, true)
5052
],
5153
[
5254
new EndsWithFilter(),
5355
'endswith',
54-
array_slice($this->values, 0, 2, true)
56+
array_slice(FiltersTest::$values, 0, 2, true)
5557
],
5658
[
5759
new EqualToFilter(),
5860
'eq',
59-
$this->values
61+
FiltersTest::$values
6062
],
6163
[
6264
new GreaterThanFilter(),
6365
'gt',
64-
$this->values
66+
FiltersTest::$values
6567
],
6668
[
6769
new GreaterThanOrEqualFilter(),
6870
'gte',
69-
$this->values
71+
FiltersTest::$values
7072
],
7173
[
7274
new InFilter(),
7375
'in',
74-
$this->values['array']
76+
FiltersTest::$values['array']
7577
],
7678
[
7779
new LessThanFilter(),
7880
'lt',
79-
$this->values
81+
FiltersTest::$values
8082
],
8183
[
8284
new LessThanOrEqualFilter(),
8385
'lte',
84-
$this->values
86+
FiltersTest::$values
8587
],
8688
[
8789
new NotEqualFilter(),
8890
'ne',
89-
$this->values
91+
FiltersTest::$values
9092
],
9193
[
9294
new StartsWithFilter(),
9395
'startswith',
94-
array_slice($this->values, 0, 2, true)
96+
array_slice(FiltersTest::$values, 0, 2, true)
9597
]
9698
];
9799
}

tests/Schema/DataObject/Plugin/InheritanceTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use SilverStripe\GraphQL\Tests\Schema\DataObject\FakeInterfaceBuilder;
3636
use SilverStripe\GraphQL\Tests\Schema\DataObject\TestSchema;
3737
use SilverStripe\ORM\DataObject;
38+
use PHPUnit\Framework\Attributes\DataProvider;
3839

3940
class InheritanceTest extends SapphireTest
4041
{
@@ -62,8 +63,8 @@ class InheritanceTest extends SapphireTest
6263
* @param false $unions
6364
* @throws \ReflectionException
6465
* @throws SchemaBuilderException
65-
* @dataProvider provideUnionOption
6666
*/
67+
#[DataProvider('provideUnionOption')]
6768
public function testInheritance($unions = false)
6869
{
6970
$schema = new TestSchema();
@@ -168,7 +169,7 @@ private function assertCalls(array $expected, array $actual)
168169
$this->assertEmpty(array_diff($compare ?? [], $expected), 'Actual calls exceed the expected calls');
169170
}
170171

171-
public function provideUnionOption()
172+
public static function provideUnionOption()
172173
{
173174
return [
174175
[true],

0 commit comments

Comments
 (0)