Skip to content

Commit

Permalink
API phpunit9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 17, 2021
1 parent 33a437c commit 50d4474
Show file tree
Hide file tree
Showing 26 changed files with 70 additions and 82 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"dnadesign/silverstripe-elemental": "<4.6"
},
"require-dev": {
"sminnee/phpunit": "^5.7",
"sminnee/phpunit-mock-objects": "^3.4.5",
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
Expand Down
17 changes: 7 additions & 10 deletions tests/Auth/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class HandlerTest extends SapphireTest
/**
* {@inheritDoc}
*/
public function setUp()
protected function setUp(): void
{
parent::setUp();
Handler::config()->remove('authenticators');
Expand Down Expand Up @@ -65,12 +65,11 @@ public function testGetAuthenticator()

/**
* Test that an exception is thrown if an authenticator is configured that doesn't implement the interface
*
* @expectedException \SilverStripe\ORM\ValidationException
* @expectedExceptionMessage stdClass must implement SilverStripe\GraphQL\Auth\AuthenticatorInterface!
*/
public function testExceptionThrownWhenAuthenticatorDoesNotImplementAuthenticatorInterface()
{
$this->expectException(\SilverStripe\ORM\ValidationException::class);
$this->expectExceptionMessage('stdClass must implement SilverStripe\GraphQL\Auth\AuthenticatorInterface!');
Handler::config()->update('authenticators', [
['class' => 'stdClass']
]);
Expand Down Expand Up @@ -131,12 +130,11 @@ public function prioritisedAuthenticatorProvider()

/**
* Ensure that an failed authentication attempt throws an exception
*
* @expectedException \SilverStripe\ORM\ValidationException
* @expectedExceptionMessage Never!
*/
public function testFailedAuthenticationThrowsException()
{
$this->expectException(\SilverStripe\ORM\ValidationException::class);
$this->expectExceptionMessage('Never!');
Handler::config()->update('authenticators', [
['class' => BrutalAuthenticatorFake::class]
]);
Expand All @@ -148,12 +146,11 @@ 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.
*
* @expectedException \SilverStripe\ORM\ValidationException
* @expectedExceptionMessage Authentication failed.
*/
public function testFailedAuthenticationWithFalsyReturnValueThrowsDefaultException()
{
$this->expectException(\SilverStripe\ORM\ValidationException::class);
$this->expectExceptionMessage('Authentication failed');
Handler::config()->update('authenticators', [
['class' => FalsyAuthenticatorFake::class]
]);
Expand Down
4 changes: 2 additions & 2 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ConnectionTest extends SapphireTest
*/
private $manager;

public function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -158,7 +158,7 @@ public function testResolveListSortWithCustomMapping()

public function testSortByInvalidColumnThrowsException()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);

$list = DataObjectFake::get();

Expand Down
18 changes: 8 additions & 10 deletions tests/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ControllerTest extends SapphireTest
{
protected $usesDatabase = true;

public function setUp()
protected function setUp(): void
{
parent::setUp();

Expand All @@ -43,7 +43,7 @@ public function setUp()
TestAssetStore::activate('GraphQLController');
}

public function tearDown()
protected function tearDown(): void
{
TestAssetStore::reset();
parent::tearDown();
Expand Down Expand Up @@ -170,11 +170,9 @@ public function authenticatorProvider()
];
}

/**
* @expectedException \SilverStripe\Control\HTTPResponse_Exception
*/
public function testAddCorsHeadersOriginDisallowed()
{
$this->expectException(\SilverStripe\Control\HTTPResponse_Exception::class);
Config::modify()->set(Controller::class, 'cors', [
'Enabled' => true,
'Allow-Origin' => null,
Expand Down Expand Up @@ -280,7 +278,7 @@ public function testAddCorsHeadersRefererPortAllowed()
*/
public function testAddCorsHeadersRefererPortDisallowed()
{
$this->expectException(HTTPResponse_Exception::class);
$this->expectException(\HTTPResponse_Exception::class);

Config::modify()->set(Controller::class, 'cors', [
'Enabled' => true,
Expand Down Expand Up @@ -322,7 +320,7 @@ public function testAddCorsHeadersOriginAllowedWildcard()

public function testAddCorsHeadersOriginMissing()
{
$this->expectException(HTTPResponse_Exception::class);
$this->expectException(\HTTPResponse_Exception::class);

Controller::config()->set('cors', [
'Enabled' => true,
Expand All @@ -344,7 +342,7 @@ public function testAddCorsHeadersOriginMissing()
*/
public function testAddCorsHeadersResponseCORSDisabled()
{
$this->expectException(HTTPResponse_Exception::class);
$this->expectException(\HTTPResponse_Exception::class);

Config::modify()->set(Controller::class, 'cors', [
'Enabled' => false
Expand Down Expand Up @@ -386,7 +384,7 @@ public function testCorsOverride()
$this->assertEquals('200', $response->getStatusCode());
$this->assertNull($response->getHeader('Access-Control-Allow-Origin'));

$this->expectException(HTTPResponse_Exception::class);
$this->expectException(\HTTPResponse_Exception::class);
$controller->setCorsConfig(['Enabled' => true]);
$controller->addCorsHeaders($request, $response);
}
Expand Down Expand Up @@ -562,7 +560,7 @@ protected function assertQueryError(Controller $controller, HTTPRequest $request
$data = json_decode($controller->handleRequest($request)->getBody(), true);
$this->assertArrayHasKey('errors', $data);
$this->assertCount(1, $data['errors']);
$this->assertRegExp($regExp, $data['errors'][0]['message']);
$this->assertMatchesRegularExpression($regExp, $data['errors'][0]['message']);
}

protected function assertQuerySuccess(Controller $controller, HTTPRequest $request, $operation)
Expand Down
8 changes: 4 additions & 4 deletions tests/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class ManagerTest extends SapphireTest
{

protected function setUp()
protected function setUp(): void
{
parent::setUp();
/** @var IdentityStore $store */
Expand Down Expand Up @@ -135,17 +135,17 @@ public function testSchemaKey()
$manager->setSchemaKey('test');
$this->assertEquals('test', $manager->getSchemaKey());

$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/must be a string/');
$manager->setSchemaKey(['test']);
$this->assertEquals('test', $manager->getSchemaKey());

$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/cannnot be empty/');
$manager->setSchemaKey('');
$this->assertEquals('test', $manager->getSchemaKey());

$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/alphanumeric/');
$manager->setSchemaKey('completely % invalid #key');
$this->assertEquals('test', $manager->getSchemaKey());
Expand Down
2 changes: 1 addition & 1 deletion tests/Middleware/MiddlewareProcessTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class MiddlewareProcessTestBase extends SapphireTest
*/
protected $defaultCallback;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->defaultCallback = function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/PersistedQuery/HTTPProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testURLValidation()
{
/* @var HTTPProvider $provider */
$provider = Injector::inst()->create(HTTPProvider::class);
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$provider->setSchemaMapping(['default' => 'not a url']);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/PersistedQuery/JSONStringProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function testJSONValidation()
{
/* @var PersistedQueryMappingProvider $provider */
$provider = new JSONStringProvider();
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$provider->setSchemaMapping(['default' => 'not a JSON string']);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/QueryFilter/ReadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ReadTest extends SapphireTest
DataObjectFake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
// Make sure we're only testing the native features
Expand Down
2 changes: 1 addition & 1 deletion tests/Scaffolding/Scaffolders/ArgumentScaffolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testNonInternalType()

public function testNonInternalTypeNoManager()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$scaffolder = new ArgumentScaffolder('Test', 'MyType');
$scaffolder->toArray();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Scaffolding/Scaffolders/CRUD/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CreateTest extends SapphireTest
RestrictedDataObjectFake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
StaticSchema::inst()->setTypeNames([]);
Expand All @@ -35,7 +35,7 @@ protected function setUp()
}
}

protected function tearDown()
protected function tearDown(): void
{
StaticSchema::inst()->setTypeNames([]);
parent::tearDown();
Expand Down
2 changes: 1 addition & 1 deletion tests/Scaffolding/Scaffolders/CRUD/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DeleteTest extends SapphireTest
RestrictedDataObjectFake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
// Make sure we're only testing the native features
Expand Down
2 changes: 1 addition & 1 deletion tests/Scaffolding/Scaffolders/CRUD/ReadOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ReadOneTest extends SapphireTest
RestrictedDataObjectFake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
// Make sure we're only testing the native features
Expand Down
2 changes: 1 addition & 1 deletion tests/Scaffolding/Scaffolders/CRUD/ReadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ReadTest extends SapphireTest
RestrictedDataObjectFake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
// Make sure we're only testing the native features
Expand Down
2 changes: 1 addition & 1 deletion tests/Scaffolding/Scaffolders/CRUD/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class UpdateTest extends SapphireTest
RestrictedDataObjectFake::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
// Make sure we're only testing the native features
Expand Down
16 changes: 8 additions & 8 deletions tests/Scaffolding/Scaffolders/DataObjectScaffolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class DataObjectScaffolderTest extends SapphireTest
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();
foreach (Read::get_extensions() as $class) {
Expand All @@ -42,7 +42,7 @@ public function testDataObjectScaffolderConstructor()
$this->assertEquals(DataObjectFake::class, $scaffolder->getDataObjectClass());
$this->assertInstanceOf(DataObjectFake::class, $scaffolder->getDataObjectInstance());

$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/Non-existent classname/i');
new DataObjectScaffolder('fail');
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public function testDataObjectScaffolderOperations()
$scaffolder->removeOperation(SchemaScaffolder::DELETE);
$this->assertEquals(1, $scaffolder->getOperations()->count());

$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/Invalid operation/');
$scaffolder = $this->getFakeScaffolder();
$scaffolder->operation('fail');
Expand Down Expand Up @@ -174,7 +174,7 @@ public function testDataObjectScaffolderNestedQueries()
$scaffolder->addToManager($managerMock);

// Can't add a nested query for a regular field
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/returns a DataList or ArrayList/');
$scaffolder = $this->getFakeScaffolder();
$scaffolder->nestedQuery('MyField');
Expand Down Expand Up @@ -295,7 +295,7 @@ public function testDataObjectScaffolderApplyConfigInvalidFieldsExceptException(
$scaffolder = $this->getFakeScaffolder();

// Invalid fieldsExcept
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/"excludeFields" must be an enumerated list/');
$scaffolder->applyConfig([
'fields' => ['MyField'],
Expand Down Expand Up @@ -374,7 +374,7 @@ public function testDataObjectScaffolderScaffold()

public function testDataObjectScaffolderScaffoldFieldException()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/Invalid field/');
$scaffolder = $this->getFakeScaffolder()
->addFields(['not a field'])
Expand All @@ -384,7 +384,7 @@ public function testDataObjectScaffolderScaffoldFieldException()

public function testDataObjectScaffolderScaffoldNestedQueryException()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/returns a list/');
$scaffolder = $this->getFakeScaffolder()
->addFields(['Files'])
Expand Down Expand Up @@ -480,7 +480,7 @@ public function testCloneTo()

$target = $scaffolder->cloneTo($target);

$this->assertContains('Title', $target->getFields()->column('Name'));
$this->assertStringContainsString('Title', $target->getFields()->column('Name'));
$this->assertNotContains('RedirectionType', $target->getFields()->column('Name'));
$this->assertCount(2, $target->getOperations());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Scaffolding/Scaffolders/InheritanceScaffolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class InheritanceScaffolderTest extends SapphireTest
{
public function testThrowsOnNonExistentClass()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/not exist/');

$scaffolder = new InheritanceScaffolder('fail');
}

public function testThrowsOnNonDataObjectClass()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/subclass of/');

$scaffolder = new InheritanceScaffolder(Controller::class);
Expand Down
2 changes: 1 addition & 1 deletion tests/Scaffolding/Scaffolders/ListQueryScaffolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function testListQueryScaffolderApplyConfig()

public function testListQueryScaffolderApplyConfigThrowsOnBadSortableFields()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/sortableFields must be an array/');
$scaffolder = new ListQueryScaffolder('testQuery', 'testType');
$scaffolder->applyConfig([
Expand Down
Loading

0 comments on commit 50d4474

Please sign in to comment.