/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { $dburl = $input->getArgument('dburl'); $filename = $input->getArgument('filename'); $autoUuidField = $input->getArgument('autouuidfield'); $locale = $input->getOption('locale'); $seed = $input->getOption('seed'); if (!file_exists($filename)) { throw new FileNotFoundException($filename); } $manager = new DatabaseManager(); $pdo = $manager->getPdo($dburl, 'default'); $providers = array(); $loader = new AliceLoader($locale, $providers, $seed); $instantiator = new TableRecordInstantiator(); if ($autoUuidField) { $instantiator->setAutoUuidColumn($autoUuidField); } $loader->addInstantiator($instantiator); $output->writeln(sprintf("Loading '%s' into %s", $filename, $dburl)); $objects = $loader->load($filename); $output->writeln(sprintf("Persisting '%s' objects in database '%s'", count($objects), $dburl)); $persister = new PdoPersister($pdo, $output, $input->getOption('dry-run')); if (!is_null($input->getOption('append'))) { $persister->reset($objects); } $persister->persist($objects); $output->writeln("Done"); }
public function testParametersSetOnTheLoader() { $loader = new Loader(); $parser = new Yaml($loader); $parser->parse(__DIR__ . '/../../../support/fixtures/include.yml'); $this->assertEquals('ebay.us', $loader->getParameterBag()->get('ebay_domain_name')); }
/** * @param string $path * @return object[] */ private function loadFromFile($path) { $entities = $this->aliceLoader->load($path); foreach ($entities as $entity) { $this->entityManager->persist($entity); } return $entities; }
/** * Load data fixtures with the passed EntityManager * * @param ObjectManager $om */ public function load(ObjectManager $om) { // auto save to db example // $members = Fixtures::load(__DIR__.'/members.yml', $om); $loader = new Loader(); $members = $loader->load(__DIR__ . '/members.yml'); $manager = $this->container->get('member.manager'); foreach ($members as $member) { $manager->updateMember($member, false); } $persister = new Doctrine($om); $persister->persist($members); }
/** * Loads a fixture file. * * @param string|array $dataOrFilename May either be the path to the file in which case it will be parsed, or be * an array of data (then skips the parsing). The format of the array of data * depends of the builders used. * @param array $references Array where the key is the object name and the value the actual object * class. The references are used to inject objects which the loader should be * aware of while loading the file. * * @return array|\object[] */ public function load($dataOrFilename, array $references = []) { $this->setReferences($references); $objects = parent::load($dataOrFilename); $this->setReferences([]); return $objects; }
/** * @param string $source * * @return array */ protected function loadFixturesFromFile($source) { $source = $this->getFixtureRealPath($source); $this->assertSourceExists($source); $objects = $this->fixtureLoader->load($source); $this->persistObjects($objects); $this->entityManager->flush(); return $objects; }
public function testYamlArrayParametersAreProperlyInterpreted() { $res = $this->createLoader()->load(__DIR__ . '/../support/fixtures/array_parameters.yml'); $this->assertCount(5, $res); foreach ($this->loader->getReferences() as $user) { $this->assertInstanceOf(self::USER, $user); $this->assertContains($user->username, ['Alice', 'Bob', 'Ogi']); } }
/** * {@inheritdoc} */ protected function instantiateFixtures(array $fixtures) { parent::instantiateFixtures($fixtures); foreach ($fixtures as $fixture) { $spec = array_map(function ($property) { return $property->getValue(); }, $fixture->getProperties()); $this->cache[$fixture->getName()] = [$spec, $this->objects->get($fixture->getName())]; } }
public function testBackslashes() { $loader = new Loader(); $res = $loader->load(__DIR__ . '/../support/fixtures/backslashes.yml'); $this->assertEquals('\\\\', $res['user0']->username); $this->assertEquals([$res['foo'], '@foo', '\\@foo', '\\\\@foo'], $res['user0']->friends); }
public function testCallFakerFromFakerCall() { $loader = new Loader('en_US', array(new FakerProvider())); $res = $loader->load(__DIR__ . '/../support/fixtures/nested_faker.php'); foreach (array('user1', 'user2') as $userKey) { $user = $res[$userKey]; $this->assertInstanceOf(self::USER, $user, $userKey . ' should match'); $this->assertEquals('JOHN DOE', $user->username, $userKey . ' should match'); $this->assertEquals('JOHN DOE', $user->fullname, $userKey . ' should match'); } }
public function testCurrentInConstructor() { $res = $this->loadData(array(self::USER => array('user1' => array('__construct' => array('alice', '*****@*****.**')), 'user2' => array('__construct' => array('bob', '*****@*****.**'))), self::CONTACT => array('contact{1..2}' => array('__construct' => array('@user<current()>'))))); $this->assertSame($this->loader->getReference('user1'), $this->loader->getReference('contact1')->getUser()); $this->assertSame($this->loader->getReference('user2'), $this->loader->getReference('contact2')->getUser()); }
/** * Sets all needed options and dependencies to a loader. * * @param Loader $loader */ protected function configureLoader(Loader $loader) { if ($loader instanceof Loader) { $loader->setPersister($this->getORM()); if ($this->logger) { $loader->setLogger($this->logger); } } if (is_callable(array($loader, 'addProvider'))) { // new in Alice 1.7.2 $loader->addProvider($this->providers); } else { // BC path $loader->setProviders($this->providers); } }
public function load($data) { $this->persist(parent::load($data)); }
public function testAtLiteral() { $loader = new Loader('en_US', array(new FakerProvider())); $res = $loader->load(array(self::USER => array('user' => array('__construct' => array('\\@<fooGenerator()> \\\\@foo \\\\\\@foo \\foo'))))); $this->assertInstanceOf(self::USER, $res['user']); $this->assertSame('@foo \\@foo \\@foo \\foo', $res['user']->username); }