tetssssss

This commit is contained in:
lubiana 2025-06-10 19:05:55 +02:00
parent 6f07d70436
commit 8063e7bec9
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
28 changed files with 771 additions and 273 deletions

View file

@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
use App\Entity\DrinkType;
use App\Repository\DrinkTypeRepository;
use Doctrine\ORM\EntityManagerInterface;
test('findAll returns all drink types ordered by wantedStock DESC', function (): void {
$em = $this->getContainer()->get(EntityManagerInterface::class);
$repository = $this->getContainer()->get(DrinkTypeRepository::class);
// Clear existing drink types
$existingDrinkTypes = $repository->findAll();
foreach ($existingDrinkTypes as $drinkType) {
$em->remove($drinkType);
}
$em->flush();
// Create test drink types with different wantedStock values
$drinkType1 = new DrinkType();
$drinkType1->setName('Drink Type 1');
$drinkType1->setWantedStock(5);
$drinkType2 = new DrinkType();
$drinkType2->setName('Drink Type 2');
$drinkType2->setWantedStock(10);
$drinkType3 = new DrinkType();
$drinkType3->setName('Drink Type 3');
$drinkType3->setWantedStock(0);
// Persist the drink types
$em->persist($drinkType1);
$em->persist($drinkType2);
$em->persist($drinkType3);
$em->flush();
// Test findAll method
$result = $repository->findAll();
// Verify the result
expect($result)->toHaveCount(3);
expect($result[0]->getName())->toBe('Drink Type 2');
expect($result[1]->getName())->toBe('Drink Type 1');
expect($result[2]->getName())->toBe('Drink Type 3');
});
test('findWanted returns only drink types with wantedStock > 0 ordered by wantedStock DESC and name ASC', function (): void {
$em = $this->getContainer()->get(EntityManagerInterface::class);
$repository = $this->getContainer()->get(DrinkTypeRepository::class);
// Clear existing drink types
$existingDrinkTypes = $repository->findAll();
foreach ($existingDrinkTypes as $drinkType) {
$em->remove($drinkType);
}
$em->flush();
// Create test drink types with different wantedStock values
$drinkType1 = new DrinkType();
$drinkType1->setName('Cola');
$drinkType1->setWantedStock(10);
$drinkType2 = new DrinkType();
$drinkType2->setName('Beer');
$drinkType2->setWantedStock(10);
$drinkType3 = new DrinkType();
$drinkType3->setName('Water');
$drinkType3->setWantedStock(5);
$drinkType4 = new DrinkType();
$drinkType4->setName('Juice');
$drinkType4->setWantedStock(0);
// Persist the drink types
$em->persist($drinkType1);
$em->persist($drinkType2);
$em->persist($drinkType3);
$em->persist($drinkType4);
$em->flush();
// Test findWanted method
$result = $repository->findWanted();
// Verify the result
expect($result)->toHaveCount(3);
// First should be Beer (wantedStock 10, name starts with B)
expect($result[0]->getName())->toBe('Beer');
expect($result[0]->getWantedStock())->toBe(10);
// Second should be Cola (wantedStock 10, name starts with C)
expect($result[1]->getName())->toBe('Cola');
expect($result[1]->getWantedStock())->toBe(10);
// Third should be Water (wantedStock 5)
expect($result[2]->getName())->toBe('Water');
expect($result[2]->getWantedStock())->toBe(5);
// Juice should not be in the result (wantedStock 0)
$names = array_map(fn($dt) => $dt->getName(), $result);
expect($names)->not->toContain('Juice');
});