From b3cdf22275c13a50cdb5ffe3dcd58d0974e9768a Mon Sep 17 00:00:00 2001
From: Vincent Chalamon <407859+vincentchalamon@users.noreply.github.com>
Date: Fri, 8 Sep 2023 15:20:49 +0200
Subject: [PATCH] fix(metadata): fix CreateProvider Behat tests
---
src/State/CreateProvider.php | 2 +-
src/Symfony/Bundle/Resources/config/state.xml | 2 +-
tests/State/CreateProviderTest.php | 14 +++++++-------
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/State/CreateProvider.php b/src/State/CreateProvider.php
index b805d2eb4a8..1ff9c6ed4c8 100644
--- a/src/State/CreateProvider.php
+++ b/src/State/CreateProvider.php
@@ -57,7 +57,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
->create($relationClass)
->getOperation($operation->getExtraProperties()['parent_uri_template'] ?? null);
try {
- $relation = $this->decorated->provide($parentOperation, $uriVariables);
+ $relation = $this->decorated->provide($parentOperation, $uriVariables, $context);
} catch (ProviderNotFoundException) {
$relation = null;
}
diff --git a/src/Symfony/Bundle/Resources/config/state.xml b/src/Symfony/Bundle/Resources/config/state.xml
index 11f68df3626..a866331c2a2 100644
--- a/src/Symfony/Bundle/Resources/config/state.xml
+++ b/src/Symfony/Bundle/Resources/config/state.xml
@@ -81,7 +81,7 @@
-
+
diff --git a/tests/State/CreateProviderTest.php b/tests/State/CreateProviderTest.php
index 088539c9d5f..b11efb6e66d 100644
--- a/tests/State/CreateProviderTest.php
+++ b/tests/State/CreateProviderTest.php
@@ -54,7 +54,7 @@ public function testProvide(): void
new ApiResource(operations: [$parentOperation]),
])
);
- $decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willReturn(new Company());
+ $decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willReturn(new Company());
$createProvider = new CreateProvider($decorated->reveal(), $resourceMetadataCollectionFactory->reveal());
$createProvider->provide($operation, $uriVariables);
@@ -78,7 +78,7 @@ public function testProvideParentNotFound(): void
new ApiResource(operations: [$parentOperation]),
])
);
- $decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willReturn(null);
+ $decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willReturn(null);
$this->expectException(NotFoundHttpException::class);
@@ -104,7 +104,7 @@ public function testProvideParentProviderNotFound(): void
new ApiResource(operations: [$parentOperation]),
])
);
- $decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willThrow(ProviderNotFoundException::class);
+ $decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willThrow(ProviderNotFoundException::class);
$this->expectException(NotFoundHttpException::class);
@@ -127,7 +127,7 @@ class: Employee::class,
$parentOperation = new Get(uriVariables: ['id' => $link], class: Company::class);
$resourceMetadataCollectionFactory->create(Company::class)->shouldBeCalledOnce()->willThrow(ResourceClassNotFoundException::class);
- $decorated->provide($parentOperation, $uriVariables)->shouldNotBeCalled();
+ $decorated->provide($parentOperation, $uriVariables, [])->shouldNotBeCalled();
$this->expectException(ResourceClassNotFoundException::class);
@@ -157,7 +157,7 @@ class: Employee::class,
new ApiResource(),
])
);
- $decorated->provide($parentOperation, $uriVariables)->shouldNotBeCalled();
+ $decorated->provide($parentOperation, $uriVariables, [])->shouldNotBeCalled();
$this->expectException(OperationNotFoundException::class);
@@ -191,7 +191,7 @@ class: Employee::class,
]),
])
);
- $decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willReturn(new Company());
+ $decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willReturn(new Company());
$createProvider = new CreateProvider($decorated->reveal(), $resourceMetadataCollectionFactory->reveal());
$createProvider->provide($operation, $uriVariables);
@@ -215,7 +215,7 @@ public function testProvideFailsProperlyOnComplexConstructor(): void
new ApiResource(operations: [$parentOperation]),
])
);
- $decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willReturn(new Company());
+ $decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willReturn(new Company());
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('An error occurred while trying to create an instance of the "ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyResourceWithComplexConstructor" resource. Consider writing your own "ApiPlatform\State\ProviderInterface" implementation and setting it as `provider` on your operation instead.');