Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ migrate:
update:
docker compose exec app php bin/console doctrine:migrations:migrate -n
docker compose exec app php bin/console app:install

fixtures:
docker compose exec app php bin/console doctrine:fixtures:load -n --purge-exclusions=users --purge-exclusions=usergroups --purge-exclusions=users_groups
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@
"league/flysystem-async-aws-s3": "^3.10",
"league/flysystem-aws-s3-v3": "^3.10",
"php-coveralls/php-coveralls": "^2.4",
"phpstan/phpstan-doctrine": "^2.0.13",
"phpstan/phpstan-symfony": "^2.0.12",
"phpstan/phpdoc-parser": "<2",
"phpstan/phpstan": "^2.1.36",
"phpstan/phpstan-doctrine": "^2.0.13",
"phpstan/phpstan-symfony": "^2.0.12",
"phpunit/phpunit": "^9.6",
"rector/rector": "^2.1",
"runtime/frankenphp-symfony": "^0.2.0",
Expand All @@ -167,7 +167,8 @@
"symfony/maker-bundle": "^1.52",
"symfony/phpunit-bridge": "^7.0",
"symfony/web-profiler-bundle": "7.4.*",
"symplify/monorepo-builder": "11.2.23"
"symplify/monorepo-builder": "11.2.23",
"zenstruck/foundry": "^2.9"
},
"config": {
"optimize-autoloader": true,
Expand Down
1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
Scheb\TwoFactorBundle\SchebTwoFactorBundle::class => ['all' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
Nelmio\SolariumBundle\NelmioSolariumBundle::class => ['all' => true],
Zenstruck\Foundry\ZenstruckFoundryBundle::class => ['dev' => true, 'test' => true],
];
16 changes: 16 additions & 0 deletions config/packages/zenstruck_foundry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
when@dev: &dev
# See full configuration: https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#full-default-bundle-configuration
zenstruck_foundry:
persistence:
# Flush only once per call of `PersistentObjectFactory::create()`
flush_once: true

# If you use the `make:factory --test` command, you may need to uncomment the following.
# See https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#generate
#services:
# App\Tests\Factory\:
# resource: '%kernel.project_dir%/tests/Factory/'
# autowire: true
# autoconfigure: true

when@test: *dev
50 changes: 49 additions & 1 deletion config/reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,9 @@
* enabled?: bool|Param, // Default: true
* },
* max_query_depth?: int|Param, // Default: 20
* graphql_playground?: array<mixed>,
* graphql_playground?: bool|array{ // Deprecated: The "graphql_playground" configuration is deprecated and will be ignored.
* enabled?: bool|Param, // Default: false
* },
* max_query_complexity?: int|Param, // Default: 500
* nesting_separator?: scalar|Param|null, // The separator to use to filter nested fields. // Default: "_"
* collection?: array{
Expand Down Expand Up @@ -2270,6 +2272,50 @@
* }>,
* }>,
* }
* @psalm-type ZenstruckFoundryConfig = array{
* auto_refresh_proxies?: bool|Param|null, // Deprecated: Since 2.0 auto_refresh_proxies defaults to true and this configuration has no effect. // Whether to auto-refresh proxies by default (https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#auto-refresh) // Default: null
* enable_auto_refresh_with_lazy_objects?: bool|Param|null, // Enable auto-refresh using PHP 8.4 lazy objects (cannot be enabled if PHP < 8.4). // Default: null
* faker?: array{ // Configure the faker used by your factories.
* locale?: scalar|Param|null, // The default locale to use for faker. // Default: null
* seed?: scalar|Param|null, // Deprecated: The "faker.seed" configuration is deprecated and will be removed in 3.0. Use environment variable "FOUNDRY_FAKER_SEED" instead. // Random number generator seed to produce the same fake values every run. // Default: null
* manage_seed?: bool|Param, // Automatically manage faker seed to ensure consistent data between test runs. // Default: true
* service?: scalar|Param|null, // Service id for custom faker instance. // Default: null
* },
* instantiator?: array{ // Configure the default instantiator used by your object factories.
* use_constructor?: bool|Param, // Use the constructor to instantiate objects. // Default: true
* allow_extra_attributes?: bool|Param, // Whether or not to skip attributes that do not correspond to properties. // Default: false
* always_force_properties?: bool|Param, // Whether or not to skip setters and force set object properties (public/private/protected) directly. // Default: false
* service?: scalar|Param|null, // Service id of your custom instantiator. // Default: null
* },
* global_state?: list<scalar|Param|null>,
* persistence?: array{
* flush_once?: bool|Param, // Flush only once per call of `PersistentObjectFactory::create()` in userland. // Default: false
* },
* orm?: array{
* auto_persist?: bool|Param, // Deprecated: Since 2.4 auto_persist defaults to true and this configuration has no effect. // Automatically persist entities when created. // Default: true
* reset?: array{
* connections?: list<scalar|Param|null>,
* entity_managers?: list<scalar|Param|null>,
* mode?: \Zenstruck\Foundry\ORM\ResetDatabase\ResetDatabaseMode::SCHEMA|\Zenstruck\Foundry\ORM\ResetDatabase\ResetDatabaseMode::MIGRATE|Param, // Reset mode to use with ResetDatabase trait // Default: "schema"
* migrations?: array{
* configurations?: list<scalar|Param|null>,
* },
* },
* },
* mongo?: array{
* auto_persist?: bool|Param, // Deprecated: Since 2.4 auto_persist defaults to true and this configuration has no effect. // Automatically persist documents when created. // Default: true
* reset?: array{
* document_managers?: list<scalar|Param|null>,
* },
* },
* make_factory?: array{
* default_namespace?: scalar|Param|null, // Default namespace where factories will be created by maker. // Default: "Factory"
* add_hints?: bool|Param, // Add "beginner" hints in the created factory. // Default: true
* },
* make_story?: array{
* default_namespace?: scalar|Param|null, // Default namespace where stories will be created by maker. // Default: "Story"
* },
* }
* @psalm-type ConfigType = array{
* imports?: ImportsConfig,
* parameters?: ParametersConfig,
Expand Down Expand Up @@ -2317,6 +2363,7 @@
* nelmio_cors?: NelmioCorsConfig,
* scheb_two_factor?: SchebTwoFactorConfig,
* nelmio_solarium?: NelmioSolariumConfig,
* zenstruck_foundry?: ZenstruckFoundryConfig,
* },
* "when@prod"?: array{
* imports?: ImportsConfig,
Expand Down Expand Up @@ -2365,6 +2412,7 @@
* nelmio_cors?: NelmioCorsConfig,
* scheb_two_factor?: SchebTwoFactorConfig,
* nelmio_solarium?: NelmioSolariumConfig,
* zenstruck_foundry?: ZenstruckFoundryConfig,
* },
* ...<string, ExtensionType|array{ // extra keys must follow the when@%env% pattern or match an extension alias
* imports?: ImportsConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ set listItems = [
},
],
[
{
(type.open == true) ? {
'name': 'customForm.show',
'href': path('customFormSendAction', { customFormId: type.id }),
'icon': 'rz-icon-ri--eye-line',
Expand Down
11 changes: 5 additions & 6 deletions src/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\DataFixtures;

use App\Story\TranslationsStory;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use RZ\Roadiz\CoreBundle\Entity\Translation;
Expand All @@ -15,13 +16,11 @@ class AppFixtures extends Fixture
#[\Override]
public function load(ObjectManager $manager): void
{
$defaultTranslation = new Translation();
$defaultTranslation->setName('en');
$defaultTranslation->setLocale('en');
$defaultTranslation->setDefaultTranslation(true);
$manager->persist($defaultTranslation);
$defaultTranslation = TranslationsStory::get('defaultTranslation');
if (!$defaultTranslation instanceof Translation) {
throw new \RuntimeException('Default translation story state is invalid.');
}

$manager->flush();
$this->addReference(self::DEFAULT_TRANSLATION_REFERENCE, $defaultTranslation);
}
}
37 changes: 3 additions & 34 deletions src/DataFixtures/ArticleFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,24 @@

namespace App\DataFixtures;

use App\Story\ArticleStory;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use RZ\Roadiz\CoreBundle\Bag\NodeTypes;
use RZ\Roadiz\CoreBundle\Entity\Translation;
use RZ\Roadiz\CoreBundle\Enum\NodeStatus;
use RZ\Roadiz\CoreBundle\Node\UniqueNodeGenerator;

class ArticleFixtures extends Fixture implements DependentFixtureInterface
{
public function __construct(
private readonly UniqueNodeGenerator $uniqueNodeGenerator,
private readonly NodeTypes $nodeTypesBag,
) {
}

#[\Override]
public function getDependencies(): array
{
return [
AppFixtures::class,
PageHierarchyFixtures::class,
];
}

#[\Override]
public function load(ObjectManager $manager): void
{
$articleType = $this->nodeTypesBag->get('Article') ?? throw new \RuntimeException('Article node type is missing.');
$articleContainer = $this->uniqueNodeGenerator->generate(
nodeType: $articleType,
translation: $this->getReference(AppFixtures::DEFAULT_TRANSLATION_REFERENCE, Translation::class),
flush: false,
);
$articleContainer->setTitle('Articles container');
$articleContainer->getNode()->setStatus(NodeStatus::PUBLISHED);
$articleContainer->setPublishedAt(new \DateTime());
$manager->flush();

for ($i = 0; $i < 50; ++$i) {
$article = $this->uniqueNodeGenerator->generate(
nodeType: $articleType,
translation: $this->getReference(AppFixtures::DEFAULT_TRANSLATION_REFERENCE, Translation::class),
parent: $articleContainer->getNode(),
flush: false,
);
$article->getNode()->setStatus(NodeStatus::PUBLISHED);
$article->setPublishedAt(new \DateTime());
}

$manager->flush();
ArticleStory::load();
}
}
27 changes: 27 additions & 0 deletions src/DataFixtures/FieldsFixtures.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\DataFixtures;

use App\Story\FieldsStory;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;

class FieldsFixtures extends Fixture implements DependentFixtureInterface
{
#[\Override]
public function getDependencies(): array
{
return [
PageHierarchyFixtures::class,
];
}

#[\Override]
public function load(ObjectManager $manager): void
{
FieldsStory::load();
}
}
43 changes: 3 additions & 40 deletions src/DataFixtures/OfferFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,24 @@

namespace App\DataFixtures;

use App\GeneratedEntity\NSOffer;
use App\Story\OfferStory;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use RZ\Roadiz\CoreBundle\Bag\NodeTypes;
use RZ\Roadiz\CoreBundle\Entity\Translation;
use RZ\Roadiz\CoreBundle\Enum\NodeStatus;
use RZ\Roadiz\CoreBundle\Node\UniqueNodeGenerator;

class OfferFixtures extends Fixture implements DependentFixtureInterface
{
public function __construct(
private readonly UniqueNodeGenerator $uniqueNodeGenerator,
private readonly NodeTypes $nodeTypesBag,
) {
}

#[\Override]
public function getDependencies(): array
{
return [
AppFixtures::class,
PageHierarchyFixtures::class,
];
}

#[\Override]
public function load(ObjectManager $manager): void
{
$offerContainer = $this->uniqueNodeGenerator->generate(
// @phpstan-ignore-next-line
nodeType: $this->nodeTypesBag->get('Offer'),
// @phpstan-ignore-next-line
translation: $this->getReference(AppFixtures::DEFAULT_TRANSLATION_REFERENCE, Translation::class),
flush: false,
);
$offerContainer->setTitle('Offers container');
$offerContainer->getNode()->setStatus(NodeStatus::PUBLISHED);
$offerContainer->setPublishedAt(new \DateTime());

for ($i = 0; $i < 50; ++$i) {
/** @var NSOffer $offer */
$offer = $this->uniqueNodeGenerator->generate(
// @phpstan-ignore-next-line
nodeType: $this->nodeTypesBag->get('Offer'),
// @phpstan-ignore-next-line
translation: $this->getReference(AppFixtures::DEFAULT_TRANSLATION_REFERENCE, Translation::class),
parent: $offerContainer->getNode(),
flush: false,
);
$offer->getNode()->setStatus(NodeStatus::PUBLISHED);
$offer->setPrice(mt_rand(10, 10000));
$offer->setVat(0.2);
$offer->setPublishedAt(new \DateTime());
}

$manager->flush();
OfferStory::load();
}
}
34 changes: 2 additions & 32 deletions src/DataFixtures/PageHierarchyFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,13 @@

namespace App\DataFixtures;

use App\Story\PageHierarchyStory;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use RZ\Roadiz\CoreBundle\Bag\NodeTypes;
use RZ\Roadiz\CoreBundle\Entity\Translation;
use RZ\Roadiz\CoreBundle\Enum\NodeStatus;
use RZ\Roadiz\CoreBundle\Node\UniqueNodeGenerator;

class PageHierarchyFixtures extends Fixture implements DependentFixtureInterface
{
public function __construct(
private readonly UniqueNodeGenerator $uniqueNodeGenerator,
private readonly NodeTypes $nodeTypesBag,
) {
}

#[\Override]
public function getDependencies(): array
{
Expand All @@ -31,27 +22,6 @@ public function getDependencies(): array
#[\Override]
public function load(ObjectManager $manager): void
{
$parent = null;
for ($i = 1; $i <= 5; ++$i) {
$page = $this->uniqueNodeGenerator->generate(
// @phpstan-ignore-next-line
nodeType: $this->nodeTypesBag->get('Page'),
// @phpstan-ignore-next-line
translation: $this->getReference(AppFixtures::DEFAULT_TRANSLATION_REFERENCE, Translation::class),
parent: $parent?->getNode(),
flush: false,
);
$parent = $page;

$page->setTitle('Page level '.$i);
$page->getNode()->setNodeName('Page level '.$i);
$page->getNode()->setStatus(NodeStatus::PUBLISHED);
$page->setPublishedAt(new \DateTime());

if (1 === $i) {
$page->getNode()->setHome(true);
}
}
$manager->flush();
PageHierarchyStory::load();
}
}
27 changes: 27 additions & 0 deletions src/DataFixtures/TagFixtures.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\DataFixtures;

use App\Story\TagStory;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;

class TagFixtures extends Fixture implements DependentFixtureInterface
{
#[\Override]
public function getDependencies(): array
{
return [
ArticleFixtures::class,
];
}

#[\Override]
public function load(ObjectManager $manager): void
{
TagStory::load();
}
}
Loading
Loading