-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #377 from loic425/feature/foundry
Use Foundry for data fixtures
- Loading branch information
Showing
41 changed files
with
380 additions
and
739 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# See full configuration: https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#full-default-bundle-configuration | ||
zenstruck_foundry: | ||
# Whether to auto-refresh proxies by default (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#auto-refresh) | ||
auto_refresh_proxies: true |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Unless you want different configuration for test/dev environments, | ||
# add configuration to config/packages/dev/zenstruck_foundry.yml | ||
# and this will be synced to your test environment. | ||
imports: | ||
- { resource: ../dev/zenstruck_foundry.yaml } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/Monofony/Pack/CorePack/.recipe/config/packages/monofony_fixtures.yaml
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
src/Monofony/Pack/CorePack/.recipe/config/sylius/fixtures.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Monofony/Pack/CorePack/.recipe/src/DataFixtures/DefaultFixtures.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DataFixtures; | ||
|
||
use App\Story\DefaultAdministratorsStory; | ||
use App\Story\DefaultAppUsersStory; | ||
use Doctrine\Bundle\FixturesBundle\Fixture; | ||
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface; | ||
use Doctrine\Persistence\ObjectManager; | ||
|
||
class DefaultFixtures extends Fixture implements FixtureGroupInterface | ||
{ | ||
public function load(ObjectManager $manager): void | ||
{ | ||
DefaultAdministratorsStory::load(); | ||
DefaultAppUsersStory::load(); | ||
} | ||
|
||
public static function getGroups(): array | ||
{ | ||
return ['default']; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Monofony/Pack/CorePack/.recipe/src/DataFixtures/FakeFixtures.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DataFixtures; | ||
|
||
use App\Story\RandomAppUsersStory; | ||
use Doctrine\Bundle\FixturesBundle\Fixture; | ||
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface; | ||
use Doctrine\Persistence\ObjectManager; | ||
|
||
class FakeFixtures extends Fixture implements FixtureGroupInterface | ||
{ | ||
public function load(ObjectManager $manager): void | ||
{ | ||
RandomAppUsersStory::load(); | ||
} | ||
|
||
public static function getGroups(): array | ||
{ | ||
return ['fake']; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/Monofony/Pack/CorePack/.recipe/src/Factory/AdminUserFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Factory; | ||
|
||
use App\Entity\User\AdminUser; | ||
use Monofony\Contracts\Core\Model\User\AdminUserInterface; | ||
use Zenstruck\Foundry\ModelFactory; | ||
use Zenstruck\Foundry\Proxy; | ||
|
||
/** | ||
* @extends ModelFactory<AdminUser> | ||
* | ||
* @method static AdminUser|Proxy createOne(array $attributes = []) | ||
* @method static AdminUser[]|Proxy[] createMany(int $number, array|callable $attributes = []) | ||
* @method static AdminUser|Proxy find(object|array|mixed $criteria) | ||
* @method static AdminUser|Proxy findOrCreate(array $attributes) | ||
* @method static AdminUser|Proxy first(string $sortedField = 'id') | ||
* @method static AdminUser|Proxy last(string $sortedField = 'id') | ||
* @method static AdminUser|Proxy random(array $attributes = []) | ||
* @method static AdminUser|Proxy randomOrCreate(array $attributes = []) | ||
* @method static AdminUser[]|Proxy[] all() | ||
* @method static AdminUser[]|Proxy[] findBy(array $attributes) | ||
* @method static AdminUser[]|Proxy[] randomSet(int $number, array $attributes = []) | ||
* @method static AdminUser[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) | ||
* @method AdminUser|Proxy create(array|callable $attributes = []) | ||
*/ | ||
final class AdminUserFactory extends ModelFactory | ||
{ | ||
protected function getDefaults(): array | ||
{ | ||
return [ | ||
'email' => self::faker()->email(), | ||
'username' => self::faker()->userName(), | ||
'enabled' => true, | ||
'password' => 'password', | ||
'first_name' => self::faker()->firstName(), | ||
'last_name' => self::faker()->lastName(), | ||
]; | ||
} | ||
|
||
protected function initialize(): self | ||
{ | ||
return $this | ||
->afterInstantiate(function (AdminUserInterface $adminUser) { | ||
$adminUser->setPlainPassword($adminUser->getPassword()); | ||
$adminUser->setPassword(null); | ||
}) | ||
; | ||
} | ||
|
||
protected static function getClass(): string | ||
{ | ||
return AdminUser::class; | ||
} | ||
} |
Oops, something went wrong.