Skip to content

Commit 4b6828d

Browse files
committed
start working on tests
1 parent 7fbcfc2 commit 4b6828d

File tree

193 files changed

+602
-1563
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+602
-1563
lines changed

tests/Action/EntrypointActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
use ApiPlatform\Action\EntrypointAction;
1717
use ApiPlatform\Api\Entrypoint;
18-
use ApiPlatform\Tests\ProphecyTrait;
1918
use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
2019
use ApiPlatform\Metadata\Resource\ResourceNameCollection;
20+
use ApiPlatform\Tests\ProphecyTrait;
2121
use PHPUnit\Framework\TestCase;
2222

2323
/**

tests/Action/ExceptionActionTest.php

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414
namespace ApiPlatform\Tests\Action;
1515

1616
use ApiPlatform\Action\ExceptionAction;
17-
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
18-
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
19-
use ApiPlatform\Tests\ProphecyTrait;
2017
use ApiPlatform\Exception\InvalidArgumentException;
2118
use ApiPlatform\Metadata\ApiResource;
2219
use ApiPlatform\Metadata\Get;
2320
use ApiPlatform\Metadata\HttpOperation;
2421
use ApiPlatform\Metadata\Operations;
2522
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
2623
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
24+
use ApiPlatform\Tests\ProphecyTrait;
2725
use DomainException;
2826
use PHPUnit\Framework\TestCase;
2927
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
@@ -38,7 +36,6 @@
3836
* @author Amrouche Hamza <[email protected]>
3937
* @author Baptiste Meyer <[email protected]>
4038
*
41-
* @group legacy
4239
* @group time-sensitive
4340
*/
4441
class ExceptionActionTest extends TestCase
@@ -69,62 +66,6 @@ public function testActionWithCatchableException()
6966
$this->assertTrue($response->headers->contains('X-Frame-Options', 'deny'));
7067
}
7168

72-
/**
73-
* @dataProvider provideOperationExceptionToStatusCases
74-
* @group legacy
75-
*/
76-
public function testLegacyActionWithOperationExceptionToStatus(
77-
array $globalExceptionToStatus,
78-
?array $resourceExceptionToStatus,
79-
?array $operationExceptionToStatus,
80-
int $expectedStatusCode
81-
) {
82-
$this->expectDeprecation('Since api-platform/core 2.7: Use "ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface" instead of "ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface".');
83-
84-
$exception = new DomainException();
85-
$flattenException = FlattenException::create($exception);
86-
87-
$serializer = $this->prophesize(SerializerInterface::class);
88-
$serializer->serialize($flattenException, 'jsonproblem', ['statusCode' => $expectedStatusCode])->willReturn('');
89-
90-
$resourceMetadataFactory = $this->prophesize(ResourceMetadataFactoryInterface::class);
91-
$resourceMetadataFactory->create('Foo')->willReturn(new ResourceMetadata(
92-
'Foo',
93-
null,
94-
null,
95-
[
96-
'operation' => null !== $operationExceptionToStatus ? ['exception_to_status' => $operationExceptionToStatus] : [],
97-
],
98-
null,
99-
null !== $resourceExceptionToStatus ? ['exception_to_status' => $resourceExceptionToStatus] : []
100-
));
101-
102-
$exceptionAction = new ExceptionAction(
103-
$serializer->reveal(),
104-
[
105-
'jsonproblem' => ['application/problem+json'],
106-
'jsonld' => ['application/ld+json'],
107-
],
108-
$globalExceptionToStatus,
109-
$resourceMetadataFactory->reveal()
110-
);
111-
112-
$request = new Request();
113-
$request->setFormat('jsonproblem', 'application/problem+json');
114-
$request->attributes->replace([
115-
'_api_resource_class' => 'Foo',
116-
'_api_item_operation_name' => 'operation',
117-
]);
118-
119-
$response = $exceptionAction($flattenException, $request);
120-
121-
$this->assertSame('', $response->getContent());
122-
$this->assertSame($expectedStatusCode, $response->getStatusCode());
123-
$this->assertTrue($response->headers->contains('Content-Type', 'application/problem+json; charset=utf-8'));
124-
$this->assertTrue($response->headers->contains('X-Content-Type-Options', 'nosniff'));
125-
$this->assertTrue($response->headers->contains('X-Frame-Options', 'deny'));
126-
}
127-
12869
/**
12970
* @dataProvider provideOperationExceptionToStatusCases
13071
*/

tests/Api/IdentifiersExtractorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515

1616
use ApiPlatform\Api\IdentifiersExtractor;
1717
use ApiPlatform\Api\ResourceClassResolverInterface;
18-
use ApiPlatform\Tests\ProphecyTrait;
1918
use ApiPlatform\Metadata\Get;
2019
use ApiPlatform\Metadata\HttpOperation;
2120
use ApiPlatform\Metadata\Link;
2221
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
2322
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
2423
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
2524
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy;
25+
use ApiPlatform\Tests\ProphecyTrait;
2626
use PHPUnit\Framework\TestCase;
2727

2828
/**

tests/Api/QueryParameterValidator/QueryParameterValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
use ApiPlatform\Api\FilterInterface;
1717
use ApiPlatform\Api\QueryParameterValidator\QueryParameterValidator;
18-
use ApiPlatform\Tests\ProphecyTrait;
1918
use ApiPlatform\Exception\FilterValidationException;
2019
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy;
20+
use ApiPlatform\Tests\ProphecyTrait;
2121
use PHPUnit\Framework\TestCase;
2222
use Psr\Container\ContainerInterface;
2323

tests/Doctrine/Common/State/PersistProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
namespace ApiPlatform\Tests\Doctrine\Common\State;
1515

16-
use ApiPlatform\Tests\ProphecyTrait;
1716
use ApiPlatform\Doctrine\Common\State\PersistProcessor;
1817
use ApiPlatform\Metadata\Get;
1918
use ApiPlatform\State\ProcessorInterface;
2019
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy;
20+
use ApiPlatform\Tests\ProphecyTrait;
2121
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
2222
use Doctrine\ORM\Mapping\ClassMetadataInfo;
2323
use Doctrine\Persistence\ManagerRegistry;

tests/Doctrine/Common/State/RemoveProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
namespace ApiPlatform\Tests\Doctrine\Common\State;
1515

16-
use ApiPlatform\Tests\ProphecyTrait;
1716
use ApiPlatform\Doctrine\Common\State\RemoveProcessor;
1817
use ApiPlatform\Metadata\Delete;
1918
use ApiPlatform\State\ProcessorInterface;
2019
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy;
20+
use ApiPlatform\Tests\ProphecyTrait;
2121
use Doctrine\Persistence\ManagerRegistry;
2222
use Doctrine\Persistence\ObjectManager;
2323
use PHPUnit\Framework\TestCase;

tests/Doctrine/EventListener/PublishMercureUpdatesListenerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use ApiPlatform\Api\IriConverterInterface;
1717
use ApiPlatform\Api\ResourceClassResolverInterface;
1818
use ApiPlatform\Api\UrlGeneratorInterface;
19-
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
20-
use ApiPlatform\Tests\ProphecyTrait;
2119
use ApiPlatform\Doctrine\EventListener\PublishMercureUpdatesListener;
2220
use ApiPlatform\Exception\InvalidArgumentException;
2321
use ApiPlatform\GraphQl\Subscription\MercureSubscriptionIriGeneratorInterface as GraphQlMercureSubscriptionIriGeneratorInterface;
@@ -33,6 +31,7 @@
3331
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyFriend;
3432
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyMercure;
3533
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyOffer;
34+
use ApiPlatform\Tests\ProphecyTrait;
3635
use Doctrine\ORM\EntityManagerInterface;
3736
use Doctrine\ORM\Event\OnFlushEventArgs;
3837
use Doctrine\ORM\UnitOfWork;
@@ -309,7 +308,9 @@ public function testPublishUpdate(): void
309308

310309
$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class);
311310

312-
$resourceMetadataFactoryProphecy->create(DummyMercure::class)->willReturn(new ResourceMetadata(null, null, null, null, null, ['mercure' => []]));
311+
$resourceMetadataFactoryProphecy->create(DummyMercure::class)->willReturn(new ResourceMetadataCollection(Dummy::class, [(new ApiResource())->withOperations(new Operations([
312+
'get' => (new Get())->withMercure([]),
313+
]))]));
313314

314315
$resourceMetadataFactoryProphecy->create(Dummy::class)->willReturn(new ResourceMetadataCollection(Dummy::class, [(new ApiResource())->withOperations(new Operations([
315316
'get' => (new Get())->withMercure(['hub' => 'managed', 'enable_async_update' => false])->withNormalizationContext(['groups' => ['foo', 'bar']]),

tests/Doctrine/EventListener/PurgeHttpCacheListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use ApiPlatform\Api\IriConverterInterface;
1717
use ApiPlatform\Api\ResourceClassResolverInterface;
1818
use ApiPlatform\Api\UrlGeneratorInterface;
19-
use ApiPlatform\Tests\ProphecyTrait;
2019
use ApiPlatform\Doctrine\EventListener\PurgeHttpCacheListener;
2120
use ApiPlatform\Exception\InvalidArgumentException;
2221
use ApiPlatform\Exception\ItemNotFoundException;
@@ -25,6 +24,7 @@
2524
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy;
2625
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyNoGetOperation;
2726
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\RelatedDummy;
27+
use ApiPlatform\Tests\ProphecyTrait;
2828
use Doctrine\ORM\EntityManagerInterface;
2929
use Doctrine\ORM\Event\OnFlushEventArgs;
3030
use Doctrine\ORM\Event\PreUpdateEventArgs;

tests/Doctrine/EventListener/WriteListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
namespace ApiPlatform\Tests\Doctrine\EventListener;
1515

16-
use ApiPlatform\Tests\ProphecyTrait;
1716
use ApiPlatform\Doctrine\EventListener\WriteListener;
1817
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy;
18+
use ApiPlatform\Tests\ProphecyTrait;
1919
use Doctrine\Persistence\ManagerRegistry;
2020
use Doctrine\Persistence\ObjectManager;
2121
use PHPUnit\Framework\TestCase;

tests/Doctrine/Odm/Extension/FilterExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace ApiPlatform\Tests\Doctrine\Odm\Extension;
1515

1616
use ApiPlatform\Api\FilterInterface as ApiFilterInterface;
17-
use ApiPlatform\Tests\ProphecyTrait;
1817
use ApiPlatform\Doctrine\Odm\Extension\FilterExtension;
1918
use ApiPlatform\Doctrine\Odm\Filter\FilterInterface;
2019
use ApiPlatform\Metadata\ApiResource;
@@ -23,6 +22,7 @@
2322
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
2423
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
2524
use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy;
25+
use ApiPlatform\Tests\ProphecyTrait;
2626
use Doctrine\ODM\MongoDB\Aggregation\Builder;
2727
use PHPUnit\Framework\TestCase;
2828
use Psr\Container\ContainerInterface;

0 commit comments

Comments
 (0)