Skip to content

Commit

Permalink
Doctrine requirement is now optional
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Sep 23, 2024
1 parent 7125cd7 commit f490265
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 80 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"babdev/pagerfanta-bundle": "^3.7 || ^4.0",
"doctrine/annotations": "^2.0",
"doctrine/collections": "^1.8 || ^2.0",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/event-manager": "^1.1 || ^2.0",
"doctrine/inflector": "^1.4 || ^2.0",
"doctrine/persistence": "^2.0 || ^3.0",
Expand Down Expand Up @@ -57,6 +56,7 @@
"sylius/resource": "self.version"
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.0",
"doctrine/orm": "^2.5",
"friendsofsymfony/rest-bundle": "^3.0",
"jms/serializer-bundle": "^3.5 || ^4.0 || ^5.0",
Expand Down Expand Up @@ -102,7 +102,8 @@
"allow-plugins": {
"symfony/flex": true,
"dealerdirect/phpcodesniffer-composer-installer": false
}
},
"sort-packages": true
},
"extra": {
"symfony": {
Expand Down
2 changes: 1 addition & 1 deletion src/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private function addDriversSection(ArrayNodeDefinition $node): void
$node
->children()
->arrayNode('drivers')
->defaultValue([SyliusResourceBundle::DRIVER_DOCTRINE_ORM])
->defaultValue([])
->enumPrototype()->values(SyliusResourceBundle::getAvailableDrivers())->end()
->end()
->end()
Expand Down
111 changes: 94 additions & 17 deletions src/Bundle/DependencyInjection/SyliusResourceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function load(array $configs, ContainerBuilder $container): void

$loader->load('services.xml');

/** @var array $bundles */
/** @var array<string, string> $bundles */
$bundles = $container->getParameter('kernel.bundles');
if (array_key_exists('SyliusGridBundle', $bundles)) {
$loader->load('services/integrations/grid.xml');
Expand All @@ -68,7 +68,7 @@ public function load(array $configs, ContainerBuilder $container): void

$this->autoRegisterResources($config, $container);

$this->loadPersistence($config['drivers'], $config['resources'], $loader);
$this->loadPersistence($config['drivers'], $config['resources'], $loader, $container);
$this->loadResources($config['resources'], $container);

$container->registerForAutoconfiguration(ProviderInterface::class)
Expand Down Expand Up @@ -175,8 +175,20 @@ private function getResourceAlias(ResourceMetadata $resource, string $className)
return 'app.' . u($shortName)->snake()->toString();
}

private function loadPersistence(array $drivers, array $resources, LoaderInterface $loader): void
/**
* @param array<string, array{driver: string|false}> $resources
*/
private function loadPersistence(array $drivers, array $resources, LoaderInterface $loader, ContainerBuilder $container): void
{
$availableDrivers = $this->getAvailableDrivers($container);

// Enable all available drivers if there is no configured drivers
$drivers = [] !== $drivers ? $drivers : $availableDrivers;

$resourceDrivers = $this->getResourceDrivers($resources);

$this->checkConfiguredDrivers($drivers, $availableDrivers, $resourceDrivers);

$integrateDoctrine = array_reduce($drivers, function (bool $result, string $driver): bool {
return $result || in_array($driver, [SyliusResourceBundle::DRIVER_DOCTRINE_ORM, SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM, SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM], true);
}, false);
Expand All @@ -185,20 +197,6 @@ private function loadPersistence(array $drivers, array $resources, LoaderInterfa
$loader->load('services/integrations/doctrine.xml');
}

foreach ($resources as $alias => $resource) {
if (false === $resource['driver']) {
break;
}

if (!in_array($resource['driver'], $drivers, true)) {
throw new InvalidArgumentException(sprintf(
'Resource "%s" uses driver "%s", but this driver has not been enabled.',
$alias,
$resource['driver'],
));
}
}

foreach ($drivers as $driver) {
if (in_array($driver, [SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM, SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM], true)) {
trigger_deprecation(
Expand All @@ -209,10 +207,89 @@ private function loadPersistence(array $drivers, array $resources, LoaderInterfa
);
}

// Only Doctrine drivers need service integration file
if (!str_starts_with($driver, 'doctrine')) {
continue;
}

$loader->load(sprintf('services/integrations/%s.xml', $driver));
}
}

/**
* @param array<string, array{driver: string|false}> $resources
*
* @return array<string, string>
*/
private function getResourceDrivers(array $resources): array
{
$resourceDrivers = array_map(function (array $resource): string|false {
return $resource['driver'] ?? false;
}, $resources);

// Remove resources with disabled driver
return array_filter($resourceDrivers, function (string|false $driver): bool {
return false !== $driver;
});
}

private function getAvailableDrivers(ContainerBuilder $container): array
{
$availableDrivers = [];

if ($container::willBeAvailable(SyliusResourceBundle::DRIVER_DOCTRINE_ORM, \Doctrine\ORM\EntityManagerInterface::class, ['doctrine/doctrine-bundle'])) {
$availableDrivers[] = SyliusResourceBundle::DRIVER_DOCTRINE_ORM;
}

if ($container::willBeAvailable(SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM, \Doctrine\ODM\PHPCR\Document\Resource::class, ['doctrine/doctrine-bundle'])) {

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.3, Symfony ^6.4, Persistence: ^3.0, Collections: ^2.0

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.2, Symfony ^6.4, Persistence: ^3.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.2, Symfony ^6.4, Persistence: ^3.0, Collections: ^2.0

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.3, Symfony ^5.4, Persistence: ^2.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.1, Symfony ^5.4, Persistence: ^3.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.2, Symfony ^5.4, Persistence: ^2.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.3, Symfony ^5.4, Persistence: ^3.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.1, Symfony ^6.4, Persistence: ^3.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.2, Symfony ^5.4, Persistence: ^3.0, Collections: ^2.0

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.3, Symfony ^6.4, Persistence: ^3.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.1, Symfony ^5.4, Persistence: , Collections:

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.1, Symfony ^5.4, Persistence: ^2.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.3, Symfony ^7.0, Persistence: , Collections:

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.1, Symfony ^6.4, Persistence: ^3.0, Collections: ^2.0

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.3, Symfony ^5.4, Persistence: ^3.0, Collections: ^2.0

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.2, Symfony ^5.4, Persistence: ^3.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)

Check failure on line 244 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.1, Symfony ^5.4, Persistence: ^3.0, Collections: ^2.0

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:244:90: UndefinedClass: Class, interface or enum named Doctrine\ODM\PHPCR\Document\Resource does not exist (see https://psalm.dev/019)
$availableDrivers[] = SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM;
}

if ($container::willBeAvailable(SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM, \Doctrine\ODM\MongoDB\DocumentManager::class, ['doctrine/doctrine-bundle'])) {

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.3, Symfony ^6.4, Persistence: ^3.0, Collections: ^2.0

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.2, Symfony ^6.4, Persistence: ^3.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.2, Symfony ^6.4, Persistence: ^3.0, Collections: ^2.0

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.3, Symfony ^5.4, Persistence: ^2.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.1, Symfony ^5.4, Persistence: ^3.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.2, Symfony ^5.4, Persistence: ^2.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.3, Symfony ^5.4, Persistence: ^3.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.1, Symfony ^6.4, Persistence: ^3.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.2, Symfony ^5.4, Persistence: ^3.0, Collections: ^2.0

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.3, Symfony ^6.4, Persistence: ^3.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.1, Symfony ^5.4, Persistence: , Collections:

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.1, Symfony ^5.4, Persistence: ^2.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.3, Symfony ^7.0, Persistence: , Collections:

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.1, Symfony ^6.4, Persistence: ^3.0, Collections: ^2.0

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.3, Symfony ^5.4, Persistence: ^3.0, Collections: ^2.0

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.2, Symfony ^5.4, Persistence: ^3.0, Collections: ^1.8

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)

Check failure on line 248 in src/Bundle/DependencyInjection/SyliusResourceExtension.php

View workflow job for this annotation

GitHub Actions / PHP 8.1, Symfony ^5.4, Persistence: ^3.0, Collections: ^2.0

UndefinedClass

src/Bundle/DependencyInjection/SyliusResourceExtension.php:248:92: UndefinedClass: Class, interface or enum named Doctrine\ODM\MongoDB\DocumentManager does not exist (see https://psalm.dev/019)
$availableDrivers[] = SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM;
}

return $availableDrivers;
}

/**
* @param string[] $configuredDrivers
* @param string[] $availableDrivers
* @param array<string, string> $resourceDrivers
*/
private function checkConfiguredDrivers(array $configuredDrivers, array $availableDrivers, array $resourceDrivers): void
{
foreach ($configuredDrivers as $driver) {
if (!in_array($driver, $availableDrivers, true)) {
throw new InvalidArgumentException(sprintf(
'Driver "%s" is configured, but this driver is not available. Try running "composer require %s"',
$driver,
$driver,
));
}
}

foreach ($resourceDrivers as $resource => $driver) {
if (!in_array($driver, $availableDrivers, true)) {
throw new InvalidArgumentException(sprintf(
'Resource "%s" uses drivers "%s", but this driver is not available. Try running "composer require %s"',
$resource,
$driver,
$driver,
));
}

if (!in_array($driver, $configuredDrivers, true)) {
throw new InvalidArgumentException(sprintf(
'Resource "%s" uses drivers "%s", but this driver is not enabled. Try adding "%s" in sylius_resource.drivers option',
$resource,
$driver,
$driver,
));
}
}
}

private function loadResources(array $loadedResources, ContainerBuilder $container): void
{
/** @var array<string, array> $resources */
Expand Down
18 changes: 18 additions & 0 deletions tests/Application/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions tests/Application/config/packages/test/doctrine.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
doctrine:
dbal:
driver: "%database_driver%"
path: "%database_path%"
charset: UTF8
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
BoardGameBlog:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/BoardGameBlog/Domain'
prefix: 'App\BoardGameBlog\Domain'
Subscription:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/Subscription/Entity'
prefix: 'App\Subscription\Entity'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sylius_resource:
drivers: []
95 changes: 95 additions & 0 deletions tests/Application/config/services_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
parameters:
database_driver: pdo_sqlite
database_path: "%kernel.project_dir%/config/db.sql"

locale: en_US
secret: "Three can keep a secret, if two of them are dead."

services:
# Gets rid of "[error] Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException"
# errors in PHPUnit output when testing 404 errors.
Psr\Log\NullLogger: ~
logger: '@Psr\Log\NullLogger'

# Default configuration for services in *this* file
_defaults:
# Automatically injects dependencies in your services
autowire: true

# Automatically registers your services as commands, event subscribers, etc.
autoconfigure: true

# Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work
public: false

# Controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']

test.translation_locale_provider:
class: Sylius\Component\Resource\Translation\Provider\ImmutableTranslationLocaleProvider
arguments:
- ["pl_PL", "en_US", "de_DE"]
- "en_US"

test.custom_book_factory:
class: App\Factory\CustomBookFactory
public: true
arguments:
- "%app.model.book.class%"
- "@test.translation_locale_provider"

test.custom_book_repository:
class: App\Repository\CustomBookRepository
public: true
arguments:
- "@app.repository.book"

app.form.type.book:
class: App\Form\Type\BookType
arguments:
- '%app.model.book.class%'
tags: ['form.type']

app.form.type.science_book:
class: App\Form\Type\ScienceBookType
arguments:
- '%app.model.science_book.class%'
- ['sylius']
tags: [ 'form.type' ]

app.form.type.book_translation:
class: App\Form\Type\BookTranslationType
arguments:
- '%app.model.book_translation.class%'
tags: ['form.type']

App\Repository\ComicBookRepository: null
App\Repository\LegacyBookRepository: null

App\Shared\:
resource: '../src/Shared'

App\BoardGameBlog\:
resource: '../src/BoardGameBlog'

App\Subscription\:
resource: '../src/Subscription'

App\Subscription\Factory\SubscriptionFactory:
decorates: 'app.factory.subscription'

app.service.legacy_autowired_repository:
class: App\Service\LegacyAutowiredRepositoryService
autowire: true

app.service.legacy_autowired_factory:
class: App\Service\LegacyAutowiredFactoryService
autowire: true

app.service.legacy_autowired_translatable_factory:
class: App\Service\LegacyAutowiredTranslatableFactoryService
autowire: true
Loading

0 comments on commit f490265

Please sign in to comment.