From 701047da658169a7c291a1ba099ed28c83db1b4d Mon Sep 17 00:00:00 2001 From: Yuriy Berest Date: Tue, 12 Nov 2013 16:20:29 +0200 Subject: [PATCH] sfPropelBaseTask->getConnections() mast return only sfPropelConnection connections --- lib/task/sfPropelBaseTask.class.php | 17 +++++++----- test/bin/installer.php | 3 +++ test/unit/task/sfPropelTaskTest.php | 40 +++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 test/unit/task/sfPropelTaskTest.php diff --git a/lib/task/sfPropelBaseTask.class.php b/lib/task/sfPropelBaseTask.class.php index a112572da..560a6b9b5 100644 --- a/lib/task/sfPropelBaseTask.class.php +++ b/lib/task/sfPropelBaseTask.class.php @@ -346,7 +346,7 @@ protected function callPhing($taskName, $checkSchema, $properties = array()) return $ret; } - protected function getPhingPropertiesForConnection($databaseManager, $connection) + protected function getPhingPropertiesForConnection(sfDatabaseManager $databaseManager, $connection) { $database = $databaseManager->getDatabase($connection); @@ -360,12 +360,18 @@ protected function getPhingPropertiesForConnection($databaseManager, $connection ); } - public function getConnections($databaseManager) + public function getConnections(sfDatabaseManager $databaseManager) { $connections = array(); foreach ($databaseManager->getNames() as $connectionName) { + /** @var sfDatabase $database */ $database = $databaseManager->getDatabase($connectionName); + + if (!$database instanceof sfPropelDatabase) { + continue; + } + $connections[$connectionName] = array( 'adapter' => $database->getParameter('phptype'), 'dsn' => $database->getParameter('dsn'), @@ -382,7 +388,7 @@ public function getConnections($databaseManager) return $connections; } - public function getConnection($databaseManager, $connection) + public function getConnection(sfDatabaseManager $databaseManager, $connection) { $database = $databaseManager->getDatabase($connection); return array( @@ -399,7 +405,7 @@ public function getConnection($databaseManager, $connection) ); } - protected function getPlatform($databaseManager, $connection) + protected function getPlatform(sfDatabaseManager $databaseManager, $connection) { $params = $this->getConnection($databaseManager, $connection); $platformClass = ucfirst($params['adapter']) . 'Platform'; @@ -409,7 +415,7 @@ protected function getPlatform($databaseManager, $connection) return $platform; } - protected function getParser($databaseManager, $connection, $con) + protected function getParser(sfDatabaseManager $databaseManager, $connection, $con) { $params = $this->getConnection($databaseManager, $connection); $parserClass = ucfirst($params['adapter']) . 'SchemaParser'; @@ -483,7 +489,6 @@ protected function getGeneratorConfig($params = array()) 'nested_set' => 'nestedset.NestedSetBehavior', 'sortable' => 'sortable.SortableBehavior', 'sluggable' => 'sluggable.SluggableBehavior', - 'sortable' => 'sortable.SortableBehavior', 'concrete_inheritance' => 'concrete_inheritance.ConcreteInheritanceBehavior', 'query_cache' => 'query_cache.QueryCacheBehavior', 'aggregate_column' => 'aggregate_column.AggregateColumnBehavior', diff --git a/test/bin/installer.php b/test/bin/installer.php index 9eee12869..ed45d3691 100644 --- a/test/bin/installer.php +++ b/test/bin/installer.php @@ -9,6 +9,9 @@ $this->logSection('install', 'default to sqlite'); $this->runTask('configure:database', sprintf("'sqlite:%spropel.db'", sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR)); +$this->logSection('install', 'secondary database'); +$this->runTask('configure:database', sprintf("--name=non-propel --class=sfPDODatabase 'sqlite:%spropel2.db'", sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR)); + $this->logSection('install', 'fix sqlite database permissions'); touch(sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR .'propel.db'); chmod(sfConfig::get('sf_data_dir'), 0777); diff --git a/test/unit/task/sfPropelTaskTest.php b/test/unit/task/sfPropelTaskTest.php new file mode 100644 index 000000000..4d0dfcafc --- /dev/null +++ b/test/unit/task/sfPropelTaskTest.php @@ -0,0 +1,40 @@ +configuration); + $connections = $this->getConnections($databaseManager); + + $t = new lime_test(count($connections)); + $t->diag('->getConnections()'); + + foreach ($connections as $name => $connection) { + $databaseInstance = $databaseManager->getDatabase($name); + $t->ok( + $databaseInstance instanceof sfPropelDatabase, + sprintf( + '->getConnections() should return only sfPropelDatabase instance. "%s" returned', + get_class($databaseInstance) + ) + ); + } + } + +} + +$task = new sfPropelDummyTask($dispatcher, new sfFormatter()); +$task->run();