forked from thecodingmachine/graphqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrefetchDataParameterTest.php
More file actions
46 lines (37 loc) · 1.45 KB
/
PrefetchDataParameterTest.php
File metadata and controls
46 lines (37 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace TheCodingMachine\GraphQLite\Parameters;
use GraphQL\Deferred;
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
use GraphQL\Executor\Promise\Promise;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use PHPUnit\Framework\TestCase;
use stdClass;
use TheCodingMachine\GraphQLite\Context\Context;
use TheCodingMachine\GraphQLite\Types\ArgumentResolver;
class PrefetchDataParameterTest extends TestCase
{
public function testResolveWithExistingResult(): void
{
$parameter = new PrefetchDataParameter('', function () {
$this->fail('Should not be called');
}, []);
$source = new stdClass();
$prefetchResult = new stdClass();
$context = new Context();
$args = [
'first' => 'qwe',
'second' => 'rty'
];
$buffer = $context->getPrefetchBuffer($parameter);
$buffer->storeResult($source, $prefetchResult);
$resolvedParameterPromise = $parameter->resolve($source, $args, $context, $this->createStub(ResolveInfo::class));
self::assertSame([$source], $buffer->getObjectsByArguments($args));
self::assertSame($prefetchResult, $this->deferredValue($resolvedParameterPromise));
}
private function deferredValue(Deferred $promise): mixed
{
$syncPromiseAdapter = new SyncPromiseAdapter();
return $syncPromiseAdapter->wait(new Promise($promise, $syncPromiseAdapter));
}
}