Skip to content

Commit

Permalink
MNT Compatibility with webonyx/graphql-php v14
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Apr 12, 2022
1 parent 3fe3c41 commit 9a11240
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tests/GraphQL/DuplicateElementMutationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use DNADesign\Elemental\GraphQL\DuplicateElementMutation;
use DNADesign\Elemental\Models\BaseElement;
use DNADesign\Elemental\Models\ElementalArea;
use GraphQL\Type\Definition\ResolveInfo;
use DNADesign\Elemental\Tests\GraphQL\FakeResolveInfo;
use InvalidArgumentException;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Security;
Expand Down Expand Up @@ -62,7 +62,7 @@ public function canCreate($member = null, $context = [])
$object = null;
$args = ['id' => $element->ID];
$context = ['currentUser' => Security::getCurrentUser()];
$resolveInfo = new ResolveInfo([]);
$resolveInfo = new FakeResolveInfo();

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessageRegExp("#insufficient permission to {$operation}#");
Expand Down
21 changes: 20 additions & 1 deletion tests/GraphQL/FakeResolveInfo.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
<?php


namespace DNADesign\Elemental\Tests\GraphQL;

use GraphQL\Type\Definition\FieldDefinition;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;

class FakeResolveInfo extends ResolveInfo
{
public function __construct()
{
// webonyx/graphql-php v0.12
if (!property_exists(__CLASS__, 'fieldDefinition')) {
return;
}
// webonyx/graphql-php v14
parent::__construct(
FieldDefinition::create(['name' => 'fake', 'type' => Type::string()]),
[],
new ObjectType(['name' => 'fake']),
[],
new Schema([]),
[],
'',
null,
[]
);
}
}
4 changes: 2 additions & 2 deletions tests/GraphQL/Legacy/AddElementToAreaMutationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use DNADesign\Elemental\GraphQL\AddElementToAreaMutation;
use DNADesign\Elemental\Models\ElementalArea;
use DNADesign\Elemental\Tests\GraphQL\FakeResolveInfo;
use DNADesign\Elemental\Tests\Src\TestElement;
use GraphQL\Type\Definition\ResolveInfo;
use InvalidArgumentException;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\GraphQL\Schema\Schema;
Expand Down Expand Up @@ -81,7 +81,7 @@ protected function runMutation($className, $elementalAreaID, $afterElementId = n
{
$mutation = new AddElementToAreaMutation();
$context = ['currentUser' => Security::getCurrentUser()];
$resolveInfo = new ResolveInfo([]);
$resolveInfo = new FakeResolveInfo();

$args = [
'className' => $className,
Expand Down
4 changes: 2 additions & 2 deletions tests/GraphQL/Legacy/SortBlockMutationCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace DNADesign\Elemental\Tests\Legacy\GraphQL;

use DNADesign\Elemental\GraphQL\SortBlockMutationCreator;
use DNADesign\Elemental\Tests\GraphQL\FakeResolveInfo;
use DNADesign\Elemental\Tests\Src\TestElement;
use GraphQL\Type\Definition\ResolveInfo;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\GraphQL\Schema\Schema;
use SilverStripe\Security\Security;
Expand Down Expand Up @@ -56,7 +56,7 @@ protected function runMutation($id, $afterBlockId)

$mutation = new SortBlockMutationCreator();
$context = ['currentUser' => $member];
$resolveInfo = new ResolveInfo([]);
$resolveInfo = new FakeResolveInfo();

$mutation->resolve(null, [
'id' => $id,
Expand Down

0 comments on commit 9a11240

Please sign in to comment.