You are here

protected function MockGraphQLPluginTrait::mockFieldFactory in GraphQL 8.3

File

tests/src/Traits/MockGraphQLPluginTrait.php, line 343

Class

MockGraphQLPluginTrait
Trait for mocking GraphQL type system plugins.

Namespace

Drupal\Tests\graphql\Traits

Code

protected function mockFieldFactory($definition, $result = NULL, $builder = NULL) {
  $field = $this
    ->getMockBuilder(FieldPluginBase::class)
    ->setConstructorArgs([
    [],
    $definition['id'],
    $definition,
  ])
    ->setMethods([
    'resolveValues',
  ])
    ->getMock();
  if (isset($result)) {
    $field
      ->expects(static::any())
      ->method('resolveValues')
      ->with(static::anything(), static::anything(), static::anything(), static::anything())
      ->will($this
      ->toBoundPromise($result, $field));
  }
  if (is_callable($builder)) {
    $builder($field);
  }
  return $field;
}