In Symfony2 to the class path of the namespace?

In fact, the essence of the question in the title. How you can crank out this action ?
wrote the class in the tests that I builds the database schema and loads the fixture , pre-clearing the database. The fixtures are located in different Bindlach. So from each bundle not to write the way hands, want to pull the path from the Namespace, as doctrine, to load fixtures, you need the full path to the folder or to the class. I need to the class.
September 19th 19 at 13:20
2 answers
September 19th 19 at 13:22
Here class loading strategies. Can someone come in handy.

namespace Retouch\AppBundle\Tests;

use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\DependencyInjection\Container;

 * Class FixturesLoader
class FixturesLoader
 * @var Application
 protected $console;

 * @var Container
 protected $container;

 * @param Container $container
 public function __construct(Container $container)
 $this--->container = $container;
 $this->console = new Application($this->container->get('kernel'));

 * @param array $fixtures
 public function loadFixture(array $fixtures = array())
 $this->runConsole('doctrine:schema:drop --force');

 $loader = new ContainerAwareLoader($this->container);

 foreach($fixtures as $fixture){
 if($fixture instanceof FixtureInterface){

 $fixtures = $loader->getFixtures();


 $doctrine = $this->container->get('doctrine');
 $em = $doctrine->getManager();

 $purger = new ORMPurger($em);


 $executor = new ORMExecutor($em, $purger);
 $executor->execute($fixtures, false);


 * @param $command
 * @return int
 * @throws \Exception
 protected function runConsole($command)
 $command .= '--env=test --quiet';

 $input = new StringInput($command);

 return $this->console->run($input);
And what did not come? - Darlene.Muraz commented on September 19th 19 at 13:25
: Well, how would use in my class says that it (FixtureBundle) I used. But there is a wad of fixtures is loaded from the directory, and in this class I fit your needs, for testing did, in any order, separate fixtures download. - viva commented on September 19th 19 at 13:28
would not like says. I can only see using the library - Darlene.Muraz commented on September 19th 19 at 13:31
: Yeah, and on the basis of what works bundle DoctrineFixture as not data-fixtures ? FixturesBundle is just a team, by the way, the code of which the code is written above, are almost identical. Do not be lazy and look at the source code. - viva commented on September 19th 19 at 13:34
I told you about Thomas you tell me about Eremu... - Darlene.Muraz commented on September 19th 19 at 13:37
September 19th 19 at 13:24
I still do not understand, but apparently it is necessary to look into the kernel->getBundles() + bundle->getPath()
Maybe you know how to test the database. Test for record creation, update, fetch, delete. I'm just no other way found yet. - Darlene.Muraz commented on September 19th 19 at 13:27
I'm not saying that you are doing something wrong, just it would be easier to understand that you need a piece of code than to abstract example/description - viva commented on September 19th 19 at 13:30
: no, I have no hints, just really seems like something difficult to do it. Good head realized to get into command code load fixtures. As a remake, I will lay out the code, can someone come in handy. - Darlene.Muraz commented on September 19th 19 at 13:33

Find more questions by tags SymfonyPHP