You are here

protected function DataProducerExecutionTrait::executeDataProducer in GraphQL 8.4

Parameters

string $id:

array $contexts:

Return value

mixed

43 calls to DataProducerExecutionTrait::executeDataProducer()
EntityMultipleTest::testResolveEntityLoadMultiple in tests/src/Kernel/DataProducer/EntityMultipleTest.php
@covers \Drupal\graphql\Plugin\GraphQL\DataProducer\Entity\EntityLoadMultiple::resolve
EntityReferenceTest::testResolveEntityReference in tests/src/Kernel/DataProducer/EntityReferenceTest.php
@covers \Drupal\graphql\Plugin\GraphQL\DataProducer\Field\EntityReference::resolve
EntityTest::testResolveAccess in tests/src/Kernel/DataProducer/EntityTest.php
@covers \Drupal\graphql\Plugin\GraphQL\DataProducer\Entity\EntityAccess::resolve
EntityTest::testResolveBundle in tests/src/Kernel/DataProducer/EntityTest.php
@covers \Drupal\graphql\Plugin\GraphQL\DataProducer\Entity\EntityBundle::resolve
EntityTest::testResolveChanged in tests/src/Kernel/DataProducer/EntityTest.php
@covers \Drupal\graphql\Plugin\GraphQL\DataProducer\Entity\EntityChanged::resolve

... See full list

File

tests/src/Traits/DataProducerExecutionTrait.php, line 21

Class

DataProducerExecutionTrait
Helper trait for testing data producers.

Namespace

Drupal\Tests\graphql\Traits

Code

protected function executeDataProducer($id, array $contexts = []) {

  /** @var \Drupal\graphql\Plugin\DataProducerPluginManager $manager */
  $manager = $this->container
    ->get('plugin.manager.graphql.data_producer');

  /** @var \Drupal\graphql\Plugin\DataProducerPluginInterface $plugin */
  $plugin = $manager
    ->createInstance($id);
  foreach ($contexts as $key => $value) {
    $plugin
      ->setContextValue($key, $value);
  }
  $context = $this
    ->prophesize(FieldContext::class);
  $context
    ->addCacheableDependency(Argument::any())
    ->willReturn($context
    ->reveal());
  $context
    ->addCacheContexts(Argument::any())
    ->willReturn($context
    ->reveal());
  $context
    ->addCacheTags(Argument::any())
    ->willReturn($context
    ->reveal());
  $context
    ->mergeCacheMaxAge(Argument::any())
    ->willReturn($context
    ->reveal());
  $context
    ->getContextValue(Argument::any(), Argument::any())
    ->willReturn(NULL);
  $context
    ->setContextValue(Argument::any(), Argument::any())
    ->willReturn(FALSE);
  $context
    ->hasContextValue(Argument::any())
    ->willReturn(FALSE);
  $result = $plugin
    ->resolveField($context
    ->reveal());
  if (!$result instanceof SyncPromise) {
    return $result;
  }
  $adapter = new SyncPromiseAdapter();
  return $adapter
    ->wait($adapter
    ->convertThenable($result));
}