Skip to content

Commit

Permalink
fixed broken tests because of deprecated method
Browse files Browse the repository at this point in the history
  • Loading branch information
felix.ruf committed Feb 24, 2025
1 parent e4b8eae commit c461b61
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,12 @@ protected function getRandomUsers(): array
private function getProfiles(): array
{
if (null === $this->profiles) {
$this->profiles = [];
foreach ($this->referenceRepository->getReferences() as $key => $reference) {
if ($reference instanceof Profile) {
$this->profiles[$reference->getUsername()] = $this->getReference($key);
}
foreach ($this->referenceRepository->getReferencesByClass()[Profile::class] as $key => $reference) {
$this->profiles[$reference->getUsername()] = $this->getReference($key, Profile::class);
}
}

return $this->profiles;
return $this->profiles ?? [];
}

private function getUser(string $username): Profile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
namespace App\Mealz\AccountingBundle\Tests\Controller;

use App\Mealz\AccountingBundle\Entity\Transaction;
use App\Mealz\MealBundle\DataFixtures\ORM\LoadCategories;
use App\Mealz\MealBundle\DataFixtures\ORM\LoadDays;
use App\Mealz\MealBundle\DataFixtures\ORM\LoadDishes;
use App\Mealz\MealBundle\DataFixtures\ORM\LoadDishVariations;
use App\Mealz\MealBundle\DataFixtures\ORM\LoadMeals;
use App\Mealz\MealBundle\DataFixtures\ORM\LoadWeeks;
use App\Mealz\MealBundle\Tests\Controller\AbstractControllerTestCase;
use App\Mealz\UserBundle\DataFixtures\ORM\LoadRoles;
use App\Mealz\UserBundle\DataFixtures\ORM\LoadUsers;
Expand All @@ -25,6 +30,11 @@ protected function setUp(): void

$this->clearAllTables();
$this->loadFixtures([
new LoadWeeks(),
new LoadDays(),
new LoadCategories(),
new LoadDishes(),
new LoadDishVariations(),
new LoadMeals(),
new LoadRoles(),
new LoadUsers(self::getContainer()->get('security.user_password_hasher')),
Expand Down
10 changes: 4 additions & 6 deletions src/Mealz/MealBundle/DataFixtures/ORM/LoadCombinations.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ public function getOrder(): int

protected function loadWeeks(): void
{
foreach ($this->referenceRepository->getReferences() as $referenceName => $reference) {
if ($reference instanceof Week) {
// we can't just use $reference here, because
// getReference() does some doctrine magic that getReferences() does not
$this->weeks[] = $this->getReference($referenceName);
}
foreach (array_keys($this->referenceRepository->getReferencesByClass()[Week::class]) as $key) {
// we can't just use $reference here, because
// getReference() does some doctrine magic that getReferencesByClass() does not
$this->weeks[] = $this->getReference($key, Week::class);
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/Mealz/MealBundle/DataFixtures/ORM/LoadDays.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ public function getOrder(): int

protected function loadWeeks(): void
{
foreach ($this->referenceRepository->getReferences() as $referenceName => $reference) {
if ($reference instanceof Week) {
// we can't just use $reference here, because
// getReference() does some doctrine magic that getReferences() does not
$this->weeks[] = $this->getReference($referenceName);
}
foreach (array_keys($this->referenceRepository->getReferencesByClass()[Week::class]) as $key) {
// we can't just use $reference here, because
// getReference() does some doctrine magic that getReferencesByClass() does not
$this->weeks[] = $this->getReference($key, Week::class);
}
}
}
10 changes: 4 additions & 6 deletions src/Mealz/MealBundle/DataFixtures/ORM/LoadDishVariations.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ public function getOrder(): int

protected function loadDishes(): void
{
foreach ($this->referenceRepository->getReferences() as $referenceName => $reference) {
if ($reference instanceof Dish) {
// we can't just use $reference here, because
// getReference() does some doctrine magic that getReferences() does not
$this->dishes[] = $this->getReference($referenceName);
}
foreach (array_keys($this->referenceRepository->getReferencesByClass()[Dish::class]) as $key) {
// we can't just use $reference here, because
// getReference() does some doctrine magic that getReferencesByClass() does not
$this->dishes[] = $this->getReference($key, Dish::class);
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/Mealz/MealBundle/DataFixtures/ORM/LoadDishes.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ public function load(ObjectManager $manager): void

public function loadCategories(): void
{
foreach ($this->referenceRepository->getReferences() as $referenceName => $reference) {
if ($reference instanceof Category) {
// we can't just use $reference here, because
// getReference() does some doctrine magic that getReferences() does not
$this->categories[] = $this->getReference($referenceName);
}
foreach (array_keys($this->referenceRepository->getReferencesByClass()[Category::class]) as $key) {
// we can't just use $reference here, because
// getReference() does some doctrine magic that getReferencesByClass() does not
$this->categories[] = $this->getReference($key, Category::class);
}
}

Expand Down
16 changes: 7 additions & 9 deletions src/Mealz/MealBundle/DataFixtures/ORM/LoadMeals.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ public function getOrder(): int

protected function loadDishes(): void
{
foreach ($this->referenceRepository->getReferences() as $referenceName => $reference) {
foreach ($this->referenceRepository->getReferencesByClass()[Dish::class] as $key => $reference) {
if (($reference instanceof Dish) && !($reference instanceof DishVariation)) {
// we can't just use $reference here, because
// getReference() does some doctrine magic that getReferences() does not
// getReference() does some doctrine magic that getReferencesByClass() does not
/** @var Dish $dish */
$dish = $this->getReference($referenceName);
$dish = $this->getReference($key, Dish::class);

if ($dish->hasVariations()) {
$this->dishesWithVar[] = $dish;
Expand All @@ -126,12 +126,10 @@ protected function loadDishes(): void

protected function loadDays(): void
{
foreach ($this->referenceRepository->getReferences() as $referenceName => $reference) {
if ($reference instanceof Day) {
// we can't just use $reference here, because
// getReference() does some doctrine magic that getReferences() does not
$this->days[] = $this->getReference($referenceName);
}
foreach (array_keys($this->referenceRepository->getReferencesByClass()[Day::class]) as $key) {
// we can't just use $reference here, because
// getReference() does some doctrine magic that getReferencesByClass() does not
$this->days[] = $this->getReference($key, Day::class);
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/Mealz/MealBundle/DataFixtures/ORM/LoadParticipants.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,16 @@ public function getOrder(): int

protected function loadReferences(): void
{
foreach ($this->referenceRepository->getReferences() as $referenceName => $reference) {
if ($reference instanceof Meal) {
// we can't just use $reference here, because
// getReference() does some doctrine magic that getReferences() does not
$this->meals[] = $this->getReference($referenceName);
} elseif ($reference instanceof Profile) {
$this->profiles[] = $this->getReference($referenceName);
} elseif ($reference instanceof Slot) {
$this->slots[] = $this->getReference($referenceName);
}
foreach ($this->referenceRepository->getReferencesByClass()[Meal::class] as $key => $reference) {
$this->meals[] = $this->getReference($key, Meal::class);
}

foreach ($this->referenceRepository->getReferencesByClass()[Profile::class] as $key => $reference) {
$this->profiles[] = $this->getReference($key, Profile::class);
}

foreach ($this->referenceRepository->getReferencesByClass()[Slot::class] as $key => $reference) {
$this->slots[] = $this->getReference($key, Slot::class);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Mealz\MealBundle\Tests\Service;

use App\Mealz\MealBundle\DataFixtures\ORM\LoadCategories;
use App\Mealz\MealBundle\DataFixtures\ORM\LoadDays;
use App\Mealz\MealBundle\DataFixtures\ORM\LoadDishes;
use App\Mealz\MealBundle\DataFixtures\ORM\LoadDishVariations;
Expand Down Expand Up @@ -32,6 +33,7 @@ protected function setUp(): void
$this->loadFixtures([
new LoadWeeks(),
new LoadDays(),
new LoadCategories(),
new LoadDishes(),
new LoadDishVariations(),
new LoadMeals(),
Expand Down

0 comments on commit c461b61

Please sign in to comment.