You are here

protected function EntityMutationTest::mockMutationFactory in GraphQL 8.3

Overrides MockGraphQLPluginTrait::mockMutationFactory

File

modules/graphql_core/tests/src/Kernel/EntityMutation/EntityMutationTest.php, line 44

Class

EntityMutationTest
Test abstract entity mutation classes.

Namespace

Drupal\Tests\graphql_core\Kernel\EntityMutation

Code

protected function mockMutationFactory($definition, $result = NULL, $builder = NULL) {
  $mutation = $this
    ->getMockBuilder([
    'createNode' => CreateEntityBase::class,
    'updateNode' => UpdateEntityBase::class,
    'deleteNode' => DeleteEntityBase::class,
  ][$definition['id']])
    ->setConstructorArgs([
    [],
    $definition['id'],
    $definition,
    $this->container
      ->get('entity_type.manager'),
    $this->container
      ->get('renderer'),
  ])
    ->setMethods([
    'extractEntityInput',
  ])
    ->getMock();
  if (isset($result)) {
    $mutation
      ->expects(static::any())
      ->method('extractEntityInput')
      ->with(static::anything(), static::anything(), static::anything(), static::anything())
      ->will($this
      ->toBoundPromise($result, $mutation));
  }
  if (is_callable($builder)) {
    $builder($mutation);
  }
  return $mutation;
}