buildSchemaSeeds() public method

public buildSchemaSeeds ( SchemaBase $schema )
$schema LazyRecord\Schema\SchemaBase
Esempio n. 1
0
 public function setUp()
 {
     $annnotations = $this->getAnnotations();
     $configLoader = ConfigLoader::getInstance();
     $configLoader->loadFromSymbol(true);
     $configLoader->setDefaultDataSourceId($this->getDriverType());
     $connManager = ConnectionManager::getInstance();
     $connManager->init($configLoader);
     try {
         $dbh = $connManager->getConnection($this->getDriverType());
     } catch (PDOException $e) {
         if ($this->allowConnectionFailure) {
             $this->markTestSkipped(sprintf("Can not connect to database by data source '%s' message:'%s' config:'%s'", $this->getDriverType(), $e->getMessage(), var_export($configLoader->getDataSource($this->getDriverType()), true)));
             return;
         } else {
             echo sprintf("Can not connect to database by data source '%s' message:'%s' config:'%s'", $this->getDriverType(), $e->getMessage(), var_export($configLoader->getDataSource($this->getDriverType()), true));
             throw $e;
         }
     }
     $driver = $connManager->getQueryDriver($this->getDriverType());
     $this->assertInstanceOf('SQLBuilder\\Driver\\BaseDriver', $driver, 'QueryDriver object OK');
     // Rebuild means rebuild the database for new tests
     $rebuild = true;
     $basedata = true;
     if (isset($annnotations['method']['rebuild'][0]) && $annnotations['method']['rebuild'][0] == 'false') {
         $rebuild = false;
     }
     if (isset($annnotations['method']['basedata'][0]) && $annnotations['method']['basedata'][0] == 'false') {
         $basedata = false;
     }
     if ($rebuild) {
         $builder = SqlBuilder::create($driver, array('rebuild' => true));
         $this->assertNotNull($builder);
         // $schemas = ClassUtils::schema_classes_to_objects($this->getModels());
         $schemas = ClassUtils::schema_classes_to_objects($this->getModels());
         foreach ($schemas as $schema) {
             $sqls = $builder->build($schema);
             $this->assertNotEmpty($sqls);
             foreach ($sqls as $sql) {
                 $dbh->query($sql);
             }
         }
         if ($basedata) {
             $runner = new SeedBuilder($this->config, $this->logger);
             foreach ($schemas as $schema) {
                 $runner->buildSchemaSeeds($schema);
             }
             if ($scripts = $this->config->getSeedScripts()) {
                 foreach ($scripts as $script) {
                     $runner->buildScriptSeed($script);
                 }
             }
         }
     }
 }
Esempio n. 2
0
 public function setUp()
 {
     $annnotations = $this->getAnnotations();
     $connManager = ConnectionManager::getInstance();
     $dataSourceConfig = self::createDataSourceConfig($this->driver);
     if ($dataSourceConfig) {
         $connManager->addDataSource('default', $dataSourceConfig);
     } else {
         $this->markTestSkipped("{$this->driver} database configuration is missing.");
     }
     try {
         $dbh = $connManager->getConnection('default');
     } catch (PDOException $e) {
         $this->markTestSkipped('Can not connect to database, test skipped: ' . $e->getMessage());
         return;
     }
     $driver = ConnectionManager::getInstance()->getQueryDriver('default');
     ok($driver, 'QueryDriver object OK');
     // Rebuild means rebuild the database for new tests
     $rebuild = true;
     $basedata = true;
     if (isset($annnotations['method']['rebuild'][0]) && $annnotations['method']['rebuild'][0] == 'false') {
         $rebuild = false;
     }
     if (isset($annnotations['method']['basedata'][0]) && $annnotations['method']['basedata'][0] == 'false') {
         $basedata = false;
     }
     if ($rebuild) {
         $builder = SqlBuilder::create($driver, array('rebuild' => true));
         $this->assertNotNull($builder);
         // $schemas = ClassUtils::schema_classes_to_objects($this->getModels());
         $schemas = ClassUtils::schema_classes_to_objects($this->getModels());
         foreach ($schemas as $schema) {
             $sqls = $builder->build($schema);
             $this->assertNotEmpty($sqls);
             foreach ($sqls as $sql) {
                 $dbh->query($sql);
             }
         }
         if ($basedata) {
             $runner = new SeedBuilder($this->config, $this->logger);
             foreach ($schemas as $schema) {
                 $runner->buildSchemaSeeds($schema);
             }
             if ($scripts = $this->config->getSeedScripts()) {
                 foreach ($scripts as $script) {
                     $runner->buildScriptSeed($script);
                 }
             }
         }
     }
 }