Skip to content

Commit

Permalink
Expiration date order by fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBerranger committed Nov 21, 2024
1 parent ae93349 commit 7fa29dc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 40 deletions.
15 changes: 7 additions & 8 deletions src/Entity/Product/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<int, ExpirationDate>
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions tests/Application/Product/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,7 +20,7 @@ protected function setUp(): void
}

/** @throws ExceptionInterface
* @throws JsonException
* @throws \JsonException
*/
public function testScannedProductCreateSuccess(): void
{
Expand Down Expand Up @@ -53,7 +52,7 @@ public function testScannedProductCreateSuccess(): void
}

/** @throws ExceptionInterface
* @throws JsonException
* @throws \JsonException
*/
public function testCustomProductCreateSuccess(): void
{
Expand Down
14 changes: 6 additions & 8 deletions tests/Application/Product/EditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,7 +22,7 @@ protected function setUp(): void
}

/** @throws ExceptionInterface
* @throws JsonException
* @throws \JsonException
*/
public function testScannedProductShow(): void
{
Expand All @@ -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)
Expand Down Expand Up @@ -68,7 +66,7 @@ public function testScannedProductShow(): void
}

/** @throws ExceptionInterface
* @throws JsonException
* @throws \JsonException
*/
public function testCustomProductEdit(): void
{
Expand All @@ -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);

Expand Down
30 changes: 14 additions & 16 deletions tests/Application/Product/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +24,7 @@ protected function setUp(): void
}

/**
* @throws TransportExceptionInterface|JsonException
* @throws TransportExceptionInterface|\JsonException
*/
public function testProductIndexShowProductsOrderedByClosestExpirationDate(): void
{
Expand All @@ -36,23 +34,23 @@ 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
->setOwner($this->getLoggedUser())
->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);

Expand Down Expand Up @@ -92,7 +90,7 @@ public function testProductIndexShowProductsOrderedByClosestExpirationDate(): vo

/**
* @throws ExceptionInterface
* @throws JsonException
* @throws \JsonException
*/
public function testProductIndexDoNotShowProductsWithoutExpirationDate(): void
{
Expand Down Expand Up @@ -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);

Expand All @@ -158,22 +156,22 @@ public function requestIndexParamsProvider(): array

/**
* @throws TransportExceptionInterface
* @throws JsonException
* @throws \JsonException
*/
public function testProductShoppingList(): void
{
$firstProduct = new CustomProduct();
$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
Expand Down
9 changes: 4 additions & 5 deletions tests/Application/Product/ShowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 7fa29dc

Please sign in to comment.