public function testTest()
    {
        $yml = <<<END
---
detect_relations: true
Ticket_1118_User:
  columns:
    username: string(255)
    password: string(255)
    ticket__1118__profile_id: string

Ticket_1118_Profile:
  columns:
    id:
      type: integer(4)
      autoincrement: true
      primary: true
    name: string(255)
END;
        try {
            file_put_contents('test.yml', $yml);
            $import = new Doctrine_Import_Schema();
            $array = $import->buildSchema('test.yml', 'yml');
            // Test that ticket__1118__profile_id is changed to to be integer(4) since the primary key of
            // the relationship is set to that
            $this->assertEqual($array['Ticket_1118_User']['columns']['ticket__1118__profile_id']['type'], 'integer');
            $this->assertEqual($array['Ticket_1118_User']['columns']['ticket__1118__profile_id']['length'], '4');
            $this->pass();
        } catch (Exception $e) {
            $this->fail();
        }
        unlink('test.yml');
    }
    public function testTest()
    {
        $yml = <<<END
---
Ticket_1527_User:
  columns:
    username:
      type: string(255)
      extra:
        test: 123
    password:
      type: string(255)
END;

        $import = new Doctrine_Import_Schema();
        $schema = $import->buildSchema($yml, 'yml');
        $this->assertEqual($schema['Ticket_1527_User']['columns']['username']['extra']['test'], '123');

        $path = dirname(__FILE__) . '/../tmp';
        $import->importSchema($yml, 'yml', $path);
        
        require_once($path . '/generated/BaseTicket_1527_User.php');
        require_once($path . '/Ticket_1527_User.php');
        $username = Doctrine::getTable('Ticket_1527_User')->getDefinitionOf('username');
        $this->assertEqual($username['extra']['test'], '123');
    }
示例#3
0
 public function testBuildSchema()
 {
     $schema = new Doctrine_Import_Schema();
     $array = $schema->buildSchema('schema.yml', 'yml');
     $model = $array['SchemaTestUser'];
     $this->assertTrue(array_key_exists('connection', $model));
     $this->assertTrue(array_key_exists('className', $model));
     $this->assertTrue(array_key_exists('tableName', $model));
     $this->assertTrue(array_key_exists('columns', $model) && is_array($model['columns']));
     $this->assertTrue(array_key_exists('relations', $model) && is_array($model['relations']));
     $this->assertTrue(array_key_exists('indexes', $model) && is_array($model['indexes']));
     $this->assertTrue(array_key_exists('attributes', $model) && is_array($model['attributes']));
     $this->assertTrue(array_key_exists('templates', $model) && is_array($model['columns']));
     $this->assertTrue(array_key_exists('actAs', $model) && is_array($model['actAs']));
     $this->assertTrue(array_key_exists('options', $model) && is_array($model['options']));
     $this->assertTrue(array_key_exists('package', $model));
     $this->assertTrue(array_key_exists('inheritance', $model) && is_array($model['inheritance']));
     $this->assertTrue(array_key_exists('detect_relations', $model) && is_bool($model['detect_relations']));
     $this->assertEqual($array['AliasTest']['columns']['test_col']['name'], 'test_col as test_col_alias');
 }
示例#4
0
 public function testBuildSchema()
 {
     $import = new Doctrine_Import_Schema();
     $array = $import->buildSchema('Ticket/1617_schema.yml', 'yml');
     $this->assertEqual($array['term']['columns']['language']['name'], 'lang as language');
 }
示例#5
0
 /**
  * importSchema
  *
  * A method to import a Schema and translate it into a Doctrine_Record object
  *
  * @param  string $schema       The file containing the XML schema
  * @param  string $format       Format of the schema file
  * @param  string $directory    The directory where the Doctrine_Record class will be written
  * @param  array  $models       Optional array of models to import
  *
  * @return void
  */
 protected function _importSchema($schema, $format = 'yml', $directory = null, $options = array())
 {
     $schema = (array) $schema;
     $builder = new Install_Api_DoctrineBuilder();
     $builder->setTargetPath($directory);
     $builder->setOptions($options);
     $importer = new Doctrine_Import_Schema();
     $array = $importer->buildSchema($schema, $format);
     if (count($array) == 0) {
         throw new Doctrine_Import_Exception(sprintf('No ' . $format . ' schema found in ' . implode(", ", $schema)));
     }
     foreach ($array as $name => $definition) {
         $builder->buildRecord($definition);
     }
 }