Merge branch '2.0'

This commit is contained in:
William DURAND 2011-12-25 14:18:30 +01:00
commit 3c1a87d432
5 changed files with 65 additions and 4 deletions

View file

@ -388,7 +388,12 @@ EOT;
{
preg_match('#dbname=([a-zA-Z0-9\_]+)#', $dsn, $matches);
return $matches[1];
if (isset($matches[1])) {
return $matches[1];
}
// e.g. SQLite
return null;
}
/**

View file

@ -45,7 +45,12 @@ class DatabaseCreateCommand extends AbstractPropelCommand
list($name, $config) = $this->getConnection($input, $output);
$dbName = $this->parseDbName($config['connection']['dsn']);
$query = 'CREATE DATABASE '. $dbName .';';
if (null === $dbName) {
return $output->writeln('<error>No database name found.</error>');
} else {
$query = 'CREATE DATABASE '. $dbName .';';
}
try {
\Propel::setConfiguration($this->getTemporaryConfiguration($name, $config));

View file

@ -67,7 +67,12 @@ EOT
list($name, $config) = $this->getConnection($input, $output);
$dbName = $this->parseDbName($config['connection']['dsn']);
$query = 'DROP DATABASE '. $dbName .';';
if (null === $dbName) {
return $output->writeln('<error>No database name found.</error>');
} else {
$query = 'DROP DATABASE '. $dbName .';';
}
try {
$connection = \Propel::getConnection($name);

View file

@ -0,0 +1,46 @@
<?php
/**
* This file is part of the PropelBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace Tests\Command;
use Propel\PropelBundle\Tests\TestCase;
use Propel\PropelBundle\Command\AbstractPropelCommand;
/**
* @author William Durand <william.durand1@gmail.com>
*/
class AbstractPropelCommandTest extends TestCase
{
protected $command;
public function setUp()
{
$this->command = new TestableAbstractPropelCommand('testable-command');
}
public function testParseDbName()
{
$dsn = 'mydsn#dbname=foo';
$this->assertEquals('foo', $this->command->parseDbName($dsn));
}
public function testParseDbNameWithoutDbName()
{
$this->assertNull($this->command->parseDbName('foo'));
}
}
class TestableAbstractPropelCommand extends AbstractPropelCommand
{
public function parseDbName($dsn)
{
return parent::parseDbName($dsn);
}
}

View file

@ -45,7 +45,7 @@ class UniqueObjectValidator extends ConstraintValidator
$classFields = $peerClass::getFieldNames(\BasePeer::TYPE_FIELDNAME);
foreach ($fields as $fieldName) {
if(!array_search($fieldName, $classFields)) {
if(false === array_search($fieldName, $classFields)) {
throw new ConstraintDefinitionException('The field "' . $fieldName .'" doesn\'t exist in the "' . $class . '" class.');
}
}