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

api-platform / core / 15629538569

13 Jun 2025 07:58AM UTC coverage: 21.874% (-0.002%) from 21.876%
15629538569

Pull #7207

github

web-flow
Merge 3fb5fafc9 into cff61eab8
Pull Request #7207: feat(metadata) customize resource & operations

16 of 92 new or added lines in 9 files covered. (17.39%)

37 existing lines in 2 files now uncovered.

11410 of 52163 relevant lines covered (21.87%)

20.98 hits per line

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

0.0
/src/Metadata/Tests/Resource/Factory/CustomResourceMetadataCollectionFactoryTest.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\ApiResource;
17
use ApiPlatform\Metadata\Extractor\ClosureExtractorInterface;
18
use ApiPlatform\Metadata\Resource\Factory\CustomResourceMetadataCollectionFactory;
19
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
20
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
21
use PHPUnit\Framework\TestCase;
22
use stdClass;
23

24
final class CustomResourceMetadataCollectionFactoryTest extends TestCase
25
{
26
    public function testCustomizeApiResource(): void
27
    {
NEW
28
        $decorated = $this->createMock(ResourceMetadataCollectionFactoryInterface::class);
×
NEW
29
        $resourceClosureExtractor = $this->createMock(ClosureExtractorInterface::class);
×
NEW
30
        $resourceClass = stdClass::class;
×
NEW
31
        $resourceMetadataCollection = new ResourceMetadataCollection($resourceClass);
×
NEW
32
        $resourceMetadataCollection[] = new ApiResource();
×
NEW
33
        $customResourceMetadataCollectionFactory = new CustomResourceMetadataCollectionFactory($resourceClosureExtractor, $decorated);
×
34

NEW
35
        $decorated->expects($this->once())->method('create')->with($resourceClass)->willReturn(
×
NEW
36
            $resourceMetadataCollection,
×
NEW
37
        );
×
NEW
38
        $resourceClosureExtractor->expects($this->once())->method('getClosures')->willReturn([
×
NEW
39
            static function (ApiResource $resource): ApiResource {
×
NEW
40
                return $resource->withShortName('dummy');
×
NEW
41
            }
×
NEW
42
        ]);
×
43

NEW
44
        $resourceMetadataCollection = $customResourceMetadataCollectionFactory->create($resourceClass);
×
45

NEW
46
        $ApiResource = $resourceMetadataCollection->getIterator()->current();
×
NEW
47
        $this->assertInstanceOf(ApiResource::class, $ApiResource);
×
NEW
48
        $this->assertSame('dummy', $ApiResource->getShortName());
×
49
    }
50
}
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