public function TestFrameworkTest::testInterfaceMock in GraphQL 8.3
Same name and namespace in other branches
- 8.4 tests/src/Kernel/Framework/TestFrameworkTest.php \Drupal\Tests\graphql\Kernel\Framework\TestFrameworkTest::testInterfaceMock()
Test interface mocking.
File
- tests/
src/ Kernel/ Framework/ TestFrameworkTest.php, line 156
Class
- TestFrameworkTest
- Test the test framework.
Namespace
Drupal\Tests\graphql\Kernel\FrameworkCode
public function testInterfaceMock() {
$this
->mockInterface('token', [
'name' => 'Token',
]);
$this
->mockType('number', [
'name' => 'Number',
'interfaces' => [
'Token',
],
], function ($value) {
return is_int($value['value']);
});
$this
->mockType('word', [
'name' => 'Word',
'interfaces' => [
'Token',
],
], function ($value) {
return is_string($value['value']);
});
$this
->mockField('int_value', [
'name' => 'value',
'type' => 'Int',
'parents' => [
'Number',
],
], function ($value) {
(yield $value['value']);
});
$this
->mockField('string_value', [
'name' => 'value',
'type' => 'String',
'parents' => [
'Word',
],
], function ($value) {
(yield $value['value']);
});
$this
->mockField('root', [
'name' => 'root',
'type' => '[Token]',
], function () {
(yield [
'value' => 42,
]);
(yield [
'value' => 'GraphQL',
]);
});
$this
->assertResults('{ root { ... on Number { number:value } ... on Word { word:value } } }', [], [
'root' => [
0 => [
'number' => 42,
],
1 => [
'word' => 'GraphQL',
],
],
], $this
->defaultCacheMetaData());
}