Skip to content

Commit

Permalink
Merge pull request #601 from creative-commoners/pulls/6/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 b7af2d2 + f8222fb commit 9e49bb5
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 90 deletions.
8 changes: 3 additions & 5 deletions tests/Auth/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SilverStripe\GraphQL\Tests\Fake\BrutalAuthenticatorFake;
use SilverStripe\GraphQL\Tests\Fake\FalsyAuthenticatorFake;
use SilverStripe\GraphQL\Tests\Fake\PushoverAuthenticatorFake;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @package silverstripe-graphql
Expand Down Expand Up @@ -65,7 +66,6 @@ public function testGetAuthenticator()

/**
* Test that an exception is thrown if an authenticator is configured that doesn't implement the interface
*
*/
public function testExceptionThrownWhenAuthenticatorDoesNotImplementAuthenticatorInterface()
{
Expand All @@ -80,8 +80,8 @@ public function testExceptionThrownWhenAuthenticatorDoesNotImplementAuthenticato
*
* @param array $authenticators
* @param string $expected
* @dataProvider prioritisedAuthenticatorProvider
*/
#[DataProvider('prioritisedAuthenticatorProvider')]
public function testAuthenticatorsCanBePrioritised($authenticators, $expected)
{
Handler::config()->set('authenticators', $authenticators);
Expand All @@ -92,7 +92,7 @@ public function testAuthenticatorsCanBePrioritised($authenticators, $expected)
/**
* @return array
*/
public function prioritisedAuthenticatorProvider()
public static function prioritisedAuthenticatorProvider()
{
return [
[
Expand Down Expand Up @@ -128,7 +128,6 @@ public function prioritisedAuthenticatorProvider()

/**
* Ensure that an failed authentication attempt throws an exception
*
*/
public function testFailedAuthenticationThrowsException()
{
Expand All @@ -142,7 +141,6 @@ public function testFailedAuthenticationThrowsException()
* Ensure that when a falsy value is returned from an authenticator (when it should throw
* an exception on failure) that a sensible default message is used in a ValidationException
* instead.
*
*/
public function testFailedAuthenticationWithFalsyReturnValueThrowsDefaultException()
{
Expand Down
7 changes: 3 additions & 4 deletions tests/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\GraphQL\Controller;
use SilverStripe\ORM\DB;
use PHPUnit\Framework\Attributes\DataProvider;

class ControllerTest extends SapphireTest
{
protected $usesDatabase = false;

public function providePrepareBacktrace()
public static function providePrepareBacktrace()
{
$querySource = <<<'GRAPHQL'
query ReadFiles($filter: FakeInputType!) {
Expand Down Expand Up @@ -152,9 +153,7 @@ public function providePrepareBacktrace()
];
}

/**
* @dataProvider providePrepareBacktrace
*/
#[DataProvider('providePrepareBacktrace')]
public function testPrepareBacktrace(array $trace, array $expected)
{
$controller = new Controller(__FUNCTION__);
Expand Down
2 changes: 1 addition & 1 deletion tests/Middleware/CSRFMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use SilverStripe\GraphQL\Middleware\CSRFMiddleware;
use SilverStripe\Security\SecurityToken;

class CSRFMiddlewareTest extends BaseMiddlewareProcessTest
class CSRFMiddlewareTest extends MiddlewareProcessTestBase
{
private bool $securityTokenWasEnabled = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use SilverStripe\GraphQL\Middleware\QueryMiddleware;
use SilverStripe\GraphQL\Schema\Schema as SchemaSchema;

abstract class BaseMiddlewareProcessTest extends SapphireTest
abstract class MiddlewareProcessTestBase extends SapphireTest
{
/**
* @var callable
Expand Down
5 changes: 3 additions & 2 deletions tests/Modules/AssetAdmin/ReadFileUsageQueryCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SilverStripe\Dev\SapphireTest;
use Silverstripe\Assets\Dev\TestAssetStore;
use SilverStripe\GraphQL\Schema\Schema;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Most of the search functionality is covered in {@link FileFilterInputTypeCreatorTest}
Expand Down Expand Up @@ -38,7 +39,7 @@ protected function tearDown(): void
parent::tearDown();
}

public function fileUsageDataProvider()
public static function fileUsageDataProvider()
{
return [
[File::class, 'rootfile', 2, 'rootfile file is used twice'],
Expand All @@ -50,12 +51,12 @@ public function fileUsageDataProvider()
}

/**
* @dataProvider fileUsageDataProvider
* @param string $class
* @param string $fixture
* @param int|false $expectedCount
* @param $message
*/
#[DataProvider('fileUsageDataProvider')]
public function testUsageCount(string $class, string $fixture, $expectedCount, $message)
{
$id = $this->idFromFixture($class, $fixture);
Expand Down
5 changes: 3 additions & 2 deletions tests/Modules/CMS/LinkablePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SilverStripe\GraphQL\Schema\Field\ModelQuery;
use SilverStripe\GraphQL\Schema\Schema;
use SilverStripe\GraphQL\Schema\SchemaConfig;
use PHPUnit\Framework\Attributes\DataProvider;

class LinkablePluginTest extends SapphireTest
{
Expand All @@ -24,8 +25,8 @@ protected function setUp(): void

/**
* @param bool $list
* @dataProvider provideApply
*/
#[DataProvider('provideApply')]
public function testApply(bool $list)
{
$query = new ModelQuery(
Expand Down Expand Up @@ -102,7 +103,7 @@ public function testResolver()
}


public function provideApply()
public static function provideApply()
{
return [
[true],
Expand Down
2 changes: 1 addition & 1 deletion tests/PersistedQuery/HTTPProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testSchemaMapping()
public function testHTTPRequests()
{
$mock = $this->getMockBuilder(HTTPClient::class)
->setMethods(['getURL'])
->onlyMethods(['getURL'])
->getMock();
$mock->expects($this->once())
->method('getURL')
Expand Down
7 changes: 3 additions & 4 deletions tests/Schema/AbstractTypeRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use ReflectionObject;
use stdClass;
use SilverStripe\Control\Session;
use PHPUnit\Framework\Attributes\DataProvider;

class AbstractTypeRegistryTest extends SapphireTest
{
Expand Down Expand Up @@ -50,9 +51,7 @@ public function testRebuildOnMissingPath()
);
}

/**
* @dataProvider provideRebuildOnMissing
*/
#[DataProvider('provideRebuildOnMissing')]
public function testRebuildOnMissing(
bool $controller,
bool $autobuild,
Expand Down Expand Up @@ -93,7 +92,7 @@ public function testRebuildOnMissing(
$this->assertSame($expected, $canRebuildOnMissingMethod->invoke($registry));
}

public function provideRebuildOnMissing(): array
public static function provideRebuildOnMissing(): array
{
// controller = current controller is a GraphQLController
// autobuild = if autobuild is enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testApply()
public function testResolve()
{
$fake = $this->getMockBuilder(DBDate::class)
->setMethods(['Nice'])
->onlyMethods(['Nice'])
->getMock();
$fake->expects($this->once())
->method('Nice');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testApply()
public function testResolve()
{
$fake = $this->getMockBuilder(DBDatetime::class)
->setMethods(['Time'])
->onlyMethods(['Time'])
->getMock();
$fake->expects($this->once())
->method('Time');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DBFieldArgsTest extends SapphireTest
public function testBaseFormatResolver()
{
$fake = $this->getMockBuilder(DBText::class)
->setMethods(['FirstSentence'])
->onlyMethods(['FirstSentence'])
->getMock();
$fake->expects($this->once())
->method('FirstSentence');
Expand Down
15 changes: 12 additions & 3 deletions tests/Schema/DataObject/Plugin/DBFieldArgs/DBHTMLTextArgsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,20 @@ public function testApply()
public function testResolve()
{
$fake = $this->getMockBuilder(DBHTMLText::class)
->setMethods(['setProcessShortcodes'])
->onlyMethods(['setProcessShortcodes'])
->getMock();
$fake->expects($this->exactly(4))
$matcher = $this->exactly(4);
$fake->expects($matcher)
->method('setProcessShortcodes')
->withConsecutive([true], [false], [false], [true]);
->willReturnCallback(function (bool $process) use ($fake, $matcher) {
match ($matcher->numberOfInvocations()) {
1 => $this->assertSame(true, $process),
2 => $this->assertSame(false, $process),
3 => $this->assertSame(false, $process),
4 => $this->assertSame(true, $process),
};
return $fake;
});

$trueConfig = new SchemaConfig();
$trueConfig->set('modelConfig.DataObject', ['parseShortcodes' => true]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Schema/DataObject/Plugin/DBFieldArgs/DBTextArgsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testApply()
public function testResolve()
{
$fake = $this->getMockBuilder(DBText::class)
->setMethods(['FirstParagraph'])
->onlyMethods(['FirstParagraph'])
->getMock();
$fake->expects($this->once())
->method('FirstParagraph');
Expand All @@ -44,7 +44,7 @@ public function testResolve()
DBTextArgs::resolve($fake, ['format' => 'FirstParagraph', 'limit' => 5], []);

$fake = $this->getMockBuilder(DBText::class)
->setMethods(['LimitSentences'])
->onlyMethods(['LimitSentences'])
->getMock();
$fake->expects($this->once())
->method('LimitSentences')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testApply()
public function testResolve()
{
$fake = $this->getMockBuilder(DBTime::class)
->setMethods(['Nice'])
->onlyMethods(['Nice'])
->getMock();
$fake->expects($this->once())
->method('Nice');
Expand Down
32 changes: 17 additions & 15 deletions tests/Schema/DataObject/Plugin/FiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@
use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\NotEqualFilter;
use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters\StartsWithFilter;
use SilverStripe\ORM\ArrayList;
use PHPUnit\Framework\Attributes\DataProvider;

class FiltersTest extends SapphireTest
{
private array $values = [
/**
* @internal
*/
private static array $values = [
'string' => 'test',
'array' => ['a', 'b'],
'number' => 42,
'null' => null
];

/**
* @dataProvider filterArgumentsProvider
*/
#[DataProvider('filterArgumentsProvider')]
public function testFilterArguments(FieldFilterInterface $filter, string $identifier, array $params): void
{
$this->assertEquals($identifier, $filter->getIdentifier());
Expand All @@ -40,58 +42,58 @@ public function testFilterArguments(FieldFilterInterface $filter, string $identi
}
}

public function filterArgumentsProvider(): array
public static function filterArgumentsProvider(): array
{
return [
[
new ContainsFilter(),
'contains',
array_slice($this->values, 0, 2, true)
array_slice(FiltersTest::$values, 0, 2, true)
],
[
new EndsWithFilter(),
'endswith',
array_slice($this->values, 0, 2, true)
array_slice(FiltersTest::$values, 0, 2, true)
],
[
new EqualToFilter(),
'eq',
$this->values
FiltersTest::$values
],
[
new GreaterThanFilter(),
'gt',
$this->values
FiltersTest::$values
],
[
new GreaterThanOrEqualFilter(),
'gte',
$this->values
FiltersTest::$values
],
[
new InFilter(),
'in',
$this->values['array']
FiltersTest::$values['array']
],
[
new LessThanFilter(),
'lt',
$this->values
FiltersTest::$values
],
[
new LessThanOrEqualFilter(),
'lte',
$this->values
FiltersTest::$values
],
[
new NotEqualFilter(),
'ne',
$this->values
FiltersTest::$values
],
[
new StartsWithFilter(),
'startswith',
array_slice($this->values, 0, 2, true)
array_slice(FiltersTest::$values, 0, 2, true)
]
];
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Schema/DataObject/Plugin/InheritanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use SilverStripe\GraphQL\Tests\Schema\DataObject\FakeInterfaceBuilder;
use SilverStripe\GraphQL\Tests\Schema\DataObject\TestSchema;
use SilverStripe\ORM\DataObject;
use PHPUnit\Framework\Attributes\DataProvider;

class InheritanceTest extends SapphireTest
{
Expand Down Expand Up @@ -62,8 +63,8 @@ class InheritanceTest extends SapphireTest
* @param false $unions
* @throws \ReflectionException
* @throws SchemaBuilderException
* @dataProvider provideUnionOption
*/
#[DataProvider('provideUnionOption')]
public function testInheritance($unions = false)
{
$schema = new TestSchema();
Expand Down Expand Up @@ -168,7 +169,7 @@ private function assertCalls(array $expected, array $actual)
$this->assertEmpty(array_diff($compare ?? [], $expected), 'Actual calls exceed the expected calls');
}

public function provideUnionOption()
public static function provideUnionOption()
{
return [
[true],
Expand Down
Loading

0 comments on commit 9e49bb5

Please sign in to comment.