Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional fixtures #8377

Merged
merged 9 commits into from Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/bundles/LeadBundle/Config/config.php
Expand Up @@ -1193,11 +1193,13 @@
'mautic.lead.fixture.test.page_hit' => [
'class' => \Mautic\LeadBundle\Tests\DataFixtures\ORM\LoadPageHitData::class,
'tag' => \Doctrine\Bundle\FixturesBundle\DependencyInjection\CompilerPass\FixturesCompilerPass::FIXTURE_TAG,
'optional' => true,
],
'mautic.lead.fixture.test.segment' => [
'class' => \Mautic\LeadBundle\Tests\DataFixtures\ORM\LoadSegmentsData::class,
'tag' => \Doctrine\Bundle\FixturesBundle\DependencyInjection\CompilerPass\FixturesCompilerPass::FIXTURE_TAG,
'arguments' => ['mautic.lead.model.list', 'mautic.lead.model.lead'],
'optional' => true,
],
],
],
Expand Down
18 changes: 18 additions & 0 deletions app/config/config.php
Expand Up @@ -27,6 +27,24 @@
// Check for a single config file
$config = (file_exists($directory.'/Config/config.php')) ? include $directory.'/Config/config.php' : [];

// Remove optional services (has argument optional = true) if the service class does not exist
if (isset($config['services'])) {
$config['services'] = (new \Tightenco\Collect\Support\Collection($config['services']))
->mapWithKeys(function (array $serviceGroup, string $groupName) {
$serviceGroup = (new \Tightenco\Collect\Support\Collection($serviceGroup))
->reject(function ($serviceDefinition) {
// Rejects services defined as optional where the service class does not exist.
return is_array($serviceDefinition)
&& isset($serviceDefinition['optional'])
&& true === $serviceDefinition['optional']
&& isset($serviceDefinition['class'])
&& false === class_exists($serviceDefinition['class']);
})->toArray();

return [$groupName => $serviceGroup];
})->toArray();
}

// Services need to have percent signs escaped to prevent ParameterCircularReferenceException
if (isset($config['services'])) {
array_walk_recursive(
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -107,7 +107,8 @@
"knplabs/knp-menu-bundle": "^2.0",
"guzzlehttp/oauth-subscriber": "^0.3.0",
"helios-ag/fm-elfinder-bundle": "~9",
"ricardofiorani/guzzle-psr18-adapter": "^1.0"
"ricardofiorani/guzzle-psr18-adapter": "^1.0",
"tightenco/collect": "^6.13"
},
"require-dev": {
"symfony/web-profiler-bundle": "~3.4.0",
Expand Down
245 changes: 175 additions & 70 deletions composer.lock

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

1 change: 1 addition & 0 deletions plugins/MauticCitrixBundle/Config/config.php
Expand Up @@ -119,6 +119,7 @@
'class' => MauticPlugin\MauticCitrixBundle\Tests\DataFixtures\ORM\LoadCitrixData::class,
'tag' => \Doctrine\Bundle\FixturesBundle\DependencyInjection\CompilerPass\FixturesCompilerPass::FIXTURE_TAG,
'arguments' => ['doctrine.orm.entity_manager'],
'optional' => true,
],
],
'integrations' => [
Expand Down