Skip to content

Commit

Permalink
fix(metadata): defaults (api-platform#4759)
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Jun 29, 2022
1 parent 776b4f0 commit ed329bf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final class AttributesResourceMetadataCollectionFactory implements ResourceMetad

public function __construct(ResourceMetadataCollectionFactoryInterface $decorated = null, LoggerInterface $logger = null, array $defaults = [], bool $graphQlEnabled = false)
{
$this->defaults = $defaults + ['attributes' => []];
$this->defaults = $defaults;
$this->decorated = $decorated;
$this->logger = $logger ?? new NullLogger();
$this->graphQlEnabled = $graphQlEnabled;
Expand Down Expand Up @@ -235,7 +235,7 @@ private function getOperationWithDefaults(ApiResource $resource, Operation $oper
private function addGlobalDefaults($operation)
{
$extraProperties = $operation->getExtraProperties();
foreach ($this->defaults['attributes'] as $key => $value) {
foreach ($this->defaults as $key => $value) {
[$newKey, $value] = $this->getKeyValue($key, $value);
$upperKey = ucfirst($newKey);
$getter = 'get'.$upperKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class: AttributeResources::class,

public function testCreateWithDefaults(): void
{
$attributeResourceMetadataCollectionFactory = new AttributesResourceMetadataCollectionFactory(null, null, ['attributes' => ['cache_headers' => ['max_age' => 60], 'non_existing_attribute' => 'foo']]);
$attributeResourceMetadataCollectionFactory = new AttributesResourceMetadataCollectionFactory(null, null, ['cache_headers' => ['max_age' => 60], 'non_existing_attribute' => 'foo']);

$operation = new HttpOperation(shortName: 'AttributeDefaultOperations', class: AttributeDefaultOperations::class, cacheHeaders: ['max_age' => 60], paginationItemsPerPage: 10, extraProperties: ['non_existing_attribute' => 'foo']);

Expand Down Expand Up @@ -165,9 +165,7 @@ public function testCreateShouldNotOverrideWithDefault(): void
{
$attributeResourceMetadataCollectionFactory = new AttributesResourceMetadataCollectionFactory(
null, null, [
'attributes' => [
'pagination_items_per_page' => 3,
],
'pagination_items_per_page' => 3,
]
);

Expand Down

0 comments on commit ed329bf

Please sign in to comment.