Skip to content
This repository was archived by the owner on Dec 29, 2023. It is now read-only.

Commit 5e921b3

Browse files
committed
Fixture: Use AbstractFixture for default classes
1 parent d643c77 commit 5e921b3

File tree

6 files changed

+31
-85
lines changed

6 files changed

+31
-85
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
namespace App\DataFixtures;
3+
4+
use Doctrine\Bundle\FixturesBundle\{Fixture, FixtureGroupInterface};
5+
use Faker\Factory as FakerFactory;
6+
7+
abstract class AbstractFixture extends Fixture implements FixtureGroupInterface
8+
{
9+
public const NB_FIXTURE = 10;
10+
protected \Faker\Generator $faker;
11+
12+
public function __construct()
13+
{
14+
$this->faker = FakerFactory::create();
15+
}
16+
17+
/**
18+
* @return string[]
19+
*/
20+
static public function getGroups(): array
21+
{
22+
return ['default'];
23+
}
24+
}

src/DataFixtures/CategoryFixtures.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
<?php
2-
32
namespace App\DataFixtures;
43

54
use App\Entity\Category;
6-
use Doctrine\Bundle\FixturesBundle\Fixture;
7-
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
85
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
96
use Doctrine\Persistence\ObjectManager;
10-
use Faker\Factory as FakerFactory;
117
use Symfony\Component\HttpFoundation\File\UploadedFile;
128

13-
class CategoryFixtures extends Fixture implements DependentFixtureInterface, FixtureGroupInterface
9+
class CategoryFixtures extends AbstractFixture implements DependentFixtureInterface
1410
{
1511
public const NB_FIXTURE = 7;
16-
private \Faker\Generator $faker;
1712

1813
public function __construct(private string $imagesPublic, private string $imagesCategoryPublic)
1914
{
20-
$this->faker = FakerFactory::create();
15+
parent::__construct();
2116
}
2217

2318
/**
@@ -77,12 +72,4 @@ public function getDependencies(): array
7772
DossierFixtures::class,
7873
];
7974
}
80-
81-
/**
82-
* @return string[]
83-
*/
84-
public static function getGroups(): array
85-
{
86-
return ['default'];
87-
}
8875
}
Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
<?php
2-
32
namespace App\DataFixtures;
43

54
use App\Entity\Client;
6-
use Doctrine\Bundle\FixturesBundle\Fixture;
7-
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
85
use Doctrine\Persistence\ObjectManager;
9-
use Faker\Factory as FakerFactory;
106

11-
class ClientFixtures extends Fixture implements FixtureGroupInterface
7+
class ClientFixtures extends AbstractFixture
128
{
13-
public const NB_FIXTURE = 10;
14-
private \Faker\Generator $faker;
15-
16-
public function __construct()
17-
{
18-
$this->faker = FakerFactory::create();
19-
}
20-
219
public function load(ObjectManager $manager): void
2210
{
2311
for ($i = 0; $i < self::NB_FIXTURE; ++$i) {
@@ -35,12 +23,4 @@ public function load(ObjectManager $manager): void
3523

3624
$manager->flush();
3725
}
38-
39-
/**
40-
* @return string[]
41-
*/
42-
public static function getGroups(): array
43-
{
44-
return ['default'];
45-
}
4626
}

src/DataFixtures/DossierFixtures.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
<?php
2-
32
namespace App\DataFixtures;
43

54
use App\Entity\Enum\DossierStatusEnum;
65
use App\Entity\{Client, Dossier, User};
7-
use Doctrine\Bundle\FixturesBundle\Fixture;
8-
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
96
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
107
use Doctrine\Persistence\ObjectManager;
11-
use Faker\Factory as FakerFactory;
128

13-
class DossierFixtures extends Fixture implements DependentFixtureInterface, FixtureGroupInterface
9+
class DossierFixtures extends AbstractFixture implements DependentFixtureInterface
1410
{
1511
public const NB_FIXTURE = 20;
16-
private \Faker\Generator $faker;
17-
18-
public function __construct()
19-
{
20-
$this->faker = FakerFactory::create();
21-
}
2212

2313
public function load(ObjectManager $manager): void
2414
{
@@ -60,12 +50,4 @@ public function getDependencies(): array
6050
UserFixtures::class,
6151
];
6252
}
63-
64-
/**
65-
* @return string[]
66-
*/
67-
public static function getGroups(): array
68-
{
69-
return ['default'];
70-
}
7153
}

src/DataFixtures/TodolistFixtures.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
<?php
2-
32
namespace App\DataFixtures;
43

54
use App\Entity2\Todolist;
6-
use Doctrine\Bundle\FixturesBundle\{Fixture, FixtureGroupInterface};
75
use Doctrine\Persistence\ObjectManager;
8-
use Faker\Factory as FakerFactory;
96

10-
class TodolistFixtures extends Fixture implements FixtureGroupInterface
7+
class TodolistFixtures extends AbstractFixture
118
{
129
public const NB_FIXTURE = 5;
13-
private \Faker\Generator $faker;
14-
15-
public function __construct()
16-
{
17-
$this->faker = FakerFactory::create();
18-
}
1910

2011
public function load(ObjectManager $manager): void
2112
{
@@ -35,7 +26,7 @@ public function load(ObjectManager $manager): void
3526
/**
3627
* @return string[]
3728
*/
38-
public static function getGroups(): array
29+
static public function getGroups(): array
3930
{
4031
return ['second'];
4132
}

src/DataFixtures/UserFixtures.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
<?php
2-
32
namespace App\DataFixtures;
43

54
use App\Entity\User;
6-
use Doctrine\Bundle\FixturesBundle\Fixture;
7-
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
85
use Doctrine\Persistence\ObjectManager;
9-
use Faker\Factory as FakerFactory;
106

11-
class UserFixtures extends Fixture implements FixtureGroupInterface
7+
class UserFixtures extends AbstractFixture
128
{
139
public const USERS = [
1410
'admin' => ['enabled' => true, 'roles' => [User::ROLE_ADMIN]],
@@ -17,12 +13,6 @@ class UserFixtures extends Fixture implements FixtureGroupInterface
1713
'commentator' => ['enabled' => true, 'roles' => [User::ROLE_COMMENTATOR]],
1814
];
1915
public const PASSWORD = 'local';
20-
private \Faker\Generator $faker;
21-
22-
public function __construct()
23-
{
24-
$this->faker = FakerFactory::create();
25-
}
2616

2717
public function load(ObjectManager $manager): void
2818
{
@@ -42,12 +32,4 @@ public function load(ObjectManager $manager): void
4232

4333
$manager->flush();
4434
}
45-
46-
/**
47-
* @return string[]
48-
*/
49-
public static function getGroups(): array
50-
{
51-
return ['default'];
52-
}
5335
}

0 commit comments

Comments
 (0)