/** * Load Map builders. * * @param string $connectionName A connection name. */ protected function loadMapBuilders($connectionName = null) { if (null !== $this->dbMap) { return; } $this->dbMap = Propel::getDatabaseMap($connectionName); $finder = new Finder(); $files = $finder->files()->name('*TableMap.php')->in($this->getRootDir() . '/../'); foreach ($files as $file) { $class = $this->guessFullClassName($file->getRelativePath(), basename($file, '.php')); if (null !== $class) { $this->dbMap->addTableFromMapClass($class); } } }
/** * Clears and repopulates the DatabaseMap with new TableMap classes * * @param type $name * @param type $tableMapClassNames */ protected function resetDatabaseMap($name, array $tableMapClassNames) { $dbMap = new DatabaseMap($name); foreach ($tableMapClassNames as $tableMapClassName) { $dbMap->addTableFromMapClass($tableMapClassName); } Propel::setDatabaseMap($name, $dbMap); }
/** * Load Map builders. * * @param string $connectionName A connection name. */ protected function loadMapBuilders($connectionName = null) { if (null !== $this->dbMap) { return; } $this->dbMap = Propel::getDatabaseMap($connectionName); if (0 === count($this->dbMap->getTables())) { $finder = new Finder(); $files = $finder->files()->name('*TableMap.php')->in($this->getModelSearchPaths($connectionName))->exclude('PropelBundle')->exclude('Tests'); foreach ($files as $file) { $class = $this->guessFullClassName($file->getRelativePath(), basename($file, '.php')); if (null !== $class && $this->isInDatabase($class, $connectionName)) { $this->dbMap->addTableFromMapClass($class); } } } }
public function testWipesExistingData() { $author = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor(); $author->setName('Some famous author'); $book = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\Book(); $book->setName('Armageddon is near')->setBookAuthor($author)->save($this->con); $savedBook = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelectOne(new \Criteria(), $this->con); $this->assertInstanceOf('Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\Book', $savedBook, 'The fixture has been saved correctly.'); $builder = $this->getMockBuilder('Propel\\PropelBundle\\DataFixtures\\Loader\\DataWiper'); $wipeout = $builder->setMethods(array('loadMapBuilders'))->disableOriginalConstructor()->getMock(); $dbMap = new \DatabaseMap('default'); $dbMap->addTableFromMapClass('Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\map\\BookTableMap'); $reflection = new \ReflectionObject($wipeout); $property = $reflection->getProperty('dbMap'); $property->setAccessible(true); $property->setValue($wipeout, $dbMap); $wipeout->expects($this->once())->method('loadMapBuilders'); $wipeout->load(array(), 'default'); $this->assertCount(0, \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con)); }