From 7fa29dcf70abef47109e13fb09c07a80a22feba3 Mon Sep 17 00:00:00 2001 From: ThomasBerranger Date: Thu, 21 Nov 2024 23:06:42 +0100 Subject: [PATCH] Expiration date order by fixed --- src/Entity/Product/Product.php | 15 ++++++------ tests/Application/Product/CreateTest.php | 5 ++-- tests/Application/Product/EditTest.php | 14 +++++------ tests/Application/Product/IndexTest.php | 30 +++++++++++------------- tests/Application/Product/ShowTest.php | 9 ++++--- 5 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/Entity/Product/Product.php b/src/Entity/Product/Product.php index cbcde9e..1371b58 100644 --- a/src/Entity/Product/Product.php +++ b/src/Entity/Product/Product.php @@ -5,7 +5,6 @@ use App\Entity\ExpirationDate; use App\Entity\User; use App\Repository\ProductRepository; -use DateTimeInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; @@ -51,11 +50,11 @@ class Product #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)] #[Groups(['show_product', 'edit_product'])] - private ?DateTimeInterface $finishedAt = null; + private ?\DateTimeInterface $finishedAt = null; #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)] #[Groups(['show_product', 'edit_product'])] - private ?DateTimeInterface $addedToListAt = null; + private ?\DateTimeInterface $addedToListAt = null; /** * @var Collection @@ -122,24 +121,24 @@ public function setImage(?string $image): static return $this; } - public function getFinishedAt(): ?DateTimeInterface + public function getFinishedAt(): ?\DateTimeInterface { return $this->finishedAt; } - public function setFinishedAt(?DateTimeInterface $finishedAt): static + public function setFinishedAt(?\DateTimeInterface $finishedAt): static { $this->finishedAt = $finishedAt; return $this; } - public function getAddedToListAt(): ?DateTimeInterface + public function getAddedToListAt(): ?\DateTimeInterface { return $this->addedToListAt; } - public function setAddedToListAt(?DateTimeInterface $addedToListAt): static + public function setAddedToListAt(?\DateTimeInterface $addedToListAt): static { $this->addedToListAt = $addedToListAt; @@ -177,7 +176,7 @@ public function removeExpirationDate(ExpirationDate $expirationDate): static } #[Groups(['show_product'])] - public function getClosestExpirationDate(): ?DateTimeInterface + public function getClosestExpirationDate(): ?\DateTimeInterface { if ($this->expirationDates->isEmpty()) { return null; diff --git a/tests/Application/Product/CreateTest.php b/tests/Application/Product/CreateTest.php index 1e2eaad..24fe0da 100644 --- a/tests/Application/Product/CreateTest.php +++ b/tests/Application/Product/CreateTest.php @@ -5,7 +5,6 @@ use ApiPlatform\Symfony\Bundle\Test\Client; use App\Tests\BaseTest; use App\Tests\User; -use JsonException; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\HttpClient\Exception\ExceptionInterface; @@ -21,7 +20,7 @@ protected function setUp(): void } /** @throws ExceptionInterface - * @throws JsonException + * @throws \JsonException */ public function testScannedProductCreateSuccess(): void { @@ -53,7 +52,7 @@ public function testScannedProductCreateSuccess(): void } /** @throws ExceptionInterface - * @throws JsonException + * @throws \JsonException */ public function testCustomProductCreateSuccess(): void { diff --git a/tests/Application/Product/EditTest.php b/tests/Application/Product/EditTest.php index 824e124..e61504f 100644 --- a/tests/Application/Product/EditTest.php +++ b/tests/Application/Product/EditTest.php @@ -7,8 +7,6 @@ use App\Entity\Product\ScannedProduct; use App\Tests\BaseTest; use App\Tests\User; -use DateTime; -use JsonException; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\HttpClient\Exception\ExceptionInterface; @@ -24,7 +22,7 @@ protected function setUp(): void } /** @throws ExceptionInterface - * @throws JsonException + * @throws \JsonException */ public function testScannedProductShow(): void { @@ -34,8 +32,8 @@ public function testScannedProductShow(): void ->setOwner($this->getLoggedUser()) ->setDescription('Product description') ->setImage('https://product-image-url') - ->setFinishedAt(new DateTime('2024-10-10 15:16:00')) - ->setAddedToListAt(new DateTime('2024-10-10 15:16:00')) + ->setFinishedAt(new \DateTime('2024-10-10 15:16:00')) + ->setAddedToListAt(new \DateTime('2024-10-10 15:16:00')) ->setBarcode('123') ->setNutriscore('A') ->setEcoscore(1) @@ -68,7 +66,7 @@ public function testScannedProductShow(): void } /** @throws ExceptionInterface - * @throws JsonException + * @throws \JsonException */ public function testCustomProductEdit(): void { @@ -78,8 +76,8 @@ public function testCustomProductEdit(): void ->setOwner($this->getLoggedUser()) ->setDescription('Product description') ->setImage('https://product-image-url') - ->setFinishedAt(new DateTime('2024-10-10 15:16:00')) - ->setAddedToListAt(new DateTime('2024-10-10 15:16:00')); + ->setFinishedAt(new \DateTime('2024-10-10 15:16:00')) + ->setAddedToListAt(new \DateTime('2024-10-10 15:16:00')); static::persistAndFlush($product); diff --git a/tests/Application/Product/IndexTest.php b/tests/Application/Product/IndexTest.php index a18a876..7f77f04 100644 --- a/tests/Application/Product/IndexTest.php +++ b/tests/Application/Product/IndexTest.php @@ -8,8 +8,6 @@ use App\Entity\Product\ScannedProduct; use App\Tests\BaseTest; use App\Tests\User; -use DateTime; -use JsonException; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\HttpClient\Exception\ExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; @@ -26,7 +24,7 @@ protected function setUp(): void } /** - * @throws TransportExceptionInterface|JsonException + * @throws TransportExceptionInterface|\JsonException */ public function testProductIndexShowProductsOrderedByClosestExpirationDate(): void { @@ -36,9 +34,9 @@ public function testProductIndexShowProductsOrderedByClosestExpirationDate(): vo ->setName('First product name') ->setDescription('First product description') ->setImage('http://first-product-image-url') - ->setFinishedAt(new DateTime('2024-10-10 15:16:00')) - ->addExpirationDate((new ExpirationDate())->setDate(new DateTime('01-02-2025'))) - ->addExpirationDate((new ExpirationDate())->setDate(new DateTime('02-02-2025'))); + ->setFinishedAt(new \DateTime('2024-10-10 15:16:00')) + ->addExpirationDate((new ExpirationDate())->setDate(new \DateTime('01-02-2025'))) + ->addExpirationDate((new ExpirationDate())->setDate(new \DateTime('02-02-2025'))); $secondProduct = new ScannedProduct(); $secondProduct @@ -46,13 +44,13 @@ public function testProductIndexShowProductsOrderedByClosestExpirationDate(): vo ->setName('Second product name') ->setDescription('Second product description') ->setImage('http://second-product-image-url') - ->setFinishedAt(new DateTime('2024-11-01 10:30:00')) - ->setAddedToListAt(new DateTime('2024-11-01 15:00:00')) + ->setFinishedAt(new \DateTime('2024-11-01 10:30:00')) + ->setAddedToListAt(new \DateTime('2024-11-01 15:00:00')) ->setBarcode('123') ->setNutriscore('C') ->setEcoscore(2) ->setNovagroup(4) - ->addExpirationDate((new ExpirationDate())->setDate(new DateTime('01-01-2025'))); + ->addExpirationDate((new ExpirationDate())->setDate(new \DateTime('01-01-2025'))); static::persistAndFlush($firstProduct, $secondProduct); @@ -92,7 +90,7 @@ public function testProductIndexShowProductsOrderedByClosestExpirationDate(): vo /** * @throws ExceptionInterface - * @throws JsonException + * @throws \JsonException */ public function testProductIndexDoNotShowProductsWithoutExpirationDate(): void { @@ -120,20 +118,20 @@ public function testProductIndexWithLimitAndOrder(int $limit, int $offset, int $ $firstProduct ->setOwner($this->getLoggedUser()) ->setName('First product name') - ->addExpirationDate((new ExpirationDate())->setDate(new DateTime('01-02-2025'))); + ->addExpirationDate((new ExpirationDate())->setDate(new \DateTime('01-02-2025'))); $secondProduct = new ScannedProduct(); $secondProduct ->setOwner($this->getLoggedUser()) ->setName('Second product name') ->setBarcode('123') - ->addExpirationDate((new ExpirationDate())->setDate(new DateTime('02-01-2025'))); + ->addExpirationDate((new ExpirationDate())->setDate(new \DateTime('02-01-2025'))); $thirdProduct = new CustomProduct(); $thirdProduct ->setOwner($this->getLoggedUser()) ->setName('Third product name') - ->addExpirationDate((new ExpirationDate())->setDate(new DateTime('03-01-2025'))); + ->addExpirationDate((new ExpirationDate())->setDate(new \DateTime('03-01-2025'))); static::persistAndFlush($firstProduct, $secondProduct, $thirdProduct); @@ -158,7 +156,7 @@ public function requestIndexParamsProvider(): array /** * @throws TransportExceptionInterface - * @throws JsonException + * @throws \JsonException */ public function testProductShoppingList(): void { @@ -166,14 +164,14 @@ public function testProductShoppingList(): void $firstProduct ->setOwner($this->getLoggedUser()) ->setName('First product name') - ->setAddedToListAt(new DateTime('2025-01-02')); + ->setAddedToListAt(new \DateTime('2025-01-02')); $secondProduct = new ScannedProduct(); $secondProduct ->setOwner($this->getLoggedUser()) ->setName('Second product name') ->setBarcode('123') - ->setAddedToListAt(new DateTime('2025-01-01')); + ->setAddedToListAt(new \DateTime('2025-01-01')); $thirdProduct = new CustomProduct(); $thirdProduct diff --git a/tests/Application/Product/ShowTest.php b/tests/Application/Product/ShowTest.php index 2a972be..35cbf05 100644 --- a/tests/Application/Product/ShowTest.php +++ b/tests/Application/Product/ShowTest.php @@ -7,7 +7,6 @@ use App\Entity\Product\ScannedProduct; use App\Tests\BaseTest; use App\Tests\User; -use DateTime; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\HttpClient\Exception\ExceptionInterface; @@ -31,8 +30,8 @@ public function testScannedProductShow(): void ->setOwner($this->getLoggedUser()) ->setDescription('Product description') ->setImage('https://product-image-url') - ->setFinishedAt(new DateTime('2024-10-10 15:16:00')) - ->setAddedToListAt(new DateTime('2024-10-10 15:16:00')) + ->setFinishedAt(new \DateTime('2024-10-10 15:16:00')) + ->setAddedToListAt(new \DateTime('2024-10-10 15:16:00')) ->setBarcode('123') ->setNutriscore('A') ->setEcoscore(1) @@ -68,8 +67,8 @@ public function testCustomProductShow(): void ->setOwner($this->getLoggedUser()) ->setDescription('Product description') ->setImage('https://product-image-url') - ->setFinishedAt(new DateTime('2024-10-10 15:16:00')) - ->setAddedToListAt(new DateTime('2024-10-10 15:16:00')); + ->setFinishedAt(new \DateTime('2024-10-10 15:16:00')) + ->setAddedToListAt(new \DateTime('2024-10-10 15:16:00')); static::persistAndFlush($product);