|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <[email protected]> |
| 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\Tests\GraphQl\Metadata\Factory; |
| 15 | + |
| 16 | +use ApiPlatform\GraphQl\Metadata\Factory\GraphQlNestedOperationResourceMetadataFactory; |
| 17 | +use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; |
| 18 | +use ApiPlatform\Metadata\Resource\ResourceMetadataCollection; |
| 19 | +use ApiPlatform\Tests\Fixtures\TestBundle\Entity\RelatedDummy; |
| 20 | +use PHPUnit\Framework\TestCase; |
| 21 | +use Prophecy\PhpUnit\ProphecyTrait; |
| 22 | + |
| 23 | +final class GraphQlNestedOperationResourceMetadataFactoryTest extends TestCase |
| 24 | +{ |
| 25 | + use ProphecyTrait; |
| 26 | + |
| 27 | + public function testCreate(): void |
| 28 | + { |
| 29 | + $decorated = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class); |
| 30 | + $decorated->create('someClass')->shouldBeCalled()->willReturn(new ResourceMetadataCollection('someClass')); |
| 31 | + |
| 32 | + $metadataFactory = new GraphQlNestedOperationResourceMetadataFactory(['status' => 500], $decorated->reveal()); |
| 33 | + $apiResource = $metadataFactory->create('someClass')[0]; |
| 34 | + $this->assertCount(5, $apiResource->getGraphQlOperations()); |
| 35 | + } |
| 36 | + |
| 37 | + public function testCreateWithResource(): void |
| 38 | + { |
| 39 | + $metadataFactory = new GraphQlNestedOperationResourceMetadataFactory(['status' => 500]); |
| 40 | + $apiResource = $metadataFactory->create(RelatedDummy::class)[0]; |
| 41 | + $this->assertNotEmpty($apiResource->getFilters()); |
| 42 | + $this->assertEquals('RelatedDummy', $apiResource->getShortName()); |
| 43 | + } |
| 44 | +} |
0 commit comments