Skip to content

Commit

Permalink
Add CollectionResolverFactory test to cover a field not being prese…
Browse files Browse the repository at this point in the history
…nt in the source.
  • Loading branch information
DavidBennettUK committed Mar 30, 2021
1 parent 4558ab9 commit 4bc3c48
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 0 additions & 1 deletion tests/Fixtures/TestBundle/Document/SecuredDummy.php
Expand Up @@ -217,7 +217,6 @@ public function setRelatedDummy(RelatedDummy $relatedDummy)
$this->relatedDummy = $relatedDummy;
}


public function addRelatedSecuredDummy(RelatedSecuredDummy $relatedSecuredDummy)
{
$this->relatedSecuredDummies->add($relatedSecuredDummy);
Expand Down
30 changes: 30 additions & 0 deletions tests/GraphQl/Resolver/Factory/CollectionResolverFactoryTest.php
Expand Up @@ -110,6 +110,36 @@ public function testResolve(): void
$this->assertSame($serializeStageData, ($this->collectionResolverFactory)($resourceClass, $rootClass, $operationName)($source, $args, null, $info));
}

public function testResolveFieldNotInSource(): void
{
$resourceClass = 'stdClass';
$rootClass = 'rootClass';
$operationName = 'collection_query';
$source = ['source'];
$args = ['args'];
$info = $this->prophesize(ResolveInfo::class)->reveal();
$info->fieldName = 'testField';
$resolverContext = ['source' => $source, 'args' => $args, 'info' => $info, 'is_collection' => true, 'is_mutation' => false, 'is_subscription' => false];

$readStageCollection = [new \stdClass()];
$this->readStageProphecy->__invoke($resourceClass, $rootClass, $operationName, $resolverContext)->shouldNotBeCalled();

$this->securityStageProphecy->__invoke($resourceClass, $operationName, $resolverContext + [
'extra_variables' => [
'object' => $readStageCollection,
],
])->shouldNotBeCalled();
$this->securityPostDenormalizeStageProphecy->__invoke($resourceClass, $operationName, $resolverContext + [
'extra_variables' => [
'object' => $readStageCollection,
'previous_object' => $readStageCollection,
],
])->shouldNotBeCalled();

// Null should be returned if the field isn't in the source - as its lack of presence will be due to @ApiProperty security stripping unauthorized fields
$this->assertNull(($this->collectionResolverFactory)($resourceClass, $rootClass, $operationName)($source, $args, null, $info));
}

public function testResolveNullSource(): void
{
$resourceClass = 'stdClass';
Expand Down

0 comments on commit 4bc3c48

Please sign in to comment.