Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private function registerCommonConfiguration(ContainerBuilder $container, array
$container->setParameter('api_platform.collection.pagination.client_items_per_page', $config['defaults']['pagination_client_items_per_page'] ?? false);
$container->setParameter('api_platform.collection.pagination.client_partial', $config['defaults']['pagination_client_partial'] ?? false);
$container->setParameter('api_platform.collection.pagination.items_per_page', $config['defaults']['pagination_items_per_page'] ?? 30);
$container->setParameter('api_platform.collection.pagination.maximum_items_per_page', $config['defaults']['pagination_maximum_items_per_page'] ?? null);
$container->setParameter('api_platform.collection.pagination.maximum_items_per_page', \array_key_exists('pagination_maximum_items_per_page', $config['defaults']) ? $config['defaults']['pagination_maximum_items_per_page'] : 30);
$container->setParameter('api_platform.collection.pagination.page_parameter_name', $config['defaults']['pagination_page_parameter_name'] ?? $config['collection']['pagination']['page_parameter_name']);
$container->setParameter('api_platform.collection.pagination.enabled_parameter_name', $config['defaults']['pagination_enabled_parameter_name'] ?? $config['collection']['pagination']['enabled_parameter_name']);
$container->setParameter('api_platform.collection.pagination.items_per_page_parameter_name', $config['defaults']['pagination_items_per_page_parameter_name'] ?? $config['collection']['pagination']['items_per_page_parameter_name']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,41 @@ public function testItRegistersMetadataConfiguration(): void
$this->assertContainerHasService('api_platform.metadata.resource_extractor.php_file');
$this->assertSame([$emptyPhpFile], $this->container->getDefinition('api_platform.metadata.resource_extractor.php_file')->getArgument(0));
}

public function testPaginationMaximumItemsPerPageIsNotSet(): void
{
$config = self::DEFAULT_CONFIG;
(new ApiPlatformExtension())->load($config, $this->container);

$this->assertTrue($this->container->hasParameter('api_platform.collection.pagination.maximum_items_per_page'));
$this->assertSame(30, $this->container->getParameter('api_platform.collection.pagination.maximum_items_per_page'));
}

public function testPaginationMaximumItemsPerPageIsSetWithNull(): void
{
$config = self::DEFAULT_CONFIG;
$config['api_platform']['defaults']['pagination_maximum_items_per_page'] = null;
(new ApiPlatformExtension())->load($config, $this->container);

$this->assertTrue($this->container->hasParameter('api_platform.collection.pagination.maximum_items_per_page'));
$this->assertNull($this->container->getParameter('api_platform.collection.pagination.maximum_items_per_page'));
}

public function testPaginationMaximumItemsPerPageIsSetWithExplicitValue(): void
{
$config = self::DEFAULT_CONFIG;
$config['api_platform']['defaults']['pagination_maximum_items_per_page'] = 22;
(new ApiPlatformExtension())->load($config, $this->container);

$this->assertSame(22, $this->container->getParameter('api_platform.collection.pagination.maximum_items_per_page'));
}

public function testPaginationMaximumItemsPerPageIsSetWithZero(): void
{
$config = self::DEFAULT_CONFIG;
$config['api_platform']['defaults']['pagination_maximum_items_per_page'] = 0;
(new ApiPlatformExtension())->load($config, $this->container);

$this->assertSame(0, $this->container->getParameter('api_platform.collection.pagination.maximum_items_per_page'));
}
}
Loading