Skip to content

Commit

Permalink
Fix all deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
coldic3 committed Aug 23, 2024
1 parent c7e463c commit 4a1fbb9
Show file tree
Hide file tree
Showing 25 changed files with 302 additions and 76 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/vendor/
/.php-cs-fixer.php
/.php-cs-fixer.cache
/.phpunit.cache
/phpunit.xml
/.phpunit.result.cache
/behat.yaml
Expand Down
1 change: 0 additions & 1 deletion .phpunit.cache/test-results

This file was deleted.

2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"lexik/jwt-authentication-bundle": "^2.18",
"nelmio/cors-bundle": "^2.2",
"phpstan/phpdoc-parser": "^1.16",
"stof/doctrine-extensions-bundle": "^1.12",
"symfony/asset": "^6.4",
"symfony/console": "^6.4",
"symfony/dotenv": "^6.4",
Expand All @@ -30,6 +31,7 @@
"symfony/runtime": "^6.4",
"symfony/security-bundle": "^6.4",
"symfony/serializer": "^6.4",
"symfony/string": "^6.4",
"symfony/twig-bundle": "^6.4",
"symfony/uid": "^6.4",
"symfony/validator": "^6.4",
Expand Down
96 changes: 88 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 81 additions & 21 deletions spec/Core/Infrastructure/Doctrine/Orm/DoctrinePaginatorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ function it_is_initializable(
EntityManagerInterface $entityManager,
Configuration $configuration,
) {
$this->constructPaginator($paginator, $entityManager, $configuration, 0, 10);
$entityManager->getConfiguration()->willReturn($configuration);

$query = new Query($entityManager->getWrappedObject());

// Query::firstResult is set to 0 by default. It is not possible to set it to null.
$query->setFirstResult(0);
$query->setMaxResults(10);

$paginator->getQuery()->willReturn($query)->shouldBeCalledOnce();

$this->beConstructedWith($paginator);

$this->shouldHaveType(DoctrinePaginator::class);
}
Expand All @@ -41,7 +51,17 @@ function it_gets_current_page(
EntityManagerInterface $entityManager,
Configuration $configuration,
) {
$this->constructPaginator($paginator, $entityManager, $configuration, 190, 20);
$entityManager->getConfiguration()->willReturn($configuration);

$query = new Query($entityManager->getWrappedObject());

// Query::firstResult is set to 0 by default. It is not possible to set it to null.
$query->setFirstResult(190);
$query->setMaxResults(20);

$paginator->getQuery()->willReturn($query)->shouldBeCalledOnce();

$this->beConstructedWith($paginator);

$this->getCurrentPage()->shouldReturn(10);
}
Expand All @@ -51,7 +71,17 @@ function it_gets_current_page_as_a_first_page_if_first_result_is_zero(
EntityManagerInterface $entityManager,
Configuration $configuration,
) {
$this->constructPaginator($paginator, $entityManager, $configuration, 0, 10);
$entityManager->getConfiguration()->willReturn($configuration);

$query = new Query($entityManager->getWrappedObject());

// Query::firstResult is set to 0 by default. It is not possible to set it to null.
$query->setFirstResult(0);
$query->setMaxResults(10);

$paginator->getQuery()->willReturn($query)->shouldBeCalledOnce();

$this->beConstructedWith($paginator);

$this->getCurrentPage()->shouldReturn(1);
}
Expand All @@ -61,7 +91,17 @@ function it_gets_current_page_as_a_next_page_if_limit_reached(
EntityManagerInterface $entityManager,
Configuration $configuration,
) {
$this->constructPaginator($paginator, $entityManager, $configuration, 200, 10);
$entityManager->getConfiguration()->willReturn($configuration);

$query = new Query($entityManager->getWrappedObject());

// Query::firstResult is set to 0 by default. It is not possible to set it to null.
$query->setFirstResult(200);
$query->setMaxResults(10);

$paginator->getQuery()->willReturn($query)->shouldBeCalledOnce();

$this->beConstructedWith($paginator);

$this->getCurrentPage()->shouldReturn(21);
}
Expand All @@ -73,7 +113,17 @@ function it_gets_last_page(
) {
$paginator->count()->willReturn(40);

$this->constructPaginator($paginator, $entityManager, $configuration, 150, 20);
$entityManager->getConfiguration()->willReturn($configuration);

$query = new Query($entityManager->getWrappedObject());

// Query::firstResult is set to 0 by default. It is not possible to set it to null.
$query->setFirstResult(150);
$query->setMaxResults(20);

$paginator->getQuery()->willReturn($query)->shouldBeCalledOnce();

$this->beConstructedWith($paginator);

$this->getLastPage()->shouldReturn(2);
}
Expand All @@ -85,7 +135,17 @@ function it_gets_last_page_and_takes_leftovers_into_account(
) {
$paginator->count()->willReturn(45);

$this->constructPaginator($paginator, $entityManager, $configuration, 150, 20);
$entityManager->getConfiguration()->willReturn($configuration);

$query = new Query($entityManager->getWrappedObject());

// Query::firstResult is set to 0 by default. It is not possible to set it to null.
$query->setFirstResult(150);
$query->setMaxResults(20);

$paginator->getQuery()->willReturn($query)->shouldBeCalledOnce();

$this->beConstructedWith($paginator);

$this->getLastPage()->shouldReturn(3);
}
Expand All @@ -97,37 +157,37 @@ function it_gets_last_page_as_a_first_page_if_max_results_is_a_negative_number(
) {
$paginator->count()->willReturn(45);

$this->constructPaginator($paginator, $entityManager, $configuration, 150, -20);
$this->getLastPage()->shouldReturn(1);
}
$entityManager->getConfiguration()->willReturn($configuration);

function it_gets_last_page_as_a_first_page_if_max_results_is_zero(
Paginator $paginator,
EntityManagerInterface $entityManager,
Configuration $configuration,
) {
$this->constructPaginator($paginator, $entityManager, $configuration, 10, 0);
$query = new Query($entityManager->getWrappedObject());

// Query::firstResult is set to 0 by default. It is not possible to set it to null.
$query->setFirstResult(150);
$query->setMaxResults(-20);

$paginator->getQuery()->willReturn($query)->shouldBeCalledOnce();

$this->beConstructedWith($paginator);
$this->getLastPage()->shouldReturn(1);
}

private function constructPaginator(
function it_gets_last_page_as_a_first_page_if_max_results_is_zero(
Paginator $paginator,
EntityManagerInterface $entityManager,
Configuration $configuration,
?int $firstResult,
?int $maxResults,
): void {
) {
$entityManager->getConfiguration()->willReturn($configuration);

$query = new Query($entityManager->getWrappedObject());

// Query::firstResult is set to 0 by default. It is not possible to set it to null.
$query->setFirstResult($firstResult);
$query->setMaxResults($maxResults);
$query->setFirstResult(10);
$query->setMaxResults(0);

$paginator->getQuery()->willReturn($query)->shouldBeCalledOnce();

$this->beConstructedWith($paginator);

$this->getLastPage()->shouldReturn(1);
}
}
7 changes: 4 additions & 3 deletions src/Account/Infrastructure/ApiResource/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Post;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use Panda\Account\Domain\Model\UserInterface;
use Panda\Account\Infrastructure\ApiState\Processor\UserCreateProcessor;
use Panda\Account\Infrastructure\ApiState\Provider\UserProvider;
Expand All @@ -20,13 +21,13 @@
operations: [
new Get(provider: UserProvider::class),
new Post(
openapiContext: [
'responses' => [
openapi: new OpenApiOperation(
responses: [
'204' => ['description' => 'User created or already exists'],
'400' => ['description' => 'Invalid input'],
'422' => ['description' => 'Unprocessable entity'],
],
],
),
validationContext: ['groups' => self::WRITABLE_GROUPS],
output: false,
processor: UserCreateProcessor::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(
) {
}

public function process($data, Operation $operation, array $uriVariables = [], array $context = [])
public function process($data, Operation $operation, array $uriVariables = [], array $context = []): UserResource
{
Assert::isInstanceOf($data, UserResource::class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ api_platform:
title: PANDA API
version: dev
show_webby: false
use_symfony_listeners: false
keep_legacy_inflector: false
patch_formats:
json: ['application/merge-patch+json']
formats:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ doctrine:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
enable_lazy_ghost_objects: true
controller_resolver:
auto_mapping: false
resolve_target_entities:
Panda\AccountOHS\Domain\Model\Owner\OwnerInterface: Panda\Account\Domain\Model\User
Loading

0 comments on commit 4a1fbb9

Please sign in to comment.