Changeset 3888

Show
Ignore:
Timestamp:
02/23/08 21:11:36 (17 months ago)
Author:
jwage
Message:

Small refactorings and new tests for model loading(aggressive and conservative) and model generation with inheritance.

Location:
branches/0.10
Files:
11 added
5 modified

Legend:

Unmodified
Added
Removed
  • branches/0.10/lib/Doctrine.php

    r3887 r3888  
    469469    private static $_loadedModelFiles = array(); 
    470470 
    471     private static $_pathModels = array(); 
    472  
    473471    /** 
    474472     * _validators 
     
    490488    } 
    491489 
     490    /** 
     491     * getLoadedModelFiles 
     492     * 
     493     * Returns an array of all the loaded models and the path where each of them exists 
     494     * 
     495     * @return array 
     496     */ 
    492497    public static function getLoadedModelFiles() 
    493498    { 
    494499        return self::$_loadedModelFiles; 
    495     } 
    496      
    497     public static function getPathModels() 
    498     { 
    499         return self::$_pathModels; 
    500500    } 
    501501 
     
    555555                    $e = explode('.', $file->getFileName()); 
    556556                    if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) { 
     557                        $className = $e[0]; 
    557558 
    558559                        if ($modelLoading == Doctrine::MODEL_LOADING_CONSERVATIVE) { 
    559                             self::$_loadedModelFiles[$e[0]] = $file->getPathName(); 
    560                             self::$_pathModels[$file->getPathName()][$e[0]] = $e[0]; 
    561  
    562                             $loadedModels[] = $e[0]; 
     560                            self::$_loadedModelFiles[$className] = $file->getPathName(); 
     561 
     562                            $loadedModels[$className] = $className; 
    563563                        } else { 
    564564                            $declaredBefore = get_declared_classes(); 
     
    571571                                foreach ($foundClasses as $className) { 
    572572                                    if (self::isValidModelClass($className)) { 
    573                                         $loadedModels[] = $className; 
     573                                        $loadedModels[$className] = $className; 
    574574 
    575575                                        self::$_loadedModelFiles[$className] = $file->getPathName(); 
    576                                         self::$_pathModels[$file->getPathName()][$className] = $className; 
    577576                                    } 
    578577                                } 
     
    624623 
    625624        foreach ((array) $classes as $name) { 
    626             if (self::isValidModelClass($name) && !in_array($name, $validModels)) { 
     625            if (self::isValidModelClass($name) && ! in_array($name, $validModels)) { 
    627626                $validModels[] = $name; 
    628627            } 
     
    655654            // - abstract classes 
    656655            // - not a subclass of Doctrine_Record 
    657             // - don't have a setTableDefinition method 
    658             if (!$class->isAbstract() && 
    659                 $class->isSubClassOf('Doctrine_Record') && 
    660                 $class->hasMethod('setTableDefinition')) { 
     656            if ( ! $class->isAbstract() && $class->isSubClassOf('Doctrine_Record')) { 
    661657 
    662658                return true; 
     
    680676 
    681677        foreach ($loadedModels as $name) { 
    682             $model = new $name(); 
    683             $table = $model->getTable(); 
     678            $table = Doctrine::getTable($name); 
    684679 
    685680            if ($table->getTableName() == $tableName) { 
  • branches/0.10/tests/Import/BuilderTestCase.php

    r3884 r3888  
    3333class Doctrine_Import_Builder_TestCase extends Doctrine_UnitTestCase  
    3434{ 
    35     public function testBuildingOfRecord() 
     35    public function testInheritanceGeneration() 
    3636    { 
    37         $table = $this->conn->getTable('Phonenumber'); 
     37        $path = realpath(dirname(__FILE__) . '/../..') . '/models/test_generated'; 
     38 
     39        $import = new Doctrine_Import_Schema(); 
     40        $import->importSchema('schema.yml', 'yml', $path); 
     41 
     42        $models = Doctrine::loadModels($path, Doctrine::MODEL_LOADING_CONSERVATIVE); 
     43 
     44        $schemaTestInheritanceParent = new ReflectionClass('SchemaTestInheritanceParent'); 
     45        $schemaTestInheritanceChild1 = new ReflectionClass('SchemaTestInheritanceChild1'); 
     46        $schemaTestInheritanceChild2 = new ReflectionClass('SchemaTestInheritanceChild2'); 
     47 
     48        /* 
     49        $schemaTestInheritanceParentTable = new ReflectionClass('SchemaTestInheritanceParentTable'); 
     50        $schemaTestInheritanceChild1Table = new ReflectionClass('SchemaTestInheritanceChild1Table'); 
     51        $schemaTestInheritanceChild2Table = new ReflectionClass('SchemaTestInheritanceChild2Table'); 
     52        */ 
     53 
     54        $this->assertTrue($schemaTestInheritanceParent->isSubClassOf('BaseSchemaTestInheritanceParent')); 
     55        $this->assertTrue($schemaTestInheritanceChild1->isSubClassOf('BaseSchemaTestInheritanceChild1')); 
     56        $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('BaseSchemaTestInheritanceChild2')); 
    3857         
    39         $builder = new Doctrine_Import_Builder(); 
     58        $this->assertTrue($schemaTestInheritanceChild1->isSubClassOf('SchemaTestInheritanceParent')); 
     59        $this->assertTrue($schemaTestInheritanceChild1->isSubClassOf('BaseSchemaTestInheritanceParent')); 
    4060         
    41         $rel = $builder->buildRelationDefinition($table->getRelations()); 
     61        $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('SchemaTestInheritanceParent')); 
     62        $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('BaseSchemaTestInheritanceParent')); 
     63        $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('SchemaTestInheritanceChild1')); 
     64        $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('BaseSchemaTestInheritanceChild1')); 
    4265 
     66        /* 
     67        $this->assertTrue($schemaTestInheritanceParentTable->isSubClassOf('Doctrine_Table')); 
     68        $this->assertTrue($schemaTestInheritanceChild1Table->isSubClassOf('SchemaTestInheritanceParentTable')); 
     69        $this->assertTrue($schemaTestInheritanceChild1Table->isSubClassOf('PackageSchemaTestInheritanceParentTable')); 
     70        */ 
     71         
     72        Doctrine_Lib::removeDirectories($path); 
    4373    } 
    4474} 
  • branches/0.10/tests/Import/SchemaTestCase.php

    r3884 r3888  
    3838    public function testYmlImport() 
    3939    { 
     40        $path = realpath(dirname(__FILE__) . '/../..') . '/models/test_generated'; 
     41         
    4042        $import = new Doctrine_Import_Schema(); 
    41         $import->importSchema('schema.yml', 'yml', 'classes'); 
     43        $import->importSchema('schema.yml', 'yml', $path); 
    4244         
    43         if ( ! file_exists('classes/User.php')) { 
     45        if ( ! file_exists($path . '/SchemaTestUser.php')) { 
    4446            $this->fail(); 
    4547        } 
    4648         
    47         if ( ! file_exists('classes/Profile.php')) { 
     49        if ( ! file_exists($path . '/SchemaTestProfile.php')) { 
    4850            $this->fail(); 
    4951        } 
     52 
     53        Doctrine_Lib::removeDirectories($path); 
    5054    } 
    5155     
     
    5559        $array = $schema->buildSchema('schema.yml', 'yml'); 
    5660         
    57         $model = $array['User']; 
     61        $model = $array['SchemaTestUser']; 
    5862 
    5963        $this->assertTrue(array_key_exists('connection', $model)); 
     
    6872        $this->assertTrue(array_key_exists('options', $model) && is_array($model['options'])); 
    6973        $this->assertTrue(array_key_exists('package', $model)); 
     74        $this->assertTrue(array_key_exists('inheritance', $model) && is_array($model['inheritance'])); 
     75        $this->assertTrue(array_key_exists('detect_relations', $model) && is_bool($model['detect_relations'])); 
     76        $this->assertTrue(array_key_exists('generate_accessors', $model) && is_bool($model['generate_accessors'])); 
    7077    } 
    7178     
  • branches/0.10/tests/run.php

    r3880 r3888  
    121121// Core 
    122122$core = new GroupTest('Core tests: Access, Configurable, Manager, Connection, Table, UnitOfWork, Collection, Hydrate, Tokenizer','core'); 
     123$core->addTestCase(new Doctrine_Base_TestCase()); 
    123124$core->addTestCase(new Doctrine_Access_TestCase()); 
    124125//$core->addTestCase(new Doctrine_Configurable_TestCase()); 
     
    227228$record->addTestCase(new Doctrine_Record_Inheritance_TestCase()); 
    228229$record->addTestCase(new Doctrine_Record_Synchronize_TestCase()); 
     230$record->addTestCase(new Doctrine_Import_Builder_TestCase()); 
    229231$test->addTestCase($record); 
    230232 
     
    243245 
    244246$test->addTestCase(new Doctrine_Template_TestCase()); 
    245  
    246 //$test->addTestCase(new Doctrine_Import_Builder_TestCase()); 
    247247$test->addTestCase(new Doctrine_NestedSet_SingleRoot_TestCase()); 
    248248 
  • branches/0.10/tests/schema.yml

    r3159 r3888  
    11--- 
    2 User: 
     2SchemaTestUser: 
    33  actAs: [Timestampable] 
    44  columns: 
     
    1111    password: 
    1212      type: string(255) 
    13 Profile: 
     13 
     14SchemaTestProfile: 
    1415  actAs: [Timestampable] 
    1516  columns: 
     
    2728      type: string(255) 
    2829  relations: 
    29     User:  
     30    SchemaTestUser:  
    3031      foreignType: one 
    31     Contact: 
     32    SchemaTestContact: 
    3233      foreignType: one 
    33 Contact: 
     34 
     35SchemaTestContact: 
    3436  actAs: [Timestampable] 
    3537  columns: 
     
    4042    name: 
    4143      type: string(255) 
    42 Phonenumber: 
     44 
     45SchemaTestPhonenumber: 
    4346  actAs: [Timestampable] 
    4447  columns: 
     
    5255      type: integer(4) 
    5356  relations: 
    54     Contact: 
     57    SchemaTestContact: 
    5558      foreignAlias: Phonenumbers 
     59 
     60SchemaTestInheritanceParent: 
     61  package: Parent 
     62  columns: 
     63    id: 
     64      type: integer(4) 
     65      primary: true 
     66      autoincrement: true 
     67    name: 
     68      type: string(255) 
     69    type: 
     70      type: string(255) 
     71  options: 
     72    subclasses: [SchemaTestInheritanceChild1] 
     73 
     74SchemaTestInheritanceChild1: 
     75  package: Child1 
     76  inheritance: 
     77    extends: SchemaTestInheritanceParent 
     78    keyField: type 
     79    keyValue: child1 
     80 
     81SchemaTestInheritanceChild2: 
     82  package: Child2 
     83  inheritance: 
     84    extends: SchemaTestInheritanceChild1 
     85    keyField: type 
     86    keyValue: child2