Commit f0686b39 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Fix all failing tests on MySQL, PostgreSQL and Oracle

parent 4c5317e0
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......@@ -37,8 +35,7 @@ use Doctrine\Common\EventSubscriber;
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 1.0
* @version $Revision$
* @since 2.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class OracleSessionInit implements EventSubscriber
......
......@@ -21,13 +21,12 @@
namespace Doctrine\DBAL\Schema;
/**
* xxx
* PostgreSQL Schema Manager
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @version $Revision$
* @since 2.0
*/
class PostgreSqlSchemaManager extends AbstractSchemaManager
......@@ -338,6 +337,10 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
break;
}
if ($tableColumn['default'] && preg_match("('([^']+)'::)", $tableColumn['default'], $match)) {
$tableColumn['default'] = $match[1];
}
$options = array(
'length' => $length,
'notnull' => (bool) $tableColumn['isnotnull'],
......
......@@ -10,11 +10,13 @@ require_once __DIR__ . '/../../TestInit.php';
class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
static private $generated = false;
public function setUp()
{
parent::setUp();
try {
if (self::$generated === false) {
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
$table = new \Doctrine\DBAL\Schema\Table("fetch_table");
$table->addColumn('test_int', 'integer');
......@@ -26,8 +28,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$sm->createTable($table);
$this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo', 'test_datetime' => '2010-01-01 10:10:10'));
} catch(\Exception $e) {
self::$generated = true;
}
}
......@@ -354,6 +355,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->assertEquals(4, count($data));
$this->assertEquals(count($bitmap), count($data));
foreach ($data as $row) {
$row = array_change_key_case($row, CASE_LOWER);
$this->assertArrayHasKey('test_int', $row);
......
......@@ -156,6 +156,10 @@ class NamedParametersTest extends \Doctrine\Tests\DbalFunctionalTestCase
$stmt = $this->_conn->executeQuery($query, $params, $types);
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($result as $k => $v) {
$result[$k] = array_change_key_case($v, CASE_LOWER);
}
$this->assertEquals($result, $expected);
}
......
......@@ -61,6 +61,7 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->assertFetchResultRows($rows);
$stmt = $this->getPortableConnection()->query('SELECT * FROM portability_table');
$stmt->setFetchMode(\PDO::FETCH_ASSOC);
foreach ($stmt as $row) {
$this->assertFetchResultRow($row);
}
......
......@@ -72,13 +72,13 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
foreach ($this->expectedResult AS $v) {
$numExpectedResult[] = array_values($v);
}
$stmt = $this->_conn->executeQuery("SELECT * FROM caching", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$data = $this->hydrateStmt($stmt, \PDO::FETCH_ASSOC);
$this->assertEquals($this->expectedResult, $data);
$stmt = $this->_conn->executeQuery("SELECT * FROM caching", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$data = $this->hydrateStmt($stmt, \PDO::FETCH_NUM);
......@@ -94,10 +94,10 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function assertStandardAndIteratorFetchAreEqual($fetchStyle)
{
$stmt = $this->_conn->executeQuery("SELECT * FROM caching", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$data = $this->hydrateStmt($stmt, $fetchStyle);
$stmt = $this->_conn->executeQuery("SELECT * FROM caching", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$data_iterator = $this->hydrateStmtIterator($stmt, $fetchStyle);
$this->assertEquals($data, $data_iterator);
......@@ -105,14 +105,14 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testDontCloseNoCache()
{
$stmt = $this->_conn->executeQuery("SELECT * FROM caching", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$data = array();
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$data[] = $row;
}
$stmt = $this->_conn->executeQuery("SELECT * FROM caching", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$data = array();
while ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
......@@ -124,12 +124,12 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testDontFinishNoCache()
{
$stmt = $this->_conn->executeQuery("SELECT * FROM caching", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
$stmt = $this->_conn->executeQuery("SELECT * FROM caching", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$data = $this->hydrateStmt($stmt, \PDO::FETCH_NUM);
......@@ -138,13 +138,13 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, $fetchStyle)
{
$stmt = $this->_conn->executeQuery("SELECT * FROM caching", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$this->assertEquals(2, $stmt->columnCount());
$data = $this->hydrateStmt($stmt, $fetchStyle);
$this->assertEquals($expectedResult, $data);
$stmt = $this->_conn->executeQuery("SELECT * FROM caching", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
$this->assertEquals(2, $stmt->columnCount());
$data = $this->hydrateStmt($stmt, $fetchStyle);
......@@ -180,7 +180,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$data = array();
while ($row = $stmt->fetch($fetchStyle)) {
$data[] = $row;
$data[] = array_change_key_case($row, CASE_LOWER);
}
$stmt->closeCursor();
return $data;
......@@ -191,7 +191,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
$data = array();
$stmt->setFetchMode($fetchStyle);
foreach ($stmt as $row) {
$data[] = $row;
$data[] = array_change_key_case($row, CASE_LOWER);
}
$stmt->closeCursor();
return $data;
......
......@@ -98,8 +98,8 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
{
$table = new \Doctrine\DBAL\Schema\Table('list_table_columns');
$table->addColumn('id', 'integer', array('notnull' => true));
$table->addColumn('test', 'string', array('length' => 255, 'notnull' => false));
$table->addColumn('foo', 'text', array('notnull' => true, 'default' => 'expected default'));
$table->addColumn('test', 'string', array('length' => 255, 'notnull' => false, 'default' => 'expected default'));
$table->addColumn('foo', 'text', array('notnull' => true));
$table->addColumn('bar', 'decimal', array('precision' => 10, 'scale' => 4, 'notnull' => false));
$table->addColumn('baz1', 'datetime');
$table->addColumn('baz2', 'time');
......@@ -130,7 +130,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->assertEquals(255, $columns['test']->getlength());
$this->assertEquals(false, $columns['test']->getfixed());
$this->assertEquals(false, $columns['test']->getnotnull());
$this->assertEquals(null, $columns['test']->getdefault());
$this->assertEquals('expected default', $columns['test']->getdefault());
$this->assertInternalType('array', $columns['test']->getPlatformOptions());
$this->assertEquals('foo', strtolower($columns['foo']->getname()));
......@@ -138,7 +138,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->assertEquals(false, $columns['foo']->getunsigned());
$this->assertEquals(false, $columns['foo']->getfixed());
$this->assertEquals(true, $columns['foo']->getnotnull());
$this->assertEquals('expected default', $columns['foo']->getdefault());
$this->assertEquals(null, $columns['foo']->getdefault());
$this->assertInternalType('array', $columns['foo']->getPlatformOptions());
$this->assertEquals('bar', strtolower($columns['bar']->getname()));
......@@ -188,7 +188,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
public function testListTableIndexes()
{
$table = $this->getTestTable('list_table_indexes_test');
$table = $this->getTestCompositeTable('list_table_indexes_test');
$table->addUniqueIndex(array('test'), 'test_index_name');
$table->addIndex(array('id', 'test'), 'test_composite_idx');
......@@ -505,10 +505,20 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$table = new \Doctrine\DBAL\Schema\Table($name, array(), array(), array(), false, $options);
$table->setSchemaConfig($this->_sm->createSchemaConfig());
$table->addColumn('id', 'integer', array('notnull' => true));
$table->setPrimaryKey(array('id'));
$table->addColumn('test', 'string', array('length' => 255));
$table->addColumn('foreign_key_test', 'integer');
return $table;
}
protected function getTestCompositeTable($name)
{
$table = new \Doctrine\DBAL\Schema\Table($name, array(), array(), array(), false, array());
$table->setSchemaConfig($this->_sm->createSchemaConfig());
$table->addColumn('id', 'integer', array('notnull' => true));
$table->addColumn('other_id', 'integer', array('notnull' => true));
$table->setPrimaryKey(array('id', 'other_id'));
$table->addColumn('test', 'string', array('length' => 255));
$table->addColumn('foreign_key_test', 'integer');
return $table;
}
......
......@@ -100,6 +100,14 @@ class TestUtil
$conn = \Doctrine\DBAL\DriverManager::getConnection($params);
}
if (isset($GLOBALS['db_event_subscribers'])) {
$evm = $conn->getEventManager();
foreach (explode(",", $GLOBALS['db_event_subscribers']) AS $subscriberClass) {
$subscriberInstance = new $subscriberClass();
$evm->addEventSubscriber($subscriberInstance);
}
}
return $conn;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment