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

api-platform / core / 11182119487

04 Oct 2024 02:50PM UTC coverage: 7.837% (+0.4%) from 7.441%
11182119487

push

github

soyuka
Merge 4.0

0 of 266 new or added lines in 25 files covered. (0.0%)

9900 existing lines in 360 files now uncovered.

12939 of 165109 relevant lines covered (7.84%)

27.02 hits per line

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

0.0
/src/Metadata/Tests/Resource/Factory/LinkResourceMetadataCollectionFactoryTest.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\Metadata\Tests\Resource\Factory;
15

16
use ApiPlatform\Metadata\ApiProperty;
17
use ApiPlatform\Metadata\ApiResource;
18
use ApiPlatform\Metadata\GraphQl\Query;
19
use ApiPlatform\Metadata\Link;
20
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
21
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
22
use ApiPlatform\Metadata\Property\PropertyNameCollection;
23
use ApiPlatform\Metadata\Resource\Factory\LinkFactory;
24
use ApiPlatform\Metadata\Resource\Factory\LinkResourceMetadataCollectionFactory;
25
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
26
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
27
use ApiPlatform\Metadata\ResourceClassResolverInterface;
28
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\AttributeResource;
29
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\Dummy;
30
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\RelatedDummy;
31
use Doctrine\Common\Collections\Collection;
32
use PHPUnit\Framework\TestCase;
33
use Prophecy\Argument;
34
use Prophecy\PhpUnit\ProphecyTrait;
35
use Symfony\Component\PropertyInfo\Type;
36

37
class LinkResourceMetadataCollectionFactoryTest extends TestCase
38
{
39
    use ProphecyTrait;
40

41
    public function testCreate(): void
42
    {
43
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
44
        $propertyNameCollectionFactoryProphecy->create(Argument::cetera())->willReturn(new PropertyNameCollection([
×
45
            'id',
×
46
            'foo',
×
47
            'foo2',
×
48
            'bar',
×
49
        ]));
×
50
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
51
        $propertyMetadataFactoryProphecy->create(AttributeResource::class, 'id')->willReturn(new ApiProperty());
×
52
        $propertyMetadataFactoryProphecy->create(AttributeResource::class, 'foo')->willReturn((new ApiProperty())->withBuiltinTypes([
×
53
            new Type(Type::BUILTIN_TYPE_OBJECT, false, Collection::class, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)),
×
54
        ]));
×
55
        $propertyMetadataFactoryProphecy->create(AttributeResource::class, 'foo2')->willReturn((new ApiProperty())->withBuiltinTypes([
×
56
            new Type(Type::BUILTIN_TYPE_OBJECT, false, Collection::class, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)),
×
57
        ]));
×
58
        $propertyMetadataFactoryProphecy->create(AttributeResource::class, 'bar')->willReturn((new ApiProperty())->withBuiltinTypes([
×
59
            new Type(Type::BUILTIN_TYPE_OBJECT, false, Collection::class, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, RelatedDummy::class)),
×
60
        ]));
×
61
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
62
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
63
        $resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true);
×
64
        $linkFactory = new LinkFactory($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $resourceClassResolverProphecy->reveal());
×
65
        $resourceCollectionMetadataFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class);
×
66
        $resourceCollectionMetadataFactoryProphecy->create(AttributeResource::class)->willReturn(
×
67
            new ResourceMetadataCollection(AttributeResource::class, [
×
68
                new ApiResource(
×
69
                    shortName: 'AttributeResource',
×
70
                    class: AttributeResource::class,
×
71
                    graphQlOperations: [
×
72
                        'item_query' => new Query(shortName: 'AttributeResource', class: AttributeResource::class),
×
73
                    ]
×
74
                ),
×
75
            ]),
×
76
        );
×
77

NEW
78
        $linkResourceMetadataCollectionFactory = new LinkResourceMetadataCollectionFactory($linkFactory, $resourceCollectionMetadataFactoryProphecy->reveal(), true);
×
79

80
        $this->assertEquals(
×
81
            new ResourceMetadataCollection(AttributeResource::class, [
×
82
                new ApiResource(
×
83
                    shortName: 'AttributeResource',
×
84
                    class: AttributeResource::class,
×
85
                    graphQlOperations: [
×
86
                        'item_query' => (new Query(shortName: 'AttributeResource', class: AttributeResource::class))->withLinks([
×
87
                            (new Link())->withFromProperty('foo')->withFromClass(AttributeResource::class)->withToClass(Dummy::class)->withIdentifiers(['id']),
×
88
                            (new Link())->withFromProperty('foo2')->withFromClass(AttributeResource::class)->withToClass(Dummy::class)->withIdentifiers(['id']),
×
89
                            (new Link())->withFromProperty('bar')->withFromClass(AttributeResource::class)->withToClass(RelatedDummy::class)->withIdentifiers(['id']),
×
90
                        ]),
×
91
                    ]
×
92
                ),
×
93
            ]),
×
94
            $linkResourceMetadataCollectionFactory->create(AttributeResource::class)
×
95
        );
×
96
    }
97

98
    public function testCreateWithLinkAttribute(): void
99
    {
100
        $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
101
        $propertyNameCollectionFactoryProphecy->create(Argument::cetera())->willReturn(new PropertyNameCollection([
×
102
            'identifier',
×
103
            'dummy',
×
104
        ]));
×
105
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
106
        $propertyMetadataFactoryProphecy->create(AttributeResource::class, 'identifier')->willReturn((new ApiProperty())->withIdentifier(true));
×
107
        $propertyMetadataFactoryProphecy->create(AttributeResource::class, 'dummy')->willReturn((new ApiProperty())->withBuiltinTypes([
×
108
            new Type(Type::BUILTIN_TYPE_OBJECT, false, Collection::class, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)),
×
109
        ]));
×
110
        $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
×
111
        $resourceClassResolverProphecy->isResourceClass(Dummy::class)->willReturn(true);
×
112
        $linkFactory = new LinkFactory($propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), $resourceClassResolverProphecy->reveal());
×
113
        $resourceCollectionMetadataFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class);
×
114
        $resourceCollectionMetadataFactoryProphecy->create(AttributeResource::class)->willReturn(
×
115
            new ResourceMetadataCollection(AttributeResource::class, [
×
116
                new ApiResource(
×
117
                    shortName: 'AttributeResource',
×
118
                    class: AttributeResource::class,
×
119
                    graphQlOperations: [
×
120
                        'item_query' => new Query(shortName: 'AttributeResource', class: AttributeResource::class),
×
121
                    ]
×
122
                ),
×
123
            ]),
×
124
        );
×
125

NEW
126
        $linkResourceMetadataCollectionFactory = new LinkResourceMetadataCollectionFactory($linkFactory, $resourceCollectionMetadataFactoryProphecy->reveal(), true);
×
127

128
        $this->assertEquals(
×
129
            new ResourceMetadataCollection(AttributeResource::class, [
×
130
                new ApiResource(
×
131
                    shortName: 'AttributeResource',
×
132
                    class: AttributeResource::class,
×
133
                    graphQlOperations: [
×
134
                        'item_query' => (new Query(shortName: 'AttributeResource', class: AttributeResource::class))->withLinks([
×
135
                            (new Link())->withParameterName('dummyId')->withFromProperty('dummy')->withFromClass(AttributeResource::class)->withToClass(Dummy::class)->withIdentifiers(['identifier']),
×
136
                        ]),
×
137
                    ]
×
138
                ),
×
139
            ]),
×
140
            $linkResourceMetadataCollectionFactory->create(AttributeResource::class)
×
141
        );
×
142
    }
143
}
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