0

Im running my own project with Symfony 3.3.*, trying to install DoctrineFixturesBundle.

This is my fixture loader.

namespace AdminBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use AdminBundle\Entity\Group;

/**
 * Loading groups before running system from DoctrineFixtures.
 *
 * @author oadamczyk
 */
class LoadGroupsData implements FixtureInterface, ContainerAwareInterface
{

    /**
     *
     * @var ContainerInterface
     */
    private $container;

    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    public function load(ObjectManager $manager)
    {
        foreach (explode('|', $this->container->getParameter('env(ROLES_PIPE_SEPERATED)')) as $role) {
            /** @var Group */
            $group = new Group(ucfirst(str_replace('ADMIN_', '', $role)), $role);
            $manager->persist($group);
        }
        $manager->flush();
    }

}

This is my AppKernel:

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{

    public function registerBundles()
    {
        $bundles = [
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new Sonata\CoreBundle\SonataCoreBundle(),
            new Sonata\BlockBundle\SonataBlockBundle(),
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),
            new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
            new Sonata\AdminBundle\SonataAdminBundle(),
            new FOS\UserBundle\FOSUserBundle(),
//            new AppBundle\AppBundle(),
            new AdminBundle\AdminBundle(),
            new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle()
        ];

        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();

            if ('dev' === $this->getEnvironment()) {
                $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
                $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
            }
        }

        return $bundles;
    }

    public function getRootDir()
    {
        return __DIR__;
    }

    public function getCacheDir()
    {
        return dirname(__DIR__) . '/var/cache/' . $this->getEnvironment();
    }

    public function getLogDir()
    {
        return dirname(__DIR__) . '/var/logs';
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load($this->getRootDir() . '/config/config_' . $this->getEnvironment() . '.yml');
    }

}

This is exception that php bin/console doctrine:fixtures:load logs:

Careful, database will be purged. Do you want to continue y/N ?y

 [InvalidArgumentException]                                                   
 Could not find any fixtures to load in:                                      
  - /var/www/html/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/D  
  ataFixtures/ORM                                                              
  - /var/www/html/vendor/symfony/symfony/src/Symfony/Bundle/SecurityBundle/Da  
  taFixtures/ORM                                                               
  - /var/www/html/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/DataFi  
  xtures/ORM                                                                   
  - /var/www/html/vendor/symfony/monolog-bundle/DataFixtures/ORM               
  - /var/www/html/vendor/symfony/swiftmailer-bundle/DataFixtures/ORM           
  - /var/www/html/vendor/doctrine/doctrine-bundle/DataFixtures/ORM             
  - /var/www/html/vendor/sensio/framework-extra-bundle/DataFixtures/ORM        
  - /var/www/html/vendor/sonata-project/core-bundle/DataFixtures/ORM           
  - /var/www/html/vendor/sonata-project/block-bundle/DataFixtures/ORM          
  - /var/www/html/vendor/knplabs/knp-menu-bundle/DataFixtures/ORM              
  - /var/www/html/vendor/sonata-project/doctrine-orm-admin-bundle/DataFixture  
  s/ORM                                                                        
  - /var/www/html/vendor/sonata-project/admin-bundle/DataFixtures/ORM          
  - /var/www/html/vendor/friendsofsymfony/user-bundle/DataFixtures/ORM         
  - /var/www/html/src/AdminBundle/DataFixtures/ORM                             
  - /var/www/html/vendor/doctrine/doctrine-fixtures-bundle/DataFixtures/ORM    
  - /var/www/html/vendor/symfony/symfony/src/Symfony/Bundle/DebugBundle/DataF  
  ixtures/ORM                                                                  
  - /var/www/html/vendor/symfony/symfony/src/Symfony/Bundle/WebProfilerBundle  
  /DataFixtures/ORM                                                            
  - /var/www/html/vendor/sensio/distribution-bundle/DataFixtures/ORM           
  - /var/www/html/vendor/sensio/generator-bundle/DataFixtures/ORM              
  - /var/www/html/vendor/symfony/symfony/src/Symfony/Bundle/WebServerBundle/D  
  ataFixtures/ORM                                                              


doctrine:fixtures:load [--fixtures [FIXTURES]] [--append] [--em EM] [--shard SHARD] [--purge-with-truncate] [--multiple-transactions] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>

I'm using SonataAdminBundle but I highly doubt that this is a reason

kero
  • 10,647
  • 5
  • 41
  • 51
oadamczyk
  • 1
  • 1

1 Answers1

0

Hi if you are still looking for the answer here it is, I just figured out that the author have changed the implementation for version 3+. I was also facing same problem.

<?php
namespace AdminBundle\DataFixtures\ORM;

use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use AdminBundle\Entity\Group;

/**
 * Loading groups before running system from DoctrineFixtures.
 *
 * @author oadamczyk
 */
class LoadGroupsData extends Fixture
{

    /**
     *
     * @var ContainerInterface
     */
    private $container;

    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    public function load(ObjectManager $manager)
    {
        foreach (explode('|', $this->container->getParameter('env(ROLES_PIPE_SEPERATED)')) as $role) {
            /** @var Group */
            $group = new Group(ucfirst(str_replace('ADMIN_', '', $role)), $role);
            $manager->persist($group);
        }
        $manager->flush();
    }

}
Moeen Basra
  • 733
  • 4
  • 18