Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sfPropelBaseTask->getConnections() must return only sfPropelDatabase connections params #216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lib/task/sfPropelBaseTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this line

$database = $databaseManager->getDatabase($connectionName);

if (!$database instanceof sfPropelDatabase) {
continue;
}

$connections[$connectionName] = array(
'adapter' => $database->getParameter('phptype'),
'dsn' => $database->getParameter('dsn'),
Expand All @@ -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(
Expand All @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions test/bin/installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions test/unit/task/sfPropelTaskTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

$rootDir = dirname(__FILE__) . '/../../../../..';
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';

$dispatcher = new sfEventDispatcher();
require_once $rootDir.'/config/ProjectConfiguration.class.php';
$configuration = new ProjectConfiguration($rootDir, $dispatcher);

class sfPropelDummyTask extends sfPropelBaseTask
{

public function checkProjectExists()
{
}

protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->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();