• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 14246153067

03 Apr 2025 02:56PM UTC coverage: 7.286% (-0.002%) from 7.288%
14246153067

push

github

web-flow
Merge commit from fork

12 of 160 new or added lines in 7 files covered. (7.5%)

2343 existing lines in 152 files now uncovered.

12450 of 170870 relevant lines covered (7.29%)

12.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/GraphQl/Tests/Resolver/Factory/ResolverFactoryTest.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\GraphQl\Tests\Resolver\Factory;
15

16
use ApiPlatform\GraphQl\Resolver\Factory\ResolverFactory;
17
use ApiPlatform\Metadata\ApiProperty;
18
use ApiPlatform\Metadata\GraphQl\Mutation;
19
use ApiPlatform\Metadata\GraphQl\Operation;
20
use ApiPlatform\Metadata\GraphQl\Query;
21
use ApiPlatform\Metadata\Operation\Factory\OperationMetadataFactoryInterface;
22
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
23
use ApiPlatform\State\ProcessorInterface;
24
use ApiPlatform\State\ProviderInterface;
25
use GraphQL\Type\Definition\ResolveInfo;
26
use PHPUnit\Framework\TestCase;
27

28
class ResolverFactoryTest extends TestCase
29
{
30
    #[\PHPUnit\Framework\Attributes\DataProvider('graphQlQueries')]
31
    public function testGraphQlResolver(?string $resourceClass = null, ?string $rootClass = null, ?Operation $operation = null, ?Operation $providedOperation = null, ?Operation $processedOperation = null): void
32
    {
33
        $returnValue = new \stdClass();
×
34
        $body = new \stdClass();
×
35
        $context = $this->logicalAnd(
×
36
            $this->arrayHasKey('source'), $this->arrayHasKey('args'), $this->arrayHasKey('graphql_context'), $this->arrayHasKey('info'), $this->arrayHasKey('root_class')
×
37
        );
×
38
        $provider = $this->createMock(ProviderInterface::class);
×
39
        $provider->expects($this->once())->method('provide')->with($providedOperation ?: $operation, [], $context)->willReturn($body);
×
40
        $processor = $this->createMock(ProcessorInterface::class);
×
41
        $processor->expects($this->once())->method('process')->with($body, $processedOperation ?: $operation, [], $context)->willReturn($returnValue);
×
42
        $propertyMetadataFactory = $this->createMock(PropertyMetadataFactoryInterface::class);
×
43
        $propertyMetadataFactory->expects($this->once())->method('create')->with($rootClass, 'test')->willReturn(new ApiProperty(schema: ['type' => 'array']));
×
44
        $resolveInfo = $this->createMock(ResolveInfo::class);
×
45
        $resolveInfo->fieldName = 'test';
×
46

NEW
47
        $resolverFactory = new ResolverFactory($provider, $processor, $this->createMock(OperationMetadataFactoryInterface::class));
×
48
        $this->assertEquals($resolverFactory->__invoke($resourceClass, $rootClass, $operation, $propertyMetadataFactory)(['test' => null], [], [], $resolveInfo), $returnValue);
×
49
    }
50

51
    public static function graphQlQueries(): array
52
    {
53
        return [
×
54
            ['Dummy', 'Dummy', new Query()],
×
55
            ['Dummy', 'Dummy', new Mutation(), (new Mutation())->withValidate(true), (new Mutation())->withValidate(true)->withWrite(true)],
×
56
        ];
×
57
    }
58

59
    public function testGraphQlResolverWithNode(): void
60
    {
NEW
61
        $returnValue = new \stdClass();
×
NEW
62
        $op = new Query(name: 'hi');
×
NEW
63
        $provider = $this->createMock(ProviderInterface::class);
×
NEW
64
        $provider->expects($this->once())->method('provide')->with($op)->willReturn($returnValue);
×
NEW
65
        $processor = $this->createMock(ProcessorInterface::class);
×
NEW
66
        $processor->expects($this->once())->method('process')->with($returnValue, $op)->willReturn($returnValue);
×
NEW
67
        $resolveInfo = $this->createMock(ResolveInfo::class);
×
NEW
68
        $resolveInfo->fieldName = 'test';
×
69

NEW
70
        $operationFactory = $this->createMock(OperationMetadataFactoryInterface::class);
×
NEW
71
        $operationFactory->method('create')->with('/foo')->willReturn($op);
×
NEW
72
        $resolverFactory = new ResolverFactory($provider, $processor, $operationFactory);
×
NEW
73
        $this->assertSame($returnValue, $resolverFactory->__invoke()([], ['id' => '/foo'], [], $resolveInfo));
×
74
    }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc