Exemplo n.º 1
0
 public function testValidateReturnsFalseWhenTwoTablesHaveSamePhpName()
 {
     $table1 = new Table('foo');
     $table2 = new Table('bar');
     $table2->setPhpName('Foo');
     $database = new Database();
     $database->addTable($table1);
     $database->addTable($table2);
     $appData = new AppData();
     $appData->addDatabase($database);
     $validator = new SchemaValidator($appData);
     $this->assertFalse($validator->validate());
     $this->assertContains('Table "bar" declares a phpName already used in another table', $validator->getErrors());
 }
Exemplo n.º 2
0
    public function testAppendXmlNamespaceWithAutoPackage()
    {
        $schema = <<<EOF
<?xml version="1.0"?>
<table name="test" namespace="\\testNs"/>
EOF;
        $doc = new DOMDocument('1.0');
        $doc->formatOutput = true;
        $config = new GeneratorConfig();
        $config->setBuildProperties(array('propel.namespace.autoPackage' => 'true'));
        $appData = new AppData();
        $appData->setGeneratorConfig($config);
        $db = new Database('testDb');
        $db->setAppData($appData);
        $table = new Table('test');
        $table->setDatabase($db);
        $table->setNamespace('\\testNs');
        $table->appendXml($doc);
        $xmlstr = trim($doc->saveXML());
        $this->assertSame($schema, $xmlstr);
        $schema = <<<EOF
<?xml version="1.0"?>
<table name="test" namespace="\\testNs" package="testPkg"/>
EOF;
        $doc = new DOMDocument('1.0');
        $doc->formatOutput = true;
        $table->setPackage('testPkg');
        $table->appendXml($doc);
        $xmlstr = trim($doc->saveXML());
        $this->assertSame($schema, $xmlstr);
    }
Exemplo n.º 3
0
 /** Sets up the Propel model. */
 public function setUp()
 {
     $appData = new AppData(new MysqlPlatform());
     $this->database = new Database();
     $appData->addDatabase($this->database);
 }
Exemplo n.º 4
0
 /**
  * Packages the datamodels to one datamodel per package
  *
  * This applies only when the the packageObjectModel option is set. We need to
  * re-package the datamodels to allow the database package attribute to control
  * which tables go into which SQL file.
  *
  * @return     array The packaged datamodels
  */
 protected function packageDataModels()
 {
     static $packagedDataModels;
     if (is_null($packagedDataModels)) {
         $dataModels = $this->getDataModels();
         $dataModel = array_shift($dataModels);
         $packagedDataModels = array();
         $platform = $this->getGeneratorConfig()->getConfiguredPlatform();
         foreach ($dataModel->getDatabases() as $db) {
             foreach ($db->getTables() as $table) {
                 $package = $table->getPackage();
                 if (!isset($packagedDataModels[$package])) {
                     $dbClone = $this->cloneDatabase($db);
                     $dbClone->setPackage($package);
                     $ad = new AppData($platform);
                     $ad->setGeneratorConfig($this->getGeneratorConfig());
                     $ad->setName($dataModel->getName());
                     $ad->addDatabase($dbClone);
                     $packagedDataModels[$package] = $ad;
                 }
                 $packagedDataModels[$package]->getDatabase($db->getName())->addTable($table);
             }
         }
     }
     return $packagedDataModels;
 }