[go: nahoru, domu]

Skip to content

Commit

Permalink
Add DoctrineBundle to the dependencies (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas authored and theofidry committed Sep 19, 2018
1 parent 9383c75 commit df7acdc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ With [Symfony Flex](https://symfony.com/doc/current/setup/flex.html) (recommende
# If you do not have Doctrine installed yet:
composer require doctrine-orm
composer require --dev hautelook/alice-bundle doctrine/data-fixtures
composer require --dev hautelook/alice-bundle
```

Without Flex you will have to install `doctrine/orm` and register the bundles accordingly in `app/AppKernel.php` or
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@

"require": {
"php": "^7.1",
"doctrine/doctrine-bundle": "^1.8",
"doctrine/data-fixtures": "^1.2",
"doctrine/orm": "^2.5.11",
"psr/log": "^1.0",
"symfony/finder": "^3.4 || ^4.0",
"theofidry/alice-data-fixtures": "^1.0",
"symfony/framework-bundle": "^3.4 || ^4.0"
"symfony/framework-bundle": "^3.4 || ^4.0",
"theofidry/alice-data-fixtures": "^1.0"
},
"require-dev": {
"doctrine/data-fixtures": "^1.2",
"doctrine/doctrine-bundle": "^1.8",
"doctrine/orm": "^2.5.6",
"doctrine/persistence": "^1.0",
"phpunit/phpunit": "^7.0",
"phpspec/prophecy": "^1.7",
Expand Down
34 changes: 14 additions & 20 deletions src/DependencyInjection/HautelookAliceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@

use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle;
use Hautelook\AliceBundle\Console\Command\Doctrine\DoctrineOrmMissingBundleInformationCommand;
use Hautelook\AliceBundle\HautelookAliceBundle;
use LogicException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
Expand All @@ -28,6 +26,7 @@
*
* @author Baldur Rensch <brensch@gmail.com>
* @author Théo FIDRY <theo.fidry@gmail.com>
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class HautelookAliceExtension extends Extension
{
Expand All @@ -38,29 +37,24 @@ final class HautelookAliceExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
$bundles = array_flip($container->getParameter('kernel.bundles'));
$missingBundles = [DoctrineBundle::class => true, FidryAliceDataFixturesBundle::class => true];
foreach ($container->getParameter('kernel.bundles') as $bundle) {
unset($missingBundles[$bundle]);
if (!$missingBundles) {
break;
}
}

if (false === array_key_exists(FidryAliceDataFixturesBundle::class, $bundles)) {
throw new LogicException(
sprintf(
'Cannot register "%s" without "%s".',
HautelookAliceBundle::class,
FidryAliceDataFixturesBundle::class
)
);
if ($missingBundles) {
throw new LogicException(sprintf(
'To register "%s", you also need: "%s".',
HautelookAliceBundle::class,
implode('", "', array_keys($missingBundles))
));
}

$this->loadConfig($configs, $container);
$this->loadServices($container);

if (false === array_key_exists(DoctrineBundle::class, $bundles)) {
$container->removeDefinition('hautelook_alice.console.command.doctrine.doctrine_orm_load_data_fixtures_command');

$definition = new Definition(DoctrineOrmMissingBundleInformationCommand::class);
$definition->addTag('console.command');
$definition->setPublic(true);
$container->setDefinition('hautelook_alice.console.command.doctrine.doctrine_orm_bundle_missing_command', $definition);
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/DependencyInjection/HautelookAliceBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function tearDown()

/**
* @expectedException \LogicException
* @expectedExceptionMessage Cannot register "Hautelook\AliceBundle\HautelookAliceBundle" without "Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle".
* @expectedExceptionMessage To register "Hautelook\AliceBundle\HautelookAliceBundle", you also need: "Doctrine\Bundle\DoctrineBundle\DoctrineBundle", "Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle".
*/
public function testCannotBootIfFidryAliceDataFixturesBundleIsNotRegistered()
{
Expand All @@ -52,8 +52,8 @@ public function testCannotBootIfFidryAliceDataFixturesBundleIsNotRegistered()
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
* @expectedExceptionMessageRegExp /non-existent service/
* @expectedException \LogicException
* @expectedExceptionMessage To register "Hautelook\AliceBundle\HautelookAliceBundle", you also need: "Doctrine\Bundle\DoctrineBundle\DoctrineBundle".
*/
public function testWillReplaceFixtureLoadCommandWithErrorInformationCommandIfDoctrineBundleIsNotRegistered()
{
Expand Down

0 comments on commit df7acdc

Please sign in to comment.