Development

Changeset 8295

You must first sign up to be able to contribute.

Changeset 8295

Show
Ignore:
Timestamp:
04/04/08 18:02:20 (2 years ago)
Author:
fabien
Message:

moved Propel initialization and fixtures loading in ProjectConfiguration? in Propel functional tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/plugins/sfPropelPlugin/test/bootstrap/functional.php

    r8290 r8295  
    2323$configuration = ProjectConfiguration::getApplicationConfiguration($app, 'test', isset($debug) ? $debug : true); 
    2424sfContext::createInstance($configuration); 
    25 $dispatcher = $configuration->getEventDispatcher(); 
    2625 
    2726// remove all cache 
    2827sf_functional_test_shutdown(); 
     28 
     29$configuration->initializePropel(); 
     30if (isset($fixtures)) 
     31{ 
     32  $configuration->loadFixtures($fixtures); 
     33} 
    2934 
    3035register_shutdown_function('sf_functional_test_shutdown'); 
     
    3641} 
    3742 
    38 // build Propel om/map/sql/forms 
    39 $files = glob(sfConfig::get('sf_lib_dir').'/model/om/*.php'); 
    40 if (false === $files || !count($files)) 
    41 { 
    42   chdir(sfConfig::get('sf_root_dir')); 
    43   $task = new sfPropelBuildModelTask($dispatcher, new sfFormatter()); 
    44   ob_start(); 
    45   $task->run(); 
    46   $output = ob_get_clean(); 
    47 } 
    48  
    49 $files = glob(sfConfig::get('sf_data_dir').'/sql/*.php'); 
    50 if (false === $files || !count($files)) 
    51 { 
    52   chdir(sfConfig::get('sf_root_dir')); 
    53   $task = new sfPropelBuildSqlTask($dispatcher, new sfFormatter()); 
    54   ob_start(); 
    55   $task->run(); 
    56   $output = ob_get_clean(); 
    57 } 
    58  
    59 $files = glob(sfConfig::get('sf_lib_dir').'/form/base/*.php'); 
    60 if (false === $files || !count($files)) 
    61 { 
    62   chdir(sfConfig::get('sf_root_dir')); 
    63   $task = new sfPropelBuildFormsTask($dispatcher, new sfFormatter()); 
    64   $task->run(); 
    65 } 
    66  
    67 if (isset($fixtures)) 
    68 { 
    69   // initialize database manager 
    70   $databaseManager = new sfDatabaseManager($configuration); 
    71  
    72   // cleanup database 
    73   $db = sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'/database.sqlite'; 
    74   if (file_exists($db)) 
    75   { 
    76     unlink($db); 
    77   } 
    78  
    79   // initialize database 
    80   $sql = file_get_contents(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'sql'.DIRECTORY_SEPARATOR.'lib.model.schema.sql'); 
    81   $sql = preg_replace('/^\s*\-\-.+$/m', '', $sql); 
    82   $sql = preg_replace('/^\s*DROP TABLE .+?$/m', '', $sql); 
    83   $con = Propel::getConnection(); 
    84   $tables = preg_split('/CREATE TABLE/', $sql); 
    85   foreach ($tables as $table) 
    86   { 
    87     $table = trim($table); 
    88     if (!$table) 
    89     { 
    90       continue; 
    91     } 
    92  
    93     $con->executeQuery('CREATE TABLE '.$table); 
    94   } 
    95  
    96   // load fixtures 
    97   $data = new sfPropelData(); 
    98   if (is_array($fixtures)) 
    99   { 
    100     $data->loadDataFromArray($fixtures); 
    101   } 
    102   else 
    103   { 
    104     $data->loadData(sfConfig::get('sf_data_dir').'/'.$fixtures); 
    105   } 
    106 } 
    107  
    10843return true; 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/config/ProjectConfiguration.class.php

    r7962 r8295  
    99  { 
    1010  } 
     11 
     12  public function initializePropel() 
     13  { 
     14    // build Propel om/map/sql/forms 
     15    $files = glob(sfConfig::get('sf_lib_dir').'/model/om/*.php'); 
     16    if (false === $files || !count($files)) 
     17    { 
     18      chdir(sfConfig::get('sf_root_dir')); 
     19      $task = new sfPropelBuildModelTask($this->dispatcher, new sfFormatter()); 
     20      ob_start(); 
     21      $task->run(); 
     22      $output = ob_get_clean(); 
     23    } 
     24 
     25    $files = glob(sfConfig::get('sf_data_dir').'/sql/*.php'); 
     26    if (false === $files || !count($files)) 
     27    { 
     28      chdir(sfConfig::get('sf_root_dir')); 
     29      $task = new sfPropelBuildSqlTask($this->dispatcher, new sfFormatter()); 
     30      ob_start(); 
     31      $task->run(); 
     32      $output = ob_get_clean(); 
     33    } 
     34 
     35    $files = glob(sfConfig::get('sf_lib_dir').'/form/base/*.php'); 
     36    if (false === $files || !count($files)) 
     37    { 
     38      chdir(sfConfig::get('sf_root_dir')); 
     39      $task = new sfPropelBuildFormsTask($this->dispatcher, new sfFormatter()); 
     40      $task->run(); 
     41    } 
     42  } 
     43 
     44  public function loadFixtures($fixtures) 
     45  { 
     46    // initialize database manager 
     47    $databaseManager = new sfDatabaseManager($this); 
     48 
     49    // cleanup database 
     50    $db = sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'/database.sqlite'; 
     51    if (file_exists($db)) 
     52    { 
     53      unlink($db); 
     54    } 
     55 
     56    // initialize database 
     57    $sql = file_get_contents(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'sql'.DIRECTORY_SEPARATOR.'lib.model.schema.sql'); 
     58    $sql = preg_replace('/^\s*\-\-.+$/m', '', $sql); 
     59    $sql = preg_replace('/^\s*DROP TABLE .+?$/m', '', $sql); 
     60    $con = Propel::getConnection(); 
     61    $tables = preg_split('/CREATE TABLE/', $sql); 
     62    foreach ($tables as $table) 
     63    { 
     64      $table = trim($table); 
     65      if (!$table) 
     66      { 
     67        continue; 
     68      } 
     69 
     70      $con->executeQuery('CREATE TABLE '.$table); 
     71    } 
     72 
     73    // load fixtures 
     74    $data = new sfPropelData(); 
     75    if (is_array($fixtures)) 
     76    { 
     77      $data->loadDataFromArray($fixtures); 
     78    } 
     79    else 
     80    { 
     81      $data->loadData(sfConfig::get('sf_data_dir').'/'.$fixtures); 
     82    } 
     83  } 
    1184} 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.