You are here

protected function MockGraphQLPluginTrait::mockTypeFactory in GraphQL 8.3

File

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

Class

MockGraphQLPluginTrait
Trait for mocking GraphQL type system plugins.

Namespace

Drupal\Tests\graphql\Traits

Code

protected function mockTypeFactory($definition, $applies = TRUE, $builder = NULL) {
  $type = $this
    ->getMockBuilder(TypePluginBase::class)
    ->setConstructorArgs([
    [],
    $definition['id'],
    $definition,
  ])
    ->setMethods([
    'applies',
  ])
    ->getMock();
  $type
    ->expects(static::any())
    ->method('applies')
    ->with($this
    ->anything(), $this
    ->anything())
    ->will($this
    ->toBoundPromise($applies, $type));
  if (is_callable($builder)) {
    $builder($type);
  }
  return $type;
}