diff --git a/src/Metadata/Tests/Resource/OperationTest.php b/src/Metadata/Tests/Resource/OperationTest.php index 0826d88936..7b8e5ad3af 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 3acceb92e2..f68265d626 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); } }