From 394cb250f87f592bf697c8893e7ec1f71b0f7489 Mon Sep 17 00:00:00 2001 From: Maxcastel Date: Thu, 15 Oct 2026 12:15:41 +0200 Subject: [PATCH] fix(metadata): copy contentNegotiation in withOperation() --- src/Metadata/Tests/Resource/OperationTest.php | 7 +++++++ src/Metadata/WithResourceTrait.php | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Metadata/Tests/Resource/OperationTest.php b/src/Metadata/Tests/Resource/OperationTest.php index 0826d889366..7b8e5ad3af0 100644 --- a/src/Metadata/Tests/Resource/OperationTest.php +++ b/src/Metadata/Tests/Resource/OperationTest.php @@ -40,6 +40,13 @@ public function testWithResourceTrait(): void $this->assertInstanceOf(CollectionOperationInterface::class, $operation); } + public function testWithOperationCopiesContentNegotiation(): void + { + $operation = (new Get())->withOperation(new Get(contentNegotiation: false)); + + $this->assertFalse($operation->canNegotiateContent()); + } + #[DataProvider('operationProvider')] public function testOperationConstructor(Operation $operation): void { diff --git a/src/Metadata/WithResourceTrait.php b/src/Metadata/WithResourceTrait.php index 3acceb92e28..f68265d6267 100644 --- a/src/Metadata/WithResourceTrait.php +++ b/src/Metadata/WithResourceTrait.php @@ -29,7 +29,8 @@ protected function copyFrom(Metadata $resource, array $ignoredOptions = []): sta && null === $self->{$method}() && null !== $val = $resource->{$method}() ) { - $self = $self->{"with{$matches[1]}"}($val); + $wither = 'canNegotiateContent' === $method ? 'withContentNegotiation' : "with{$matches[1]}"; + $self = $self->{$wither}($val); } }