From 2be8242a8185aad55ace6442adbcc7b9e282b35b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Thu, 30 Apr 2015 18:11:43 +0200 Subject: [PATCH 01/70] fix retrieving the database name connected to for SQL Server --- .../DBAL/Driver/AbstractSQLServerDriver.php | 6 ++- .../Functional/Driver/PDOSqlsrv/Driver.php | 38 +++++++++++++++++++ .../DBAL/Functional/Driver/SQLSrv/Driver.php | 38 +++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/Driver.php create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/Driver.php diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php index 17e12254c6d..53a4dd52620 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php @@ -78,7 +78,11 @@ public function getDatabase(\Doctrine\DBAL\Connection $conn) { $params = $conn->getParams(); - return $params['dbname']; + if (isset($params['dbname'])) { + return $params['dbname']; + } + + return $conn->query('SELECT DB_NAME()')->fetchColumn(); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/Driver.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/Driver.php new file mode 100644 index 00000000000..517907f83b5 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/Driver.php @@ -0,0 +1,38 @@ +markTestSkipped('pdo_sqlsrv is not installed.'); + } + + parent::setUp(); + + if (! $this->_conn->getDriver() instanceof Driver) { + $this->markTestSkipped('pdo_sqlsrv only test.'); + } + } + + /** + * {@inheritdoc} + */ + protected function createDriver() + { + return new Driver(); + } + + /** + * {@inheritdoc} + */ + protected function getDatabaseNameForConnectionWithoutDatabaseNameParameter() + { + return 'master'; + } +} diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/Driver.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/Driver.php new file mode 100644 index 00000000000..da94f26e256 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/Driver.php @@ -0,0 +1,38 @@ +markTestSkipped('sqlsrv is not installed.'); + } + + parent::setUp(); + + if (! $this->_conn->getDriver() instanceof Driver) { + $this->markTestSkipped('sqlsrv only test.'); + } + } + + /** + * {@inheritdoc} + */ + protected function createDriver() + { + return new Driver(); + } + + /** + * {@inheritdoc} + */ + protected function getDatabaseNameForConnectionWithoutDatabaseNameParameter() + { + return 'master'; + } +} From 987421efa7aecaf5142adead54d14647c01b90aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Thu, 30 Apr 2015 18:18:49 +0200 Subject: [PATCH 02/70] make driver property protected to be available for subclassing test cases --- .../Tests/DBAL/Functional/Driver/AbstractDriverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php index 883e447c129..35991a8a47f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php @@ -12,7 +12,7 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase * * @var \Doctrine\DBAL\Driver */ - private $driver; + protected $driver; protected function setUp() { From 25a78e4d3b2ce7c937d0dc2af5e4eb8a5c7b6a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Thu, 30 Apr 2015 18:21:19 +0200 Subject: [PATCH 03/70] fix retrieving the database name connected to for SQL Anywhere --- .../DBAL/Driver/AbstractSQLAnywhereDriver.php | 6 ++- .../Driver/SQLAnywhere/DriverTest.php | 48 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php index e47517a1ac3..0527555af4f 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php @@ -116,7 +116,11 @@ public function getDatabase(\Doctrine\DBAL\Connection $conn) { $params = $conn->getParams(); - return $params['dbname']; + if (isset($params['dbname'])) { + return $params['dbname']; + } + + return $conn->query('SELECT DB_NAME()')->fetchColumn(); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php new file mode 100644 index 00000000000..0a4b13a55e0 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php @@ -0,0 +1,48 @@ +markTestSkipped('sqlanywhere is not installed.'); + } + + parent::setUp(); + + if (! $this->_conn->getDriver() instanceof Driver) { + $this->markTestSkipped('sqlanywhere only test.'); + } + } + + public function testReturnsDatabaseNameWithoutDatabaseNameParameter() + { + $params = $this->_conn->getParams(); + unset($params['dbname']); + + $connection = new Connection( + $params, + $this->_conn->getDriver(), + $this->_conn->getConfiguration(), + $this->_conn->getEventManager() + ); + + // SQL Anywhere has no "default" database. The name of the default database + // is defined on server startup and therefore can be arbitrary. + $this->assertInternalType('string', $this->driver->getDatabase($connection)); + } + + /** + * {@inheritdoc} + */ + protected function createDriver() + { + return new Driver(); + } +} From 3f221149d682c7918cf89c1e33964031557b755c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Thu, 30 Apr 2015 18:24:56 +0200 Subject: [PATCH 04/70] add functional driver test case for ibm_db2 driver --- .../Driver/IBMDB2/DB2DriverTest.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php new file mode 100644 index 00000000000..74454ec2ea1 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php @@ -0,0 +1,46 @@ +markTestSkipped('ibm_db2 is not installed.'); + } + + parent::setUp(); + + if (! $this->_conn->getDriver() instanceof DB2Driver) { + $this->markTestSkipped('ibm_db2 only test.'); + } + } + + /** + * {@inheritdoc} + */ + public function testConnectsWithoutDatabaseNameParameter() + { + $this->markTestSkipped('IBM DB2 does not support connecting without database name.'); + } + + /** + * {@inheritdoc} + */ + public function testReturnsDatabaseNameWithoutDatabaseNameParameter() + { + $this->markTestSkipped('IBM DB2 does not support connecting without database name.'); + } + + /** + * {@inheritdoc} + */ + protected function createDriver() + { + return new DB2Driver(); + } +} From 9e55dd607779a449b1aa38d6f34f286b34a1e1b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Thu, 30 Apr 2015 18:25:35 +0200 Subject: [PATCH 05/70] add functional driver test case for mysqli driver --- .../Functional/Driver/Mysqli/DriverTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php new file mode 100644 index 00000000000..3c56fbec79f --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php @@ -0,0 +1,30 @@ +markTestSkipped('mysqli is not installed.'); + } + + parent::setUp(); + + if (! $this->_conn->getDriver() instanceof Driver) { + $this->markTestSkipped('MySQLi only test.'); + } + } + + /** + * {@inheritdoc} + */ + protected function createDriver() + { + return new Driver(); + } +} From 4a4c35aa680df42ec41af0ada38549847784faab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Thu, 30 Apr 2015 18:25:50 +0200 Subject: [PATCH 06/70] add functional driver test case for oci8 driver --- .../Functional/Driver/OCI8/DriverTest.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php new file mode 100644 index 00000000000..000c8140dd8 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php @@ -0,0 +1,46 @@ +markTestSkipped('oci8 is not installed.'); + } + + parent::setUp(); + + if (! $this->_conn->getDriver() instanceof Driver) { + $this->markTestSkipped('oci8 only test.'); + } + } + + /** + * {@inheritdoc} + */ + public function testConnectsWithoutDatabaseNameParameter() + { + $this->markTestSkipped('Oracle does not support connecting without database name.'); + } + + /** + * {@inheritdoc} + */ + public function testReturnsDatabaseNameWithoutDatabaseNameParameter() + { + $this->markTestSkipped('Oracle does not support connecting without database name.'); + } + + /** + * {@inheritdoc} + */ + protected function createDriver() + { + return new Driver(); + } +} From 03aac225804db67becb46ca60bdf2020c3f620be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Thu, 30 Apr 2015 18:26:13 +0200 Subject: [PATCH 07/70] add functional driver test case for pdo_mysql driver --- .../Functional/Driver/PDOMySql/DriverTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php new file mode 100644 index 00000000000..09840ba268c --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php @@ -0,0 +1,30 @@ +markTestSkipped('pdo_mysql is not installed.'); + } + + parent::setUp(); + + if (! $this->_conn->getDriver() instanceof Driver) { + $this->markTestSkipped('pdo_mysql only test.'); + } + } + + /** + * {@inheritdoc} + */ + protected function createDriver() + { + return new Driver(); + } +} From f6e708d245eb04d3dac01e18325b2ccc72213632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Thu, 30 Apr 2015 18:26:39 +0200 Subject: [PATCH 08/70] add functional driver test case for PDO_OCI driver --- .../Driver/PDOOracle/DriverTest.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php new file mode 100644 index 00000000000..ddfdf780d5f --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php @@ -0,0 +1,46 @@ +markTestSkipped('PDO_OCI is not installed.'); + } + + parent::setUp(); + + if (! $this->_conn->getDriver() instanceof Driver) { + $this->markTestSkipped('PDO_OCI only test.'); + } + } + + /** + * {@inheritdoc} + */ + public function testConnectsWithoutDatabaseNameParameter() + { + $this->markTestSkipped('Oracle does not support connecting without database name.'); + } + + /** + * {@inheritdoc} + */ + public function testReturnsDatabaseNameWithoutDatabaseNameParameter() + { + $this->markTestSkipped('Oracle does not support connecting without database name.'); + } + + /** + * {@inheritdoc} + */ + protected function createDriver() + { + return new Driver(); + } +} From 457678023f89c9c8f54f032041c462a22ba37389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Thu, 30 Apr 2015 18:26:53 +0200 Subject: [PATCH 09/70] add functional driver test case for pdo_sqlite driver --- .../Driver/PDOSqlite/DriverTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php new file mode 100644 index 00000000000..beb1b0d1910 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php @@ -0,0 +1,30 @@ +markTestSkipped('pdo_sqlite is not installed.'); + } + + parent::setUp(); + + if (! $this->_conn->getDriver() instanceof Driver) { + $this->markTestSkipped('pdo_sqlite only test.'); + } + } + + /** + * {@inheritdoc} + */ + protected function createDriver() + { + return new Driver(); + } +} From f6d28a64d311f8465ece9fe820de4deabebf45ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Thu, 30 Apr 2015 23:39:55 +0200 Subject: [PATCH 10/70] fix namespace --- .../Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php index 74454ec2ea1..f345e88d92c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php @@ -1,6 +1,6 @@ Date: Fri, 1 May 2015 10:16:55 +0200 Subject: [PATCH 11/70] fix dropping database with active connection on PostgreSQL --- .../DBAL/Platforms/PostgreSQL92Platform.php | 8 +++++ .../DBAL/Platforms/PostgreSqlPlatform.php | 28 +++++++++++++++++ .../DBAL/Schema/PostgreSqlSchemaManager.php | 28 +++++++++++++++++ .../SchemaManagerFunctionalTestCase.php | 30 +++++++++++++++++++ .../Schema/SqliteSchemaManagerTest.php | 26 ++++++++++++++++ .../AbstractPostgreSqlPlatformTestCase.php | 22 ++++++++++++++ .../Platforms/PostgreSQL92PlatformTest.php | 11 +++++++ 7 files changed, 153 insertions(+) diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php index dcb5ebe9c7f..19cf8035630 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php @@ -72,4 +72,12 @@ protected function initializeDoctrineTypeMappings() parent::initializeDoctrineTypeMappings(); $this->doctrineTypeMapping['json'] = 'json_array'; } + + /** + * {@inheritdoc} + */ + public function getCloseActiveDatabaseConnectionsSQL($database) + { + return "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '$database'"; + } } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index cb512c47939..575e144bda6 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -420,6 +420,34 @@ public function getCreateDatabaseSQL($name) return 'CREATE DATABASE ' . $name; } + /** + * Returns the SQL statement for disallowing new connections on the given database. + * + * This is useful to force DROP DATABASE operations which could fail because of active connections. + * + * @param string $database The name of the database to disallow new connections for. + * + * @return string + */ + public function getDisallowDatabaseConnectionsSQL($database) + { + return "UPDATE pg_database SET datallowconn = 'false' WHERE datname = '$database'"; + } + + /** + * Returns the SQL statement for closing currently active connections on the given database. + * + * This is useful to force DROP DATABASE operations which could fail because of active connections. + * + * @param string $database The name of the database to close currently active connections for. + * + * @return string + */ + public function getCloseActiveDatabaseConnectionsSQL($database) + { + return "SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = '$database'"; + } + /** * {@inheritDoc} */ diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index ee2606d6a53..5b7b82e152b 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -19,6 +19,7 @@ namespace Doctrine\DBAL\Schema; +use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Types\Type; /** @@ -100,6 +101,33 @@ public function determineExistingSchemaSearchPaths() }); } + /** + * {@inheritdoc} + */ + public function dropDatabase($database) + { + try { + parent::dropDatabase($database); + } catch (DriverException $exception) { + // If we have a SQLSTATE 55006, the drop database operation failed + // because of active connections on the database. + // To force dropping the database, we first have to close all active connections + // on that database and issue the drop database operation again. + if ($exception->getSQLState() !== '55006') { + throw $exception; + } + + $this->_execSql( + array( + $this->_platform->getDisallowDatabaseConnectionsSQL($database), + $this->_platform->getCloseActiveDatabaseConnectionsSQL($database), + ) + ); + + parent::dropDatabase($database); + } + } + /** * {@inheritdoc} */ diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index a2cf7311d6d..3a9bf61b294 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -40,6 +40,36 @@ protected function setUp() $this->_sm = $this->_conn->getSchemaManager(); } + /** + * @group DBAL-1220 + */ + public function testDropsDatabaseWithActiveConnections() + { + if (! $this->_sm->getDatabasePlatform()->supportsCreateDropDatabase()) { + $this->markTestSkipped('Cannot drop Database client side with this Driver.'); + } + + $this->_sm->dropAndCreateDatabase('test_drop_database'); + + $this->assertContains('test_drop_database', $this->_sm->listDatabases()); + + $params = $this->_conn->getParams(); + $params['dbname'] = 'test_drop_database'; + + $user = isset($params['user']) ? $params['user'] : null; + $password = isset($params['password']) ? $params['password'] : null; + + $connection = $this->_conn->getDriver()->connect($params, $user, $password); + + $this->assertInstanceOf('Doctrine\DBAL\Driver\Connection', $connection); + + $this->_sm->dropDatabase('test_drop_database'); + + $this->assertNotContains('test_drop_database', $this->_sm->listDatabases()); + + unset($connection); + } + /** * @group DBAL-195 */ diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index 67282b1c204..dd03a0f9877 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -26,6 +26,32 @@ public function testCreateAndDropDatabase() $this->assertEquals(false, file_exists($path)); } + /** + * @group DBAL-1220 + */ + public function testDropsDatabaseWithActiveConnections() + { + $this->_sm->dropAndCreateDatabase('test_drop_database'); + + $this->assertFileExists('test_drop_database'); + + $params = $this->_conn->getParams(); + $params['dbname'] = 'test_drop_database'; + + $user = isset($params['user']) ? $params['user'] : null; + $password = isset($params['password']) ? $params['password'] : null; + + $connection = $this->_conn->getDriver()->connect($params, $user, $password); + + $this->assertInstanceOf('Doctrine\DBAL\Driver\Connection', $connection); + + $this->_sm->dropDatabase('test_drop_database'); + + $this->assertFileNotExists('test_drop_database'); + + unset($connection); + } + public function testRenameTable() { $this->createTestTable('oldname'); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 58da19b7397..29295c25a08 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -792,4 +792,26 @@ public function testInitializesTsvectorTypeMapping() $this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('tsvector')); $this->assertEquals('text', $this->_platform->getDoctrineTypeMapping('tsvector')); } + + /** + * @group DBAL-1220 + */ + public function testReturnsDisallowDatabaseConnectionsSQL() + { + $this->assertSame( + "UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'foo'", + $this->_platform->getDisallowDatabaseConnectionsSQL('foo') + ); + } + + /** + * @group DBAL-1220 + */ + public function testReturnsCloseActiveDatabaseConnectionsSQL() + { + $this->assertSame( + "SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = 'foo'", + $this->_platform->getCloseActiveDatabaseConnectionsSQL('foo') + ); + } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php index 083df4beead..2ec361242b1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php @@ -56,4 +56,15 @@ public function testInitializesJsonTypeMapping() $this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('json')); $this->assertEquals('json_array', $this->_platform->getDoctrineTypeMapping('json')); } + + /** + * @group DBAL-1220 + */ + public function testReturnsCloseActiveDatabaseConnectionsSQL() + { + $this->assertSame( + "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'foo'", + $this->_platform->getCloseActiveDatabaseConnectionsSQL('foo') + ); + } } From 3b50eb21cd78e974477995a475dfe4846bd9294d Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Wed, 17 Jun 2015 11:18:41 -0400 Subject: [PATCH 12/70] Add conversion exception when date and time type convertToDatabaseValue methods are passed non-null values that are not DateTime instances. --- .../DBAL/Types/ConversionException.php | 25 +++++++++++++++++++ lib/Doctrine/DBAL/Types/DateTimeType.php | 4 +++ lib/Doctrine/DBAL/Types/DateTimeTzType.php | 4 +++ lib/Doctrine/DBAL/Types/DateType.php | 4 +++ lib/Doctrine/DBAL/Types/TimeType.php | 4 +++ tests/Doctrine/Tests/DBAL/Types/DateTest.php | 18 +++++++++++++ .../Tests/DBAL/Types/DateTimeTest.php | 19 ++++++++++++++ .../Tests/DBAL/Types/DateTimeTzTest.php | 19 ++++++++++++++ tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 18 +++++++++++++ 9 files changed, 115 insertions(+) diff --git a/lib/Doctrine/DBAL/Types/ConversionException.php b/lib/Doctrine/DBAL/Types/ConversionException.php index 4675101b305..e0cc64b04d1 100644 --- a/lib/Doctrine/DBAL/Types/ConversionException.php +++ b/lib/Doctrine/DBAL/Types/ConversionException.php @@ -65,4 +65,29 @@ static public function conversionFailedFormat($value, $toType, $expectedFormat) $toType . '. Expected format: ' . $expectedFormat ); } + + /** + * Thrown when the PHP value passed to the converter was not of the expected type. + * + * @param mixed $value + * @param string $fromType + * + * @return \Doctrine\DBAL\Types\ConversionException + */ + static public function conversionFailedInvalidType($value, $toType, $fromType) + { + $actualType = gettype($value); + if ($actualType === 'object') { + $actualType .= " (" . get_class($value) . ")"; + if (!method_exists($value, '__toString')) { + $value = 'object'; + } + } + $value = (string)$value; + $value = (strlen($value) > 32) ? substr($value, 0, 20) . "..." : $value; + + return new self( + "Could not convert PHP value '$value' of type '$actualType' to type $toType. Expected type: $fromType" + ); + } } diff --git a/lib/Doctrine/DBAL/Types/DateTimeType.php b/lib/Doctrine/DBAL/Types/DateTimeType.php index c5715a795c0..07b08b6b3b5 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeType.php @@ -49,6 +49,10 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { + if ($value !== null && !$value instanceof \DateTime) { + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), "DateTime"); + } + return ($value !== null) ? $value->format($platform->getDateTimeFormatString()) : null; } diff --git a/lib/Doctrine/DBAL/Types/DateTimeTzType.php b/lib/Doctrine/DBAL/Types/DateTimeTzType.php index 2a9c6fa7b74..d8c1c046813 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeTzType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeTzType.php @@ -67,6 +67,10 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { + if ($value !== null && !$value instanceof \DateTime) { + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), "DateTime"); + } + return ($value !== null) ? $value->format($platform->getDateTimeTzFormatString()) : null; } diff --git a/lib/Doctrine/DBAL/Types/DateType.php b/lib/Doctrine/DBAL/Types/DateType.php index 9d337558639..582ca5c7c9a 100644 --- a/lib/Doctrine/DBAL/Types/DateType.php +++ b/lib/Doctrine/DBAL/Types/DateType.php @@ -49,6 +49,10 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { + if ($value !== null && !$value instanceof \DateTime) { + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), "DateTime"); + } + return ($value !== null) ? $value->format($platform->getDateFormatString()) : null; } diff --git a/lib/Doctrine/DBAL/Types/TimeType.php b/lib/Doctrine/DBAL/Types/TimeType.php index 554d56dc062..b9178df8c8f 100644 --- a/lib/Doctrine/DBAL/Types/TimeType.php +++ b/lib/Doctrine/DBAL/Types/TimeType.php @@ -49,6 +49,10 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { + if ($value !== null && !$value instanceof \DateTime) { + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), "DateTime"); + } + return ($value !== null) ? $value->format($platform->getTimeFormatString()) : null; } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index f90ebb581ca..fff53a7e474 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -31,6 +31,24 @@ public function testDateConvertsToDatabaseValue() ); } + /** + * @expectedException \Doctrine\DBAL\Types\ConversionException + */ + public function testInvalidDateTimeValueInteger() + { + $date = 27; + $this->_type->convertToDatabaseValue($date, $this->_platform); + } + + /** + * @expectedException \Doctrine\DBAL\Types\ConversionException + */ + public function testInvalidDateTimeValueStdClass() + { + $date = new \stdClass(); + $this->_type->convertToDatabaseValue($date, $this->_platform); + } + public function testDateConvertsToPHPValue() { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index 3fac40c13d0..c5543201668 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; @@ -27,6 +28,24 @@ public function testDateTimeConvertsToDatabaseValue() $this->assertEquals($expected, $actual); } + /** + * @expectedException \Doctrine\DBAL\Types\ConversionException + */ + public function testInvalidDateTimeValueInteger() + { + $date = 27; + $this->_type->convertToDatabaseValue($date, $this->_platform); + } + + /** + * @expectedException \Doctrine\DBAL\Types\ConversionException + */ + public function testInvalidDateTimeValueStdClass() + { + $date = new \stdClass(); + $this->_type->convertToDatabaseValue($date, $this->_platform); + } + public function testDateTimeConvertsToPHPValue() { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index cf9c4779a8c..f84f223845f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -27,6 +27,25 @@ public function testDateTimeConvertsToDatabaseValue() $this->assertEquals($expected, $actual); } + /** + * @expectedException \Doctrine\DBAL\Types\ConversionException + */ + public function testInvalidDateTimeValueInteger() + { + $date = 27; + $this->_type->convertToDatabaseValue($date, $this->_platform); + } + + /** + * @expectedException \Doctrine\DBAL\Types\ConversionException + */ + public function testInvalidDateTimeValueStdClass() + { + $date = new \stdClass(); + $this->_type->convertToDatabaseValue($date, $this->_platform); + } + + public function testDateTimeConvertsToPHPValue() { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index 6ba6b9f9221..c721462af9c 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -24,6 +24,24 @@ public function testTimeConvertsToDatabaseValue() ); } + /** + * @expectedException \Doctrine\DBAL\Types\ConversionException + */ + public function testInvalidDateTimeValueInteger() + { + $date = 27; + $this->_type->convertToDatabaseValue($date, $this->_platform); + } + + /** + * @expectedException \Doctrine\DBAL\Types\ConversionException + */ + public function testInvalidDateTimeValueStdClass() + { + $date = new \stdClass(); + $this->_type->convertToDatabaseValue($date, $this->_platform); + } + public function testTimeConvertsToPHPValue() { $this->assertTrue( From 4aa4f06c70a5ed564ccd911438ae65140f0edf31 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Thu, 23 Jul 2015 10:07:28 +0900 Subject: [PATCH 13/70] Add test for MariaDB 5.5, 10.0 and 10.1 on Travis --- .travis.yml | 75 +++++++++++++++++++++++++++++++++ tests/travis/mariadb.travis.xml | 31 ++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 tests/travis/mariadb.travis.xml diff --git a/.travis.yml b/.travis.yml index 6dffaf89733..80ba6043d44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,81 @@ before_script: script: ./vendor/bin/phpunit --configuration tests/travis/$DB.travis.xml matrix: + include: + - php: 5.3 + env: DB=mariadb + addons: + mariadb: 5.5 + - php: 5.4 + env: DB=mariadb + addons: + mariadb: 5.5 + - php: 5.5 + env: DB=mariadb + addons: + mariadb: 5.5 + - php: 5.6 + env: DB=mariadb + addons: + mariadb: 5.5 + - php: 7.0 + env: DB=mariadb + addons: + mariadb: 5.5 + - php: hhvm + env: DB=mariadb + addons: + mariadb: 5.5 + + - php: 5.3 + env: DB=mariadb + addons: + mariadb: 10.0 + - php: 5.4 + env: DB=mariadb + addons: + mariadb: 10.0 + - php: 5.5 + env: DB=mariadb + addons: + mariadb: 10.0 + - php: 5.6 + env: DB=mariadb + addons: + mariadb: 10.0 + - php: 7.0 + env: DB=mariadb + addons: + mariadb: 10.0 + - php: hhvm + env: DB=mariadb + addons: + mariadb: 10.0 + + - php: 5.3 + env: DB=mariadb + addons: + mariadb: 10.1 + - php: 5.4 + env: DB=mariadb + addons: + mariadb: 10.1 + - php: 5.5 + env: DB=mariadb + addons: + mariadb: 10.1 + - php: 5.6 + env: DB=mariadb + addons: + mariadb: 10.1 + - php: 7.0 + env: DB=mariadb + addons: + mariadb: 10.1 + - php: hhvm + env: DB=mariadb + addons: + mariadb: 10.1 allow_failures: - php: 7.0 - php: hhvm diff --git a/tests/travis/mariadb.travis.xml b/tests/travis/mariadb.travis.xml new file mode 100644 index 00000000000..15fab573f0c --- /dev/null +++ b/tests/travis/mariadb.travis.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + ../Doctrine/Tests/DBAL + + + + + performance + locking_functional + + + + + From 6782f30aac9689e5cf61249304b500679a6e7c08 Mon Sep 17 00:00:00 2001 From: janschoenherr Date: Thu, 23 Jul 2015 09:59:31 +0200 Subject: [PATCH 14/70] use REGEXP operator for sqlite --- lib/Doctrine/DBAL/Platforms/SqlitePlatform.php | 2 +- tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index 0694bed4ce8..3d8a09b63ee 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -45,7 +45,7 @@ class SqlitePlatform extends AbstractPlatform */ public function getRegexpExpression() { - return 'RLIKE'; + return 'REGEXP'; } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php index 45fb593755f..f0d00b42523 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php @@ -31,7 +31,7 @@ public function getGenerateTableWithMultiColumnUniqueIndexSql() public function testGeneratesSqlSnippets() { - $this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct'); + $this->assertEquals('REGEXP', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct'); $this->assertEquals('SUBSTR(column, 5, LENGTH(column))', $this->_platform->getSubstringExpression('column', 5), 'Substring expression without length is not correct'); $this->assertEquals('SUBSTR(column, 0, 5)', $this->_platform->getSubstringExpression('column', 0, 5), 'Substring expression with length is not correct'); } From 5e932a5ba1e48fb37cc7c9dbee4ecabc1541f51e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 29 Jul 2015 09:50:04 +0200 Subject: [PATCH 15/70] Allow testing with doctrine/common 2.6 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9d9e7d3b1c5..120d10648da 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "require": { "php": ">=5.3.2", - "doctrine/common": ">=2.4,<2.6-dev" + "doctrine/common": "~2.4" }, "require-dev": { "phpunit/phpunit": "4.*", From 77344ece0b97b62aab9129f052830bec0463ac38 Mon Sep 17 00:00:00 2001 From: Leo Date: Sun, 2 Aug 2015 19:55:53 +0800 Subject: [PATCH 16/70] fixed typo --- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 2 +- lib/Doctrine/DBAL/Schema/Constraint.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index ae75979c30c..48a50bc1c62 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -1044,7 +1044,7 @@ public function getDropTemporaryTableSQL($table) if ($table instanceof Table) { $table = $table->getQuotedName($this); } elseif (!is_string($table)) { - throw new \InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); + throw new \InvalidArgumentException('getDropTemporaryTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); } return 'DROP TEMPORARY TABLE ' . $table; diff --git a/lib/Doctrine/DBAL/Schema/Constraint.php b/lib/Doctrine/DBAL/Schema/Constraint.php index c373472c465..2e68a771019 100644 --- a/lib/Doctrine/DBAL/Schema/Constraint.php +++ b/lib/Doctrine/DBAL/Schema/Constraint.php @@ -22,7 +22,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; /** - * Marker interface for contraints. + * Marker interface for constraints. * * @link www.doctrine-project.org * @since 2.0 From 0e1aac7e6157346afed1c9ddd3ce6dd01909cc3c Mon Sep 17 00:00:00 2001 From: Leo Date: Fri, 14 Aug 2015 01:10:24 +0800 Subject: [PATCH 17/70] refactored class CreateSchemaSqlCollector --- .../Visitor/CreateSchemaSqlCollector.php | 42 ++++--------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php index 5e0c6ed437e..ba196d0b4d6 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php @@ -66,10 +66,7 @@ public function __construct(AbstractPlatform $platform) public function acceptNamespace($namespaceName) { if ($this->platform->supportsSchemas()) { - $this->createNamespaceQueries = array_merge( - $this->createNamespaceQueries, - (array) $this->platform->getCreateSchemaSQL($namespaceName) - ); + $this->createNamespaceQueries[] = $this->platform->getCreateSchemaSQL($namespaceName); } } @@ -87,12 +84,7 @@ public function acceptTable(Table $table) public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) { if ($this->platform->supportsForeignKeyConstraints()) { - $this->createFkConstraintQueries = array_merge( - $this->createFkConstraintQueries, - (array) $this->platform->getCreateForeignKeySQL( - $fkConstraint, $localTable - ) - ); + $this->createFkConstraintQueries[] = $this->platform->getCreateForeignKeySQL($fkConstraint, $localTable); } } @@ -101,10 +93,7 @@ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkCons */ public function acceptSequence(Sequence $sequence) { - $this->createSequenceQueries = array_merge( - $this->createSequenceQueries, - (array) $this->platform->getCreateSequenceSQL($sequence) - ); + $this->createSequenceQueries[] = $this->platform->getCreateSequenceSQL($sequence); } /** @@ -125,24 +114,11 @@ public function resetQueries() */ public function getQueries() { - $sql = array(); - - foreach ($this->createNamespaceQueries as $schemaSql) { - $sql = array_merge($sql, (array) $schemaSql); - } - - foreach ($this->createTableQueries as $schemaSql) { - $sql = array_merge($sql, (array) $schemaSql); - } - - foreach ($this->createSequenceQueries as $schemaSql) { - $sql = array_merge($sql, (array) $schemaSql); - } - - foreach ($this->createFkConstraintQueries as $schemaSql) { - $sql = array_merge($sql, (array) $schemaSql); - } - - return $sql; + return array_merge( + $this->createNamespaceQueries, + $this->createTableQueries, + $this->createSequenceQueries, + $this->createFkConstraintQueries + ); } } From 6b50e2510a567f0cbc3d53609292adcfff4ec5f9 Mon Sep 17 00:00:00 2001 From: Leo Date: Fri, 14 Aug 2015 01:28:31 +0800 Subject: [PATCH 18/70] fixed the correct mock return values --- .../Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php index 1eb898c242b..b8b2e0486a8 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php @@ -17,10 +17,10 @@ public function testCreateSchema() ->will($this->returnValue(array("foo"))); $platformMock->expects($this->exactly(1)) ->method('getCreateSequenceSql') - ->will($this->returnValue(array("bar"))); + ->will($this->returnValue("bar")); $platformMock->expects($this->exactly(1)) ->method('getCreateForeignKeySql') - ->will($this->returnValue(array("baz"))); + ->will($this->returnValue("baz")); $schema = $this->createFixtureSchema(); @@ -73,4 +73,4 @@ public function createFixtureSchema() return $schema; } -} \ No newline at end of file +} From 029b0bee3f6291f0630d01c93e517f2806f1f895 Mon Sep 17 00:00:00 2001 From: Possum Date: Fri, 21 Aug 2015 11:16:27 +0200 Subject: [PATCH 19/70] remove link to empty download page --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index b18f4c7c103..b67a67e4b44 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ Powerful database abstraction layer with many features for database schema intro * [Website](http://www.doctrine-project.org/projects/dbal.html) * [Documentation](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/) * [Issue Tracker](http://www.doctrine-project.org/jira/browse/DBAL) -* [Downloads](http://github.com/doctrine/dbal/downloads) [Master image]: https://img.shields.io/travis/doctrine/dbal/master.svg?style=flat-square From 561b3985cae5d0bf1a4410e8f0e37c88b68cc501 Mon Sep 17 00:00:00 2001 From: Possum Date: Sun, 23 Aug 2015 09:38:18 +0200 Subject: [PATCH 20/70] typo fixes --- lib/Doctrine/DBAL/Driver/AbstractDriverException.php | 2 +- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php | 4 ++-- lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php | 2 +- lib/Doctrine/DBAL/Schema/Index.php | 2 +- .../DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/AbstractDriverException.php b/lib/Doctrine/DBAL/Driver/AbstractDriverException.php index c5eee5a0735..84b95db10da 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractDriverException.php +++ b/lib/Doctrine/DBAL/Driver/AbstractDriverException.php @@ -46,7 +46,7 @@ abstract class AbstractDriverException extends \Exception implements DriverExcep * Constructor. * * @param string $message The driver error message. - * @param string|null $sqlState The SQLSTATE the driver is in at the time the error occured, if any. + * @param string|null $sqlState The SQLSTATE the driver is in at the time the error occurred, if any. * @param integer|string|null $errorCode The driver specific error code if any. */ public function __construct($message, $sqlState = null, $errorCode = null) diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index 0e809e2f5cf..66fcd3bd4fb 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -39,9 +39,9 @@ class DB2Connection implements Connection, ServerInfoAwareConnection */ public function __construct(array $params, $username, $password, $driverOptions = array()) { - $isPersistant = (isset($params['persistent']) && $params['persistent'] == true); + $isPersistent = (isset($params['persistent']) && $params['persistent'] == true); - if ($isPersistant) { + if ($isPersistent) { $this->_conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions); } else { $this->_conn = db2_connect($params['dbname'], $username, $password, $driverOptions); diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 19dfa9369b4..df3f1df67ba 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -152,7 +152,7 @@ public function listSequences($database = null) * * In contrast to other libraries and to the old version of Doctrine, * this column definition does try to contain the 'primary' field for - * the reason that it is not portable accross different RDBMS. Use + * the reason that it is not portable across different RDBMS. Use * {@see listTableIndexes($tableName)} to retrieve the primary key * of a table. We're a RDBMS specifies more details these are held * in the platformDetails array. diff --git a/lib/Doctrine/DBAL/Schema/Index.php b/lib/Doctrine/DBAL/Schema/Index.php index bc5cd93dc6f..554d80f78b2 100644 --- a/lib/Doctrine/DBAL/Schema/Index.php +++ b/lib/Doctrine/DBAL/Schema/Index.php @@ -215,7 +215,7 @@ public function isFullfilledBy(Index $other) } if ( ! $this->isUnique() && ! $this->isPrimary()) { - // this is a special case: If the current key is neither primary or unique, any uniqe or + // this is a special case: If the current key is neither primary or unique, any unique or // primary key will always have the same effect for the index and there cannot be any constraint // overlaps. This means a primary or unique index can always fulfill the requirements of just an // index that has no constraints. diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php index c1a524f76a4..d60160c39f7 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php @@ -41,8 +41,8 @@ * - You always have to work with `filtering=On` when using federations with this * multi-tenant approach. * - Primary keys are either using globally unique ids (GUID, Table Generator) - * or you explicitly add the tenent_id in every UPDATE or DELETE statement - * (otherwise they will affect the same-id rows from other tenents as well). + * or you explicitly add the tenant_id in every UPDATE or DELETE statement + * (otherwise they will affect the same-id rows from other tenants as well). * SQLAzure throws errors when you try to create IDENTIY columns on federated * tables. * From 4cbb248230c50bfc707c5911215a9d075401eb6f Mon Sep 17 00:00:00 2001 From: Possum Date: Sun, 23 Aug 2015 10:07:41 +0200 Subject: [PATCH 21/70] Typos in tests. --- .../Tests/DBAL/Functional/DataAccessTest.php | 6 +++--- .../Tests/DBAL/Functional/ExceptionTest.php | 8 ++++---- .../Schema/SQLServerSchemaManagerTest.php | 6 +++--- .../DBAL/Platforms/AbstractPlatformTestCase.php | 2 +- .../AbstractPostgreSqlPlatformTestCase.php | 4 ++-- .../AbstractSQLServerPlatformTestCase.php | 6 +++--- .../Tests/DBAL/Schema/ComparatorTest.php | 16 ++++++++-------- tests/Doctrine/Tests/DBAL/Schema/IndexTest.php | 8 ++++---- tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php | 2 +- .../DBAL/Sharding/PoolingShardConnectionTest.php | 4 ++-- .../SQLAzure/SQLAzureShardManagerTest.php | 2 +- 11 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index 14b1c988ba0..bbc9d8f4337 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -533,11 +533,11 @@ public function testDateArithmetics() $this->assertEquals('2010-01-08', date('Y-m-d', strtotime($row['add_weeks'])), "Adding week should end up on 2010-01-08"); $this->assertEquals('2009-12-25', date('Y-m-d', strtotime($row['sub_weeks'])), "Subtracting week should end up on 2009-12-25"); $this->assertEquals('2010-03-01', date('Y-m-d', strtotime($row['add_month'])), "Adding month should end up on 2010-03-01"); - $this->assertEquals('2009-11-01', date('Y-m-d', strtotime($row['sub_month'])), "Substracting month should end up on 2009-11-01"); + $this->assertEquals('2009-11-01', date('Y-m-d', strtotime($row['sub_month'])), "Subtracting month should end up on 2009-11-01"); $this->assertEquals('2010-10-01', date('Y-m-d', strtotime($row['add_quarters'])), "Adding quarters should end up on 2010-04-01"); - $this->assertEquals('2009-04-01', date('Y-m-d', strtotime($row['sub_quarters'])), "Substracting quarters should end up on 2009-10-01"); + $this->assertEquals('2009-04-01', date('Y-m-d', strtotime($row['sub_quarters'])), "Subtracting quarters should end up on 2009-10-01"); $this->assertEquals('2016-01-01', date('Y-m-d', strtotime($row['add_years'])), "Adding years should end up on 2016-01-01"); - $this->assertEquals('2004-01-01', date('Y-m-d', strtotime($row['sub_years'])), "Substracting years should end up on 2004-01-01"); + $this->assertEquals('2004-01-01', date('Y-m-d', strtotime($row['sub_years'])), "Subtracting years should end up on 2004-01-01"); } public function testLocateExpression() diff --git a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php index 1d01f8053b6..c63409eba72 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php @@ -56,7 +56,7 @@ public function testTableExistsException() } } - public function testForeignKeyContraintViolationExceptionOnInsert() + public function testForeignKeyConstraintViolationExceptionOnInsert() { if ( ! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped("Only fails on platforms with foreign key constraints."); @@ -80,7 +80,7 @@ public function testForeignKeyContraintViolationExceptionOnInsert() $this->tearDownForeignKeyConstraintViolationExceptionTest(); } - public function testForeignKeyContraintViolationExceptionOnUpdate() + public function testForeignKeyConstraintViolationExceptionOnUpdate() { if ( ! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped("Only fails on platforms with foreign key constraints."); @@ -104,7 +104,7 @@ public function testForeignKeyContraintViolationExceptionOnUpdate() $this->tearDownForeignKeyConstraintViolationExceptionTest(); } - public function testForeignKeyContraintViolationExceptionOnDelete() + public function testForeignKeyConstraintViolationExceptionOnDelete() { if ( ! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped("Only fails on platforms with foreign key constraints."); @@ -128,7 +128,7 @@ public function testForeignKeyContraintViolationExceptionOnDelete() $this->tearDownForeignKeyConstraintViolationExceptionTest(); } - public function testForeignKeyContraintViolationExceptionOnTruncate() + public function testForeignKeyConstraintViolationExceptionOnTruncate() { $platform = $this->_conn->getDatabasePlatform(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php index da51840c73a..8c654ba4bd3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php @@ -53,7 +53,7 @@ public function testColumnCollation() $this->assertEquals($collation, $columns[$columnName]->getPlatformOption('collation')); } - public function testDefaultContraints() + public function testDefaultConstraints() { $table = new Table('sqlsrv_default_constraints'); $table->addColumn('no_default', 'string'); @@ -179,7 +179,7 @@ public function testColumnComments() $table->addColumn('comment_float_0', 'integer', array('comment' => 0.0)); $table->addColumn('comment_string_0', 'integer', array('comment' => '0')); $table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!')); - $table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitely quoted columns!')); + $table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitly quoted columns!')); $table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')); $table->addColumn('commented_type', 'object'); $table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.')); @@ -197,7 +197,7 @@ public function testColumnComments() $this->assertEquals('0', $columns['comment_float_0']->getComment()); $this->assertEquals('0', $columns['comment_string_0']->getComment()); $this->assertEquals('Doctrine 0wnz you!', $columns['comment']->getComment()); - $this->assertEquals('Doctrine 0wnz comments for explicitely quoted columns!', $columns['comment_quoted']->getComment()); + $this->assertEquals('Doctrine 0wnz comments for explicitly quoted columns!', $columns['comment_quoted']->getComment()); $this->assertEquals('Doctrine 0wnz comments for reserved keyword columns!', $columns['[create]']->getComment()); $this->assertNull($columns['commented_type']->getComment()); $this->assertEquals('Doctrine array type.', $columns['commented_type_with_comment']->getComment()); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index b0917617fc0..9807d066845 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -83,7 +83,7 @@ public function getReturnsForeignKeyReferentialActionSQL() ); } - public function testGetInvalidtForeignKeyReferentialActionSQL() + public function testGetInvalidForeignKeyReferentialActionSQL() { $this->setExpectedException('InvalidArgumentException'); $this->_platform->getForeignKeyReferentialActionSQL('unknown'); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 29295c25a08..17ee9e4bcf7 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -303,7 +303,7 @@ protected function getQuotedColumnInForeignKeySQL() * @dataProvider pgBooleanProvider * * @param string $databaseValue - * @param string $prepareStatementValue + * @param string $preparedStatementValue * @param integer $integerValue * @param boolean $booleanValue */ @@ -338,7 +338,7 @@ public function testConvertBooleanAsLiteralIntegers() * @dataProvider pgBooleanProvider * * @param string $databaseValue - * @param string $prepareStatementValue + * @param string $preparedStatementValue * @param integer $integerValue * @param boolean $booleanValue */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index cc59e4a72a2..f20d0a310a3 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -529,7 +529,7 @@ public function testGeneratesCreateTableSQLWithColumnComments() $table->addColumn('comment_float_0', 'integer', array('comment' => 0.0)); $table->addColumn('comment_string_0', 'integer', array('comment' => '0')); $table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!')); - $table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitely quoted columns!')); + $table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitly quoted columns!')); $table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')); $table->addColumn('commented_type', 'object'); $table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.')); @@ -543,7 +543,7 @@ public function testGeneratesCreateTableSQLWithColumnComments() "EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_float_0", "EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_string_0", "EXEC sp_addextendedproperty N'MS_Description', N'Doctrine 0wnz you!', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment", - "EXEC sp_addextendedproperty N'MS_Description', N'Doctrine 0wnz comments for explicitely quoted columns!', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [comment_quoted]", + "EXEC sp_addextendedproperty N'MS_Description', N'Doctrine 0wnz comments for explicitly quoted columns!', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [comment_quoted]", "EXEC sp_addextendedproperty N'MS_Description', N'Doctrine 0wnz comments for reserved keyword columns!', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [create]", "EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:object)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', commented_type", "EXEC sp_addextendedproperty N'MS_Description', N'Doctrine array type.(DC2Type:array)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', commented_type_with_comment", @@ -568,7 +568,7 @@ public function testGeneratesAlterTableSQLWithColumnComments() $table->addColumn('comment_float_0', 'integer', array('comment' => 0.0)); $table->addColumn('comment_string_0', 'integer', array('comment' => '0')); $table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!')); - $table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitely quoted columns!')); + $table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitly quoted columns!')); $table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')); $table->addColumn('commented_type', 'object'); $table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.')); diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index e8d6facff3f..dd346a5d8d6 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -570,7 +570,7 @@ public function testTablesCaseInsensitive() $this->assertSchemaTableChangeCount($diff, 1, 0, 1); } - public function testSequencesCaseInsenstive() + public function testSequencesCaseInsensitive() { $schemaA = new Schema(); $schemaA->createSequence('foo'); @@ -680,7 +680,7 @@ public function testDetectRenameColumn() } /** - * You can easily have ambiguouties in the column renaming. If these + * You can easily have ambiguities in the column renaming. If these * are detected no renaming should take place, instead adding and dropping * should be used exclusively. * @@ -700,7 +700,7 @@ public function testDetectRenameColumnAmbiguous() $this->assertEquals(1, count($tableDiff->addedColumns), "'baz' should be added, not created through renaming!"); $this->assertArrayHasKey('baz', $tableDiff->addedColumns, "'baz' should be added, not created through renaming!"); - $this->assertEquals(2, count($tableDiff->removedColumns), "'foo' and 'bar' should both be dropped, an ambigouty exists which one could be renamed to 'baz'."); + $this->assertEquals(2, count($tableDiff->removedColumns), "'foo' and 'bar' should both be dropped, an ambiguity exists which one could be renamed to 'baz'."); $this->assertArrayHasKey('foo', $tableDiff->removedColumns, "'foo' should be removed."); $this->assertArrayHasKey('bar', $tableDiff->removedColumns, "'bar' should be removed."); $this->assertEquals(0, count($tableDiff->renamedColumns), "no renamings should take place."); @@ -840,7 +840,7 @@ public function testDiffDecimalWithNullPrecision() /** * @group DBAL-204 */ - public function testFqnSchemaComparision() + public function testFqnSchemaComparison() { $config = new SchemaConfig(); $config->setName("foo"); @@ -887,7 +887,7 @@ public function testNamespacesComparison() /** * @group DBAL-204 */ - public function testFqnSchemaComparisionDifferentSchemaNameButSameTableNoDiff() + public function testFqnSchemaComparisonDifferentSchemaNameButSameTableNoDiff() { $config = new SchemaConfig(); $config->setName("foo"); @@ -907,7 +907,7 @@ public function testFqnSchemaComparisionDifferentSchemaNameButSameTableNoDiff() /** * @group DBAL-204 */ - public function testFqnSchemaComparisionNoSchemaSame() + public function testFqnSchemaComparisonNoSchemaSame() { $config = new SchemaConfig(); $config->setName("foo"); @@ -926,7 +926,7 @@ public function testFqnSchemaComparisionNoSchemaSame() /** * @group DDC-1657 */ - public function testAutoIncremenetSequences() + public function testAutoIncrementSequences() { $oldSchema = new Schema(); $table = $oldSchema->createTable("foo"); @@ -950,7 +950,7 @@ public function testAutoIncremenetSequences() * Check that added autoincrement sequence is not populated in newSequences * @group DBAL-562 */ - public function testAutoIncremenetNoSequences() + public function testAutoIncrementNoSequences() { $oldSchema = new Schema(); $table = $oldSchema->createTable("foo"); diff --git a/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php b/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php index 5c92121c309..088905dcb62 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php @@ -39,7 +39,7 @@ public function testCreateUnique() /** * @group DBAL-50 */ - public function testFullfilledByUnique() + public function testFulfilledByUnique() { $idx1 = $this->createIndex(true, false); $idx2 = $this->createIndex(true, false); @@ -52,7 +52,7 @@ public function testFullfilledByUnique() /** * @group DBAL-50 */ - public function testFullfilledByPrimary() + public function testFulfilledByPrimary() { $idx1 = $this->createIndex(true, true); $idx2 = $this->createIndex(true, true); @@ -65,7 +65,7 @@ public function testFullfilledByPrimary() /** * @group DBAL-50 */ - public function testFullfilledByIndex() + public function testFulfilledByIndex() { $idx1 = $this->createIndex(); $idx2 = $this->createIndex(); @@ -77,7 +77,7 @@ public function testFullfilledByIndex() $this->assertTrue($idx1->isFullfilledBy($uniq)); } - public function testFullfilledWithPartial() + public function testFulfilledWithPartial() { $without = new Index('without', array('col1', 'col2'), true, false, array(), array()); $partial = new Index('partial', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL')); diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php index f17f0ca6f25..c6cbee5e3bb 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php @@ -24,7 +24,7 @@ public function testAddTable() $this->assertTrue($schema->hasTable($tableName)); } - public function testTableMatchingCaseInsenstive() + public function testTableMatchingCaseInsensitive() { $table = new Table("Foo"); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php index c0a446bddf1..d77c11d2a47 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php @@ -72,7 +72,7 @@ public function testNoGlobalServerException() )); } - public function testNoShardsServersExecption() + public function testNoShardsServersException() { $this->setExpectedException('InvalidArgumentException', "Connection Parameters require 'global' and 'shards' configurations."); @@ -84,7 +84,7 @@ public function testNoShardsServersExecption() )); } - public function testNoShardsChoserExecption() + public function testNoShardsChoserException() { $this->setExpectedException('InvalidArgumentException', "Missing Shard Choser configuration 'shardChoser'"); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php index f73e494081a..7790086a11d 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php @@ -72,7 +72,7 @@ public function testSelectShard() $this->assertEquals(1234, $sm->getCurrentDistributionValue()); } - public function testSelectShardNoDistriubtionValue() + public function testSelectShardNoDistributionValue() { $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false)); From fc4dc7c833fe0ff4254fcfaca93bf3d4a1ad0885 Mon Sep 17 00:00:00 2001 From: Valentas Date: Fri, 28 Aug 2015 14:47:56 +0300 Subject: [PATCH 22/70] requiresSQLCommentHint in DateIntervalType According to comment https://github.com/doctrine/dbal/pull/854#issuecomment-126935212 --- lib/Doctrine/DBAL/Types/DateIntervalType.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/Doctrine/DBAL/Types/DateIntervalType.php b/lib/Doctrine/DBAL/Types/DateIntervalType.php index 8b2c18e4710..d71b8e7283e 100644 --- a/lib/Doctrine/DBAL/Types/DateIntervalType.php +++ b/lib/Doctrine/DBAL/Types/DateIntervalType.php @@ -67,4 +67,12 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return $interval; } + + /** + * {@inheritdoc} + */ + public function requiresSQLCommentHint(AbstractPlatform $platform) + { + return true; + } } From 69963f62c90d6c6f287637780c840a7c95aac760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentinas=20Bartusevi=C4=8Dius?= Date: Mon, 31 Aug 2015 18:21:11 +0300 Subject: [PATCH 23/70] SchemaManager test added --- .../SchemaManagerFunctionalTestCase.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 3a9bf61b294..dbeecab8480 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -736,6 +736,31 @@ public function testAutomaticallyAppendCommentOnMarkedColumns() $this->assertInstanceOf('Doctrine\DBAL\Types\ArrayType', $columns['arr']->getType(), "The Doctrine2 should be detected from comment hint."); } + /** + * @group DBAL-1228 + */ + public function testCommentHintOnDateIntervalTypeColumn() + { + if ( ! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && + ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && + $this->_conn->getDatabasePlatform()->getName() != 'mssql') { + $this->markTestSkipped('Database does not support column comments.'); + } + + $table = new Table('column_dateinterval_comment'); + $table->addColumn('id', 'integer', array('comment' => 'This is a comment')); + $table->addColumn('date_interval', 'dateinterval', array('comment' => 'This is a comment')); + $table->setPrimaryKey(array('id')); + + $this->_sm->createTable($table); + + $columns = $this->_sm->listTableColumns("column_dateinterval_comment"); + $this->assertEquals(2, count($columns)); + $this->assertEquals('This is a comment', $columns['id']->getComment()); + $this->assertEquals('This is a comment', $columns['date_interval']->getComment(), "The Doctrine2 Typehint should be stripped from comment."); + $this->assertInstanceOf('Doctrine\DBAL\Types\DateIntervalType', $columns['date_interval']->getType(), "The Doctrine2 should be detected from comment hint."); + } + /** * @group DBAL-825 */ From c3d454664449df5a6df199aea043af570e9b3d5d Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Thu, 3 Sep 2015 13:46:17 -0400 Subject: [PATCH 24/70] Update docs dependency install script for Ubuntu 14.04, also update docs readme to specify Ubuntu 14.04 --- docs/README.md | 3 ++- docs/bin/install-dependencies.sh | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8b42be3833f..ec42877ec67 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,7 @@ # Doctrine DBAL Documentation -## How to Generate +## How to Generate: +Using Ubuntu 14.04 LTS: 1. Run ./bin/install-dependencies.sh 2. Run ./bin/generate-docs.sh diff --git a/docs/bin/install-dependencies.sh b/docs/bin/install-dependencies.sh index 86b3bdff7bf..9ee43bd07a0 100644 --- a/docs/bin/install-dependencies.sh +++ b/docs/bin/install-dependencies.sh @@ -1,4 +1,2 @@ #!/bin/bash -sudo apt-get install python25 python25-dev texlive-full rubber -sudo easy_install pygments -sudo easy_install sphinx \ No newline at end of file +sudo apt-get update && sudo apt-get install -y python2.7 python-sphinx python-pygments \ No newline at end of file From bf05595c9d9b73f5e205a1360d102c61ed0e3a7a Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Thu, 3 Sep 2015 13:56:27 -0400 Subject: [PATCH 25/70] Add bit to docs readme about the theme submodule --- docs/README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index ec42877ec67..4945e9de7df 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,4 +6,13 @@ Using Ubuntu 14.04 LTS: 1. Run ./bin/install-dependencies.sh 2. Run ./bin/generate-docs.sh -It will generate the documentation into the build directory of the checkout. \ No newline at end of file +It will generate the documentation into the build directory of the checkout. + + +## Theme issues + +If you get a "Theme error", check if the `en/_theme` subdirectory is empty, +in which case you will need to run: + +1. git submodule init +2. git submodule update \ No newline at end of file From 1369b0f4f01f6984348bd2da4f28ce1c00b7b132 Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Thu, 3 Sep 2015 16:01:58 -0400 Subject: [PATCH 26/70] Update copyright date on docs, change docs version to read '2' instead of '2.1.0' - matches orm --- docs/en/conf.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/conf.py b/docs/en/conf.py index 3265f58ca5d..964e208b184 100644 --- a/docs/en/conf.py +++ b/docs/en/conf.py @@ -38,16 +38,16 @@ # General information about the project. project = u'Doctrine DBAL' -copyright = u'2010, Roman Borschel, Guilherme Blanco, Benjamin Eberlei, Jonathan Wage' +copyright = u'2010-2015, Roman Borschel, Guilherme Blanco, Benjamin Eberlei, Jonathan Wage' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '2.1' +version = '2' # The full version, including alpha/beta/rc tags. -release = '2.1.0' +release = '2' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. From 3a2f2f8d7db435759e40e5c49ec2e5f666ec373a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Sat, 5 Sep 2015 14:21:22 +0200 Subject: [PATCH 27/70] add test for SQL comment hint requirement --- tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php index 95f5233a12c..f757759c2e5 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php @@ -44,4 +44,12 @@ public function testDateIntervalNullConversion() { $this->assertNull($this->_type->convertToPHPValue(null, $this->_platform)); } + + /** + * @group DBAL-1288 + */ + public function testRequiresSQLCommentHint() + { + $this->assertTrue($this->_type->requiresSQLCommentHint($this->_platform)); + } } From 0f188647249e78903589d91cc5a91373bffdda34 Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Wed, 15 Jul 2015 10:48:42 -0400 Subject: [PATCH 28/70] drop php 5.3 from travis build matrix --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 80ba6043d44..37e7fa5e03f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.3 - 5.4 - 5.5 - 5.6 From fb2eda8aa4311585fda3650decb32da6e44131cd Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Wed, 15 Jul 2015 11:04:42 -0400 Subject: [PATCH 29/70] Update composer php requirement to >= 5.4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 120d10648da..516d079d16e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ {"name": "Jonathan Wage", "email": "jonwage@gmail.com"} ], "require": { - "php": ">=5.3.2", + "php": ">=5.4", "doctrine/common": "~2.4" }, "require-dev": { From d36037d58bb5220a56e8288a746af3dfdd47381e Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Thu, 3 Sep 2015 14:01:24 -0400 Subject: [PATCH 30/70] Remove comment in security.rst about MySQL with PHP <= 5.3.6 --- docs/en/reference/security.rst | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/docs/en/reference/security.rst b/docs/en/reference/security.rst index 9cb4ded7cae..29fb7d9a35a 100644 --- a/docs/en/reference/security.rst +++ b/docs/en/reference/security.rst @@ -154,21 +154,4 @@ the ``Connection#quote`` method: $sql = "SELECT * FROM users WHERE name = " . $connection->quote($_GET['username'], \PDO::PARAM_STR); This method is only available for SQL, not for DQL. For DQL it is always encouraged to use prepared -statements not only for security, but also for caching reasons. - -Non-ASCII compatible Charsets in MySQL --------------------------------------- - -Up until PHP 5.3.6 PDO has a security problem when using non ascii compatible charsets. Even if specifying -the charset using "SET NAMES", emulated prepared statements and ``PDO#quote`` could not reliably escape -values, opening up to potential SQL injections. If you are running PHP 5.3.6 you can solve this issue -by passing the driver option "charset" to Doctrine PDO MySQL driver. Using SET NAMES does not suffice! - -.. code-block:: - - 'pdo_mysql', - 'charset' => 'UTF8', - )); - +statements not only for security, but also for caching reasons. \ No newline at end of file From 190c0e5c1c15df36e15cca099e8a667dcea8272b Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Sat, 5 Sep 2015 10:20:13 -0400 Subject: [PATCH 31/70] Remove php 5.3 mariadb matrix entries --- .travis.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 37e7fa5e03f..5d2223e955c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,10 +29,6 @@ script: ./vendor/bin/phpunit --configuration tests/travis/$DB.travis.xml matrix: include: - - php: 5.3 - env: DB=mariadb - addons: - mariadb: 5.5 - php: 5.4 env: DB=mariadb addons: @@ -54,10 +50,6 @@ matrix: addons: mariadb: 5.5 - - php: 5.3 - env: DB=mariadb - addons: - mariadb: 10.0 - php: 5.4 env: DB=mariadb addons: @@ -79,10 +71,6 @@ matrix: addons: mariadb: 10.0 - - php: 5.3 - env: DB=mariadb - addons: - mariadb: 10.1 - php: 5.4 env: DB=mariadb addons: From 9f72045a5e5161dca7466d90ccf9079bb51c8c6f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 17:54:03 +0200 Subject: [PATCH 32/70] #869 - DBAL-1293 - simplified conversion logic for readability --- lib/Doctrine/DBAL/Types/DateTimeType.php | 11 +++++++---- lib/Doctrine/DBAL/Types/DateTimeTzType.php | 13 ++++++++----- lib/Doctrine/DBAL/Types/DateType.php | 11 +++++++---- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/Doctrine/DBAL/Types/DateTimeType.php b/lib/Doctrine/DBAL/Types/DateTimeType.php index 07b08b6b3b5..07633834d42 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeType.php @@ -49,12 +49,15 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if ($value !== null && !$value instanceof \DateTime) { - throw ConversionException::conversionFailedInvalidType($value, $this->getName(), "DateTime"); + if (null === $value) { + return $value; + } + + if ($value instanceof \DateTime) { + return $value->format($platform->getDateTimeFormatString()); } - return ($value !== null) - ? $value->format($platform->getDateTimeFormatString()) : null; + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), 'DateTime'); } /** diff --git a/lib/Doctrine/DBAL/Types/DateTimeTzType.php b/lib/Doctrine/DBAL/Types/DateTimeTzType.php index d8c1c046813..ab6c2e72d82 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeTzType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeTzType.php @@ -67,12 +67,15 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if ($value !== null && !$value instanceof \DateTime) { - throw ConversionException::conversionFailedInvalidType($value, $this->getName(), "DateTime"); + if (null === $value) { + return $value; + } + + if ($value instanceof \DateTime) { + return $value->format($platform->getDateTimeTzFormatString()); } - - return ($value !== null) - ? $value->format($platform->getDateTimeTzFormatString()) : null; + + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), 'DateTime'); } /** diff --git a/lib/Doctrine/DBAL/Types/DateType.php b/lib/Doctrine/DBAL/Types/DateType.php index 582ca5c7c9a..8658a7a19f5 100644 --- a/lib/Doctrine/DBAL/Types/DateType.php +++ b/lib/Doctrine/DBAL/Types/DateType.php @@ -49,12 +49,15 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if ($value !== null && !$value instanceof \DateTime) { - throw ConversionException::conversionFailedInvalidType($value, $this->getName(), "DateTime"); + if (null === $value) { + return $value; + } + + if ($value instanceof \DateTime) { + return $value->format($platform->getDateFormatString()); } - return ($value !== null) - ? $value->format($platform->getDateFormatString()) : null; + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), 'DateTime'); } /** From 35a4dfb2f33f00c55ed22d3aaadbd93cf3784749 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 18:04:02 +0200 Subject: [PATCH 33/70] #869 - DBAL-1293 - simplified conversion logic for readability (TimeType) --- lib/Doctrine/DBAL/Types/TimeType.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/DBAL/Types/TimeType.php b/lib/Doctrine/DBAL/Types/TimeType.php index b9178df8c8f..c794e3f194c 100644 --- a/lib/Doctrine/DBAL/Types/TimeType.php +++ b/lib/Doctrine/DBAL/Types/TimeType.php @@ -49,12 +49,15 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if ($value !== null && !$value instanceof \DateTime) { - throw ConversionException::conversionFailedInvalidType($value, $this->getName(), "DateTime"); + if (null === $value) { + return $value; + } + + if ($value instanceof \DateTime) { + return $value->format($platform->getTimeFormatString()); } - return ($value !== null) - ? $value->format($platform->getTimeFormatString()) : null; + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), 'DateTime'); } /** From 7e80ad87e22f32c1a7037b2f613bfd1cf82a2aeb Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 18:05:13 +0200 Subject: [PATCH 34/70] #869 - DBAL-1293 - Correcting tests around the invalid date/time formats to use `setExpectedException` --- tests/Doctrine/Tests/DBAL/Types/DateTest.php | 16 ++++------ .../Tests/DBAL/Types/DateTimeTest.php | 29 ++++++++++--------- .../Tests/DBAL/Types/DateTimeTzTest.php | 29 ++++++++++--------- tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 28 +++++++++--------- 4 files changed, 51 insertions(+), 51 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index fff53a7e474..f713f6ff3b0 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -31,22 +31,18 @@ public function testDateConvertsToDatabaseValue() ); } - /** - * @expectedException \Doctrine\DBAL\Types\ConversionException - */ public function testInvalidDateTimeValueInteger() { - $date = 27; - $this->_type->convertToDatabaseValue($date, $this->_platform); + $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); + + $this->_type->convertToDatabaseValue(27, $this->_platform); } - /** - * @expectedException \Doctrine\DBAL\Types\ConversionException - */ public function testInvalidDateTimeValueStdClass() { - $date = new \stdClass(); - $this->_type->convertToDatabaseValue($date, $this->_platform); + $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); + + $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform); } public function testDateConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index c5543201668..9034142ae10 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -2,15 +2,20 @@ namespace Doctrine\Tests\DBAL\Types; -use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; class DateTimeTest extends \Doctrine\Tests\DbalTestCase { - protected - $_platform, - $_type; + /** + * @var MockPlatform + */ + private $_platform; + + /** + * @var \Doctrine\DBAL\Types\DateTimeType + */ + private $_type; protected function setUp() { @@ -28,22 +33,18 @@ public function testDateTimeConvertsToDatabaseValue() $this->assertEquals($expected, $actual); } - /** - * @expectedException \Doctrine\DBAL\Types\ConversionException - */ public function testInvalidDateTimeValueInteger() { - $date = 27; - $this->_type->convertToDatabaseValue($date, $this->_platform); + $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); + + $this->_type->convertToDatabaseValue(27, $this->_platform); } - /** - * @expectedException \Doctrine\DBAL\Types\ConversionException - */ public function testInvalidDateTimeValueStdClass() { - $date = new \stdClass(); - $this->_type->convertToDatabaseValue($date, $this->_platform); + $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); + + $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform); } public function testDateTimeConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index f84f223845f..08fdb7de005 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -7,9 +7,15 @@ class DateTimeTzTest extends \Doctrine\Tests\DbalTestCase { - protected - $_platform, - $_type; + /** + * @var MockPlatform + */ + private $_platform; + + /** + * @var \Doctrine\DBAL\Types\DateTimeTzType + */ + private $_type; protected function setUp() { @@ -27,24 +33,19 @@ public function testDateTimeConvertsToDatabaseValue() $this->assertEquals($expected, $actual); } - /** - * @expectedException \Doctrine\DBAL\Types\ConversionException - */ public function testInvalidDateTimeValueInteger() { - $date = 27; - $this->_type->convertToDatabaseValue($date, $this->_platform); + $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); + + $this->_type->convertToDatabaseValue(27, $this->_platform); } - /** - * @expectedException \Doctrine\DBAL\Types\ConversionException - */ public function testInvalidDateTimeValueStdClass() { - $date = new \stdClass(); - $this->_type->convertToDatabaseValue($date, $this->_platform); - } + $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); + $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform); + } public function testDateTimeConvertsToPHPValue() { diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index c721462af9c..7875067c5f9 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -7,9 +7,15 @@ class TimeTest extends \Doctrine\Tests\DbalTestCase { - protected - $_platform, - $_type; + /** + * @var MockPlatform + */ + private $_platform; + + /** + * @var \Doctrine\DBAL\Types\TimeType + */ + private $_type; protected function setUp() { @@ -24,22 +30,18 @@ public function testTimeConvertsToDatabaseValue() ); } - /** - * @expectedException \Doctrine\DBAL\Types\ConversionException - */ public function testInvalidDateTimeValueInteger() { - $date = 27; - $this->_type->convertToDatabaseValue($date, $this->_platform); + $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); + + $this->_type->convertToDatabaseValue(27, $this->_platform); } - /** - * @expectedException \Doctrine\DBAL\Types\ConversionException - */ public function testInvalidDateTimeValueStdClass() { - $date = new \stdClass(); - $this->_type->convertToDatabaseValue($date, $this->_platform); + $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); + + $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform); } public function testTimeConvertsToPHPValue() From e5202c0f7734be7e9fe3e57cf15cd9065dbc06f9 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 18:11:37 +0200 Subject: [PATCH 35/70] #869 - DBAL-1293 - Using a data provider for invalid type conversions --- tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 33 ++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index 7875067c5f9..9b4373a18de 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -30,18 +30,15 @@ public function testTimeConvertsToDatabaseValue() ); } - public function testInvalidDateTimeValueInteger() - { - $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - - $this->_type->convertToDatabaseValue(27, $this->_platform); - } - - public function testInvalidDateTimeValueStdClass() + /** + * @dataProvider invalidPHPValuesProvider + * @param mixed $value + */ + public function testInvalidTypeConversionToDatabaseValue($value) { $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform); + $this->_type->convertToDatabaseValue($value, $this->_platform); } public function testTimeConvertsToPHPValue() @@ -75,4 +72,22 @@ public function testConvertDateTimeToPHPValue() $date = new \DateTime("now"); $this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform)); } + + /** + * @return mixed[][] + */ + public function invalidPHPValuesProvider() + { + return [ + [0], + [''], + ['foo'], + ['10:11:12'], + [new \stdClass()], + [$this], + [27], + [-1], + [1.2], + ]; + } } From b6d34a613934301ba8a927b14ce0a214dcde6c84 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 18:12:00 +0200 Subject: [PATCH 36/70] #869 - DBAL-1293 - Adding tests for array values --- tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index 9b4373a18de..74ebbc739cf 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -88,6 +88,8 @@ public function invalidPHPValuesProvider() [27], [-1], [1.2], + [[]], + [['an array']], ]; } } From 4e42e4cb969177c218ae8d1df8f6204bab153de4 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 18:15:40 +0200 Subject: [PATCH 37/70] #869 - DBAL-1293 - converting all tests to use a data provider --- tests/Doctrine/Tests/DBAL/Types/DateTest.php | 57 ++++++++++++------- .../Tests/DBAL/Types/DateTimeTest.php | 38 ++++++++++--- .../Tests/DBAL/Types/DateTimeTzTest.php | 38 ++++++++++--- tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 3 + 4 files changed, 99 insertions(+), 37 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index f713f6ff3b0..fdf20d03cd2 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -7,21 +7,20 @@ class DateTest extends \Doctrine\Tests\DbalTestCase { - protected - $_platform, - $_type, - $_tz; + /** + * @var MockPlatform + */ + private $_platform; + + /** + * @var \Doctrine\DBAL\Types\DateType + */ + private $_type; protected function setUp() { $this->_platform = new MockPlatform(); $this->_type = Type::getType('date'); - $this->_tz = date_default_timezone_get(); - } - - public function tearDown() - { - date_default_timezone_set($this->_tz); } public function testDateConvertsToDatabaseValue() @@ -31,18 +30,16 @@ public function testDateConvertsToDatabaseValue() ); } - public function testInvalidDateTimeValueInteger() - { - $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - - $this->_type->convertToDatabaseValue(27, $this->_platform); - } - - public function testInvalidDateTimeValueStdClass() + /** + * @dataProvider invalidPHPValuesProvider + * + * @param mixed $value + */ + public function testInvalidTypeConversionToDatabaseValue($value) { $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform); + $this->_type->convertToDatabaseValue($value, $this->_platform); } public function testDateConvertsToPHPValue() @@ -90,4 +87,26 @@ public function testConvertDateTimeToPHPValue() $date = new \DateTime("now"); $this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform)); } + + /** + * @return mixed[][] + */ + public function invalidPHPValuesProvider() + { + return [ + [0], + [''], + ['foo'], + ['10:11:12'], + ['2015-01-31'], + ['2015-01-31 10:11:12'], + [new \stdClass()], + [$this], + [27], + [-1], + [1.2], + [[]], + [['an array']], + ]; + } } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index 9034142ae10..358689f2887 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -33,18 +33,16 @@ public function testDateTimeConvertsToDatabaseValue() $this->assertEquals($expected, $actual); } - public function testInvalidDateTimeValueInteger() - { - $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - - $this->_type->convertToDatabaseValue(27, $this->_platform); - } - - public function testInvalidDateTimeValueStdClass() + /** + * @dataProvider invalidPHPValuesProvider + * + * @param mixed $value + */ + public function testInvalidTypeConversionToDatabaseValue($value) { $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform); + $this->_type->convertToDatabaseValue($value, $this->_platform); } public function testDateTimeConvertsToPHPValue() @@ -80,4 +78,26 @@ public function testConvertsNonMatchingFormatToPhpValueWithParser() $this->assertEquals('1985-09-01 10:10:10', $actual->format('Y-m-d H:i:s')); } + + /** + * @return mixed[][] + */ + public function invalidPHPValuesProvider() + { + return [ + [0], + [''], + ['foo'], + ['10:11:12'], + ['2015-01-31'], + ['2015-01-31 10:11:12'], + [new \stdClass()], + [$this], + [27], + [-1], + [1.2], + [[]], + [['an array']], + ]; + } } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index 08fdb7de005..529934bf8df 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -33,18 +33,16 @@ public function testDateTimeConvertsToDatabaseValue() $this->assertEquals($expected, $actual); } - public function testInvalidDateTimeValueInteger() - { - $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - - $this->_type->convertToDatabaseValue(27, $this->_platform); - } - - public function testInvalidDateTimeValueStdClass() + /** + * @dataProvider invalidPHPValuesProvider + * + * @param mixed $value + */ + public function testInvalidTypeConversionToDatabaseValue($value) { $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform); + $this->_type->convertToDatabaseValue($value, $this->_platform); } public function testDateTimeConvertsToPHPValue() @@ -71,4 +69,26 @@ public function testConvertDateTimeToPHPValue() $date = new \DateTime("now"); $this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform)); } + + /** + * @return mixed[][] + */ + public function invalidPHPValuesProvider() + { + return [ + [0], + [''], + ['foo'], + ['10:11:12'], + ['2015-01-31'], + ['2015-01-31 10:11:12'], + [new \stdClass()], + [$this], + [27], + [-1], + [1.2], + [[]], + [['an array']], + ]; + } } diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index 74ebbc739cf..c2c772c341e 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -32,6 +32,7 @@ public function testTimeConvertsToDatabaseValue() /** * @dataProvider invalidPHPValuesProvider + * * @param mixed $value */ public function testInvalidTypeConversionToDatabaseValue($value) @@ -83,6 +84,8 @@ public function invalidPHPValuesProvider() [''], ['foo'], ['10:11:12'], + ['2015-01-31'], + ['2015-01-31 10:11:12'], [new \stdClass()], [$this], [27], From 00595fc51dba5eb038eda250078f549d7833ea3a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 18:17:08 +0200 Subject: [PATCH 38/70] #869 - DBAL-1293 - `assertInternalType` over `assertTrue(is_string())` --- tests/Doctrine/Tests/DBAL/Types/DateTest.php | 4 +--- tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index fdf20d03cd2..bc4b16b29a3 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -25,9 +25,7 @@ protected function setUp() public function testDateConvertsToDatabaseValue() { - $this->assertTrue( - is_string($this->_type->convertToDatabaseValue(new \DateTime(), $this->_platform)) - ); + $this->assertInternalType('string', $this->_type->convertToDatabaseValue(new \DateTime(), $this->_platform)); } /** diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index c2c772c341e..226a772c08b 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -25,9 +25,7 @@ protected function setUp() public function testTimeConvertsToDatabaseValue() { - $this->assertTrue( - is_string($this->_type->convertToDatabaseValue(new \DateTime(), $this->_platform)) - ); + $this->assertInternalType('string', $this->_type->convertToDatabaseValue(new \DateTime(), $this->_platform)); } /** From bc0a4a470a7231932b799ed4388d0747d8fd1de0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 18:22:19 +0200 Subject: [PATCH 39/70] #869 - DBAL-1293 - restoring logic around summer time tests --- tests/Doctrine/Tests/DBAL/Types/DateTest.php | 43 ++++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index bc4b16b29a3..e7255eca06b 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -10,22 +10,39 @@ class DateTest extends \Doctrine\Tests\DbalTestCase /** * @var MockPlatform */ - private $_platform; + private $platform; /** * @var \Doctrine\DBAL\Types\DateType */ - private $_type; + private $type; + /** + * @var string + */ + private $currentTimezone; + + /** + * {@inheritDoc} + */ protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('date'); + $this->platform = new MockPlatform(); + $this->type = Type::getType('date'); + $this->currentTimezone = date_default_timezone_get(); + } + + /** + * {@inheritDoc} + */ + protected function tearDown() + { + date_default_timezone_set($this->currentTimezone); } public function testDateConvertsToDatabaseValue() { - $this->assertInternalType('string', $this->_type->convertToDatabaseValue(new \DateTime(), $this->_platform)); + $this->assertInternalType('string', $this->type->convertToDatabaseValue(new \DateTime(), $this->platform)); } /** @@ -37,21 +54,21 @@ public function testInvalidTypeConversionToDatabaseValue($value) { $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - $this->_type->convertToDatabaseValue($value, $this->_platform); + $this->type->convertToDatabaseValue($value, $this->platform); } public function testDateConvertsToPHPValue() { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) $this->assertTrue( - $this->_type->convertToPHPValue('1985-09-01', $this->_platform) + $this->type->convertToPHPValue('1985-09-01', $this->platform) instanceof \DateTime ); } public function testDateResetsNonDatePartsToZeroUnixTimeValues() { - $date = $this->_type->convertToPHPValue('1985-09-01', $this->_platform); + $date = $this->type->convertToPHPValue('1985-09-01', $this->platform); $this->assertEquals('00:00:00', $date->format('H:i:s')); } @@ -60,11 +77,11 @@ public function testDateRests_SummerTimeAffection() { date_default_timezone_set('Europe/Berlin'); - $date = $this->_type->convertToPHPValue('2009-08-01', $this->_platform); + $date = $this->type->convertToPHPValue('2009-08-01', $this->platform); $this->assertEquals('00:00:00', $date->format('H:i:s')); $this->assertEquals('2009-08-01', $date->format('Y-m-d')); - $date = $this->_type->convertToPHPValue('2009-11-01', $this->_platform); + $date = $this->type->convertToPHPValue('2009-11-01', $this->platform); $this->assertEquals('00:00:00', $date->format('H:i:s')); $this->assertEquals('2009-11-01', $date->format('Y-m-d')); } @@ -72,18 +89,18 @@ public function testDateRests_SummerTimeAffection() public function testInvalidDateFormatConversion() { $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - $this->_type->convertToPHPValue('abcdefg', $this->_platform); + $this->type->convertToPHPValue('abcdefg', $this->platform); } public function testNullConversion() { - $this->assertNull($this->_type->convertToPHPValue(null, $this->_platform)); + $this->assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testConvertDateTimeToPHPValue() { $date = new \DateTime("now"); - $this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform)); + $this->assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } /** From 1a6a796ec301392579259f8b34814fbc71364aa1 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 18:32:57 +0200 Subject: [PATCH 40/70] #869 - DBAL-1293 - abstract test case for date-based types --- .../Tests/DBAL/Types/BaseDateTypeTestCase.php | 94 +++++++++++++++++++ tests/Doctrine/Tests/DBAL/Types/DateTest.php | 79 +--------------- .../Tests/DBAL/Types/DateTimeTest.php | 72 ++------------ .../Tests/DBAL/Types/DateTimeTzTest.php | 69 ++------------ tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 74 ++------------- 5 files changed, 124 insertions(+), 264 deletions(-) create mode 100644 tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php diff --git a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php new file mode 100644 index 00000000000..4493aa74791 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php @@ -0,0 +1,94 @@ +platform = new MockPlatform(); + $this->currentTimezone = date_default_timezone_get(); + + $this->assertInstanceOf('Doctrine\DBAL\Types\Type', $this->type); + } + + /** + * {@inheritDoc} + */ + protected function tearDown() + { + date_default_timezone_set($this->currentTimezone); + } + + public function testDateConvertsToDatabaseValue() + { + $this->assertInternalType('string', $this->type->convertToDatabaseValue(new \DateTime(), $this->platform)); + } + + /** + * @dataProvider invalidPHPValuesProvider + * + * @param mixed $value + */ + public function testInvalidTypeConversionToDatabaseValue($value) + { + $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); + + $this->type->convertToDatabaseValue($value, $this->platform); + } + + public function testNullConversion() + { + $this->assertNull($this->type->convertToPHPValue(null, $this->platform)); + } + + public function testConvertDateTimeToPHPValue() + { + $date = new \DateTime('now'); + + $this->assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); + } + + /** + * @return mixed[][] + */ + public function invalidPHPValuesProvider() + { + return [ + [0], + [''], + ['foo'], + ['10:11:12'], + ['2015-01-31'], + ['2015-01-31 10:11:12'], + [new \stdClass()], + [$this], + [27], + [-1], + [1.2], + [[]], + [['an array']], + ]; + } +} diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index e7255eca06b..68fc6597e96 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -5,56 +5,16 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; -class DateTest extends \Doctrine\Tests\DbalTestCase +class DateTestCase extends BaseDateTypeTestCase { - /** - * @var MockPlatform - */ - private $platform; - - /** - * @var \Doctrine\DBAL\Types\DateType - */ - private $type; - - /** - * @var string - */ - private $currentTimezone; - /** * {@inheritDoc} */ protected function setUp() { - $this->platform = new MockPlatform(); - $this->type = Type::getType('date'); - $this->currentTimezone = date_default_timezone_get(); - } + $this->type = Type::getType('date'); - /** - * {@inheritDoc} - */ - protected function tearDown() - { - date_default_timezone_set($this->currentTimezone); - } - - public function testDateConvertsToDatabaseValue() - { - $this->assertInternalType('string', $this->type->convertToDatabaseValue(new \DateTime(), $this->platform)); - } - - /** - * @dataProvider invalidPHPValuesProvider - * - * @param mixed $value - */ - public function testInvalidTypeConversionToDatabaseValue($value) - { - $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - - $this->type->convertToDatabaseValue($value, $this->platform); + parent::setUp(); } public function testDateConvertsToPHPValue() @@ -91,37 +51,4 @@ public function testInvalidDateFormatConversion() $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); $this->type->convertToPHPValue('abcdefg', $this->platform); } - - public function testNullConversion() - { - $this->assertNull($this->type->convertToPHPValue(null, $this->platform)); - } - - public function testConvertDateTimeToPHPValue() - { - $date = new \DateTime("now"); - $this->assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); - } - - /** - * @return mixed[][] - */ - public function invalidPHPValuesProvider() - { - return [ - [0], - [''], - ['foo'], - ['10:11:12'], - ['2015-01-31'], - ['2015-01-31 10:11:12'], - [new \stdClass()], - [$this], - [27], - [-1], - [1.2], - [[]], - [['an array']], - ]; - } } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index 358689f2887..a6d5c27eeea 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -3,52 +3,33 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; -class DateTimeTest extends \Doctrine\Tests\DbalTestCase +class DateTimeTestCase extends BaseDateTypeTestCase { /** - * @var MockPlatform + * {@inheritDoc} */ - private $_platform; - - /** - * @var \Doctrine\DBAL\Types\DateTimeType - */ - private $_type; - protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('datetime'); + $this->type = Type::getType('datetime'); + + parent::setUp(); } public function testDateTimeConvertsToDatabaseValue() { $date = new \DateTime('1985-09-01 10:10:10'); - $expected = $date->format($this->_platform->getDateTimeTzFormatString()); - $actual = $this->_type->convertToDatabaseValue($date, $this->_platform); + $expected = $date->format($this->platform->getDateTimeTzFormatString()); + $actual = $this->type->convertToDatabaseValue($date, $this->platform); $this->assertEquals($expected, $actual); } - /** - * @dataProvider invalidPHPValuesProvider - * - * @param mixed $value - */ - public function testInvalidTypeConversionToDatabaseValue($value) - { - $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - - $this->_type->convertToDatabaseValue($value, $this->_platform); - } - public function testDateTimeConvertsToPHPValue() { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) - $date = $this->_type->convertToPHPValue('1985-09-01 00:00:00', $this->_platform); + $date = $this->type->convertToPHPValue('1985-09-01 00:00:00', $this->platform); $this->assertInstanceOf('DateTime', $date); $this->assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); } @@ -56,48 +37,15 @@ public function testDateTimeConvertsToPHPValue() public function testInvalidDateTimeFormatConversion() { $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - $this->_type->convertToPHPValue('abcdefg', $this->_platform); - } - - public function testNullConversion() - { - $this->assertNull($this->_type->convertToPHPValue(null, $this->_platform)); - } - - public function testConvertDateTimeToPHPValue() - { - $date = new \DateTime("now"); - $this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform)); + $this->type->convertToPHPValue('abcdefg', $this->platform); } public function testConvertsNonMatchingFormatToPhpValueWithParser() { $date = '1985/09/01 10:10:10.12345'; - $actual = $this->_type->convertToPHPValue($date, $this->_platform); + $actual = $this->type->convertToPHPValue($date, $this->platform); $this->assertEquals('1985-09-01 10:10:10', $actual->format('Y-m-d H:i:s')); } - - /** - * @return mixed[][] - */ - public function invalidPHPValuesProvider() - { - return [ - [0], - [''], - ['foo'], - ['10:11:12'], - ['2015-01-31'], - ['2015-01-31 10:11:12'], - [new \stdClass()], - [$this], - [27], - [-1], - [1.2], - [[]], - [['an array']], - ]; - } } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index 529934bf8df..92b1c7e7485 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -5,50 +5,32 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; -class DateTimeTzTest extends \Doctrine\Tests\DbalTestCase +class DateTimeTzTestCase extends BaseDateTypeTestCase { /** - * @var MockPlatform + * {@inheritDoc} */ - private $_platform; - - /** - * @var \Doctrine\DBAL\Types\DateTimeTzType - */ - private $_type; - protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('datetimetz'); + $this->type = Type::getType('datetimetz'); + + parent::setUp(); } public function testDateTimeConvertsToDatabaseValue() { $date = new \DateTime('1985-09-01 10:10:10'); - $expected = $date->format($this->_platform->getDateTimeTzFormatString()); - $actual = $this->_type->convertToDatabaseValue($date, $this->_platform); + $expected = $date->format($this->platform->getDateTimeTzFormatString()); + $actual = $this->type->convertToDatabaseValue($date, $this->platform); $this->assertEquals($expected, $actual); } - /** - * @dataProvider invalidPHPValuesProvider - * - * @param mixed $value - */ - public function testInvalidTypeConversionToDatabaseValue($value) - { - $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - - $this->_type->convertToDatabaseValue($value, $this->_platform); - } - public function testDateTimeConvertsToPHPValue() { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) - $date = $this->_type->convertToPHPValue('1985-09-01 00:00:00', $this->_platform); + $date = $this->type->convertToPHPValue('1985-09-01 00:00:00', $this->platform); $this->assertInstanceOf('DateTime', $date); $this->assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); } @@ -56,39 +38,6 @@ public function testDateTimeConvertsToPHPValue() public function testInvalidDateFormatConversion() { $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - $this->_type->convertToPHPValue('abcdefg', $this->_platform); - } - - public function testNullConversion() - { - $this->assertNull($this->_type->convertToPHPValue(null, $this->_platform)); - } - - public function testConvertDateTimeToPHPValue() - { - $date = new \DateTime("now"); - $this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform)); - } - - /** - * @return mixed[][] - */ - public function invalidPHPValuesProvider() - { - return [ - [0], - [''], - ['foo'], - ['10:11:12'], - ['2015-01-31'], - ['2015-01-31 10:11:12'], - [new \stdClass()], - [$this], - [27], - [-1], - [1.2], - [[]], - [['an array']], - ]; + $this->type->convertToPHPValue('abcdefg', $this->platform); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index 226a772c08b..1d57c901ec4 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -5,52 +5,27 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; -class TimeTest extends \Doctrine\Tests\DbalTestCase +class TimeTestCase extends BaseDateTypeTestCase { /** - * @var MockPlatform + * {@inheritDoc} */ - private $_platform; - - /** - * @var \Doctrine\DBAL\Types\TimeType - */ - private $_type; - protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('time'); - } - - public function testTimeConvertsToDatabaseValue() - { - $this->assertInternalType('string', $this->_type->convertToDatabaseValue(new \DateTime(), $this->_platform)); - } - - /** - * @dataProvider invalidPHPValuesProvider - * - * @param mixed $value - */ - public function testInvalidTypeConversionToDatabaseValue($value) - { - $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); + $this->type = Type::getType('time'); - $this->_type->convertToDatabaseValue($value, $this->_platform); + parent::setUp(); } public function testTimeConvertsToPHPValue() { - $this->assertTrue( - $this->_type->convertToPHPValue('5:30:55', $this->_platform) - instanceof \DateTime - ); + $this->assertInstanceOf('DateTime', $this->type->convertToPHPValue('5:30:55', $this->platform)); } public function testDateFieldResetInPHPValue() { - $time = $this->_type->convertToPHPValue('01:23:34', $this->_platform); + $time = $this->type->convertToPHPValue('01:23:34', $this->platform); + $this->assertEquals('01:23:34', $time->format('H:i:s')); $this->assertEquals('1970-01-01', $time->format('Y-m-d')); } @@ -58,39 +33,6 @@ public function testDateFieldResetInPHPValue() public function testInvalidTimeFormatConversion() { $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - $this->_type->convertToPHPValue('abcdefg', $this->_platform); - } - - public function testNullConversion() - { - $this->assertNull($this->_type->convertToPHPValue(null, $this->_platform)); - } - - public function testConvertDateTimeToPHPValue() - { - $date = new \DateTime("now"); - $this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform)); - } - - /** - * @return mixed[][] - */ - public function invalidPHPValuesProvider() - { - return [ - [0], - [''], - ['foo'], - ['10:11:12'], - ['2015-01-31'], - ['2015-01-31 10:11:12'], - [new \stdClass()], - [$this], - [27], - [-1], - [1.2], - [[]], - [['an array']], - ]; + $this->type->convertToPHPValue('abcdefg', $this->platform); } } From ef4bd5d1f8eb7a7378f050ed9f1d03ee62a39c95 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 18:33:49 +0200 Subject: [PATCH 41/70] #869 - DBAL-1293 - removing unused imports --- tests/Doctrine/Tests/DBAL/Types/DateTest.php | 1 - tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php | 1 - tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 1 - 3 files changed, 3 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index 68fc6597e96..2d75928df72 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -3,7 +3,6 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; class DateTestCase extends BaseDateTypeTestCase { diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index 92b1c7e7485..f073089c751 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -3,7 +3,6 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; class DateTimeTzTestCase extends BaseDateTypeTestCase { diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index 1d57c901ec4..85e12516fec 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -3,7 +3,6 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Mocks\MockPlatform; class TimeTestCase extends BaseDateTypeTestCase { From dcc18f0ef744c7bb51bad0e1c078cf357f335cab Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 18:40:29 +0200 Subject: [PATCH 42/70] #869 - DBAL-1293 - cleaning up error message generation --- .../DBAL/Types/ConversionException.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/DBAL/Types/ConversionException.php b/lib/Doctrine/DBAL/Types/ConversionException.php index e0cc64b04d1..8d1c0b459f5 100644 --- a/lib/Doctrine/DBAL/Types/ConversionException.php +++ b/lib/Doctrine/DBAL/Types/ConversionException.php @@ -69,16 +69,17 @@ static public function conversionFailedFormat($value, $toType, $expectedFormat) /** * Thrown when the PHP value passed to the converter was not of the expected type. * - * @param mixed $value - * @param string $fromType + * @param mixed $value + * @param string $toType + * @param string[] $possibleTypes * * @return \Doctrine\DBAL\Types\ConversionException */ - static public function conversionFailedInvalidType($value, $toType, $fromType) + static public function conversionFailedInvalidType($value, $toType, array $possibleTypes) { $actualType = gettype($value); if ($actualType === 'object') { - $actualType .= " (" . get_class($value) . ")"; + $actualType .= ' (' . get_class($value) . ')'; if (!method_exists($value, '__toString')) { $value = 'object'; } @@ -86,8 +87,12 @@ static public function conversionFailedInvalidType($value, $toType, $fromType) $value = (string)$value; $value = (strlen($value) > 32) ? substr($value, 0, 20) . "..." : $value; - return new self( - "Could not convert PHP value '$value' of type '$actualType' to type $toType. Expected type: $fromType" - ); + return new self(sprintf( + "Could not convert PHP value '%s' of type '%s' to type '%s'. Expected one of the following: %s", + $value, + $actualType, + $toType, + implode(', ', $possibleTypes) + )); } } From ae0a20519e65f9e4bfdcb8cd957932f1b6462936 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 18:54:41 +0200 Subject: [PATCH 43/70] #869 - DBAL-1293 - aligning datetime types to the new conversion exception signature --- lib/Doctrine/DBAL/Types/DateTimeType.php | 2 +- lib/Doctrine/DBAL/Types/DateTimeTzType.php | 2 +- lib/Doctrine/DBAL/Types/DateType.php | 2 +- lib/Doctrine/DBAL/Types/TimeType.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/DBAL/Types/DateTimeType.php b/lib/Doctrine/DBAL/Types/DateTimeType.php index 07633834d42..83ea69e4eed 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeType.php @@ -57,7 +57,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format($platform->getDateTimeFormatString()); } - throw ConversionException::conversionFailedInvalidType($value, $this->getName(), 'DateTime'); + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateTime']); } /** diff --git a/lib/Doctrine/DBAL/Types/DateTimeTzType.php b/lib/Doctrine/DBAL/Types/DateTimeTzType.php index ab6c2e72d82..527aed19d2d 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeTzType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeTzType.php @@ -75,7 +75,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format($platform->getDateTimeTzFormatString()); } - throw ConversionException::conversionFailedInvalidType($value, $this->getName(), 'DateTime'); + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateTime']); } /** diff --git a/lib/Doctrine/DBAL/Types/DateType.php b/lib/Doctrine/DBAL/Types/DateType.php index 8658a7a19f5..a5642a598f4 100644 --- a/lib/Doctrine/DBAL/Types/DateType.php +++ b/lib/Doctrine/DBAL/Types/DateType.php @@ -57,7 +57,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format($platform->getDateFormatString()); } - throw ConversionException::conversionFailedInvalidType($value, $this->getName(), 'DateTime'); + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateTime']); } /** diff --git a/lib/Doctrine/DBAL/Types/TimeType.php b/lib/Doctrine/DBAL/Types/TimeType.php index c794e3f194c..34533d6ea1e 100644 --- a/lib/Doctrine/DBAL/Types/TimeType.php +++ b/lib/Doctrine/DBAL/Types/TimeType.php @@ -57,7 +57,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format($platform->getTimeFormatString()); } - throw ConversionException::conversionFailedInvalidType($value, $this->getName(), 'DateTime'); + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateTime']); } /** From f0534f3d29b7038bb5caa0b95ea1ab437b552c91 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 18:55:12 +0200 Subject: [PATCH 44/70] #869 - DBAL-1293 - basic coverage for the conversion exception --- .../DBAL/Types/ConversionException.php | 21 +++++----- .../DBAL/Types/ConversionExceptionTest.php | 39 +++++++++++++++++++ 2 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php diff --git a/lib/Doctrine/DBAL/Types/ConversionException.php b/lib/Doctrine/DBAL/Types/ConversionException.php index 8d1c0b459f5..931b7ee57cd 100644 --- a/lib/Doctrine/DBAL/Types/ConversionException.php +++ b/lib/Doctrine/DBAL/Types/ConversionException.php @@ -77,19 +77,20 @@ static public function conversionFailedFormat($value, $toType, $expectedFormat) */ static public function conversionFailedInvalidType($value, $toType, array $possibleTypes) { - $actualType = gettype($value); - if ($actualType === 'object') { - $actualType .= ' (' . get_class($value) . ')'; - if (!method_exists($value, '__toString')) { - $value = 'object'; - } + $actualType = is_object($value) ? get_class($value) : gettype($value); + + if (is_scalar($value)) { + return new self(sprintf( + "Could not convert PHP value '%s' of type '%s' to type '%s'. Expected one of the following types: %s", + $value, + $actualType, + $toType, + implode(', ', $possibleTypes) + )); } - $value = (string)$value; - $value = (strlen($value) > 32) ? substr($value, 0, 20) . "..." : $value; return new self(sprintf( - "Could not convert PHP value '%s' of type '%s' to type '%s'. Expected one of the following: %s", - $value, + "Could not convert PHP value of type '%s' to type '%s'. Expected one of the following types: %s", $actualType, $toType, implode(', ', $possibleTypes) diff --git a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php new file mode 100644 index 00000000000..22647a91ffb --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php @@ -0,0 +1,39 @@ +assertInstanceOf('Doctrine\DBAL\Types\ConversionException', $exception); + $this->assertRegExp( + '/^Could not convert PHP value \'.*\' of type \'(string|boolean|float|double|integer)\' to type \'foo\'. ' + . 'Expected one of the following types: bar, baz$/', + $exception->getMessage() + ); + } + + public function scalarsProvider() + { + return [ + [''], + ['foo'], + [123], + [-123], + [12.34], + [true], + [false], + ]; + } +} From beb2c7cf1fa406ec49199e98bfc0e9cb0060256f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 5 Sep 2015 18:57:31 +0200 Subject: [PATCH 45/70] #869 - DBAL-1293 - covering remaining conversion exception logic --- .../DBAL/Types/ConversionExceptionTest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php index 22647a91ffb..02196f5f21d 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php @@ -23,7 +23,41 @@ public function testConversionFailedInvalidTypeWithScalar($scalarValue) $exception->getMessage() ); } + /** + * @dataProvider nonScalarsProvider + * + * @param mixed $nonScalar + */ + public function testConversionFailedInvalidTypeWithNonScalar($nonScalar) + { + $exception = ConversionException::conversionFailedInvalidType($nonScalar, 'foo', ['bar', 'baz']); + + $this->assertInstanceOf('Doctrine\DBAL\Types\ConversionException', $exception); + $this->assertRegExp( + '/^Could not convert PHP value of type \'(.*)\' to type \'foo\'. ' + . 'Expected one of the following types: bar, baz$/', + $exception->getMessage() + ); + } + + /** + * @return mixed[][] + */ + public function nonScalarsProvider() + { + return [ + [[]], + [['foo']], + [null], + [$this], + [new \stdClass()], + [tmpfile()], + ]; + } + /** + * @return mixed[][] + */ public function scalarsProvider() { return [ From ae67ace84c403fc16ebaac59e1a386b92f7388d7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 6 Sep 2015 03:49:13 +0200 Subject: [PATCH 46/70] #869 - DBAL-1293 - testing `DateIntervalType` logic with invalid type conversions --- .../Tests/DBAL/Types/DateIntervalTest.php | 64 ++++++++++++++++--- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php index f757759c2e5..236ff1b7f24 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php @@ -7,14 +7,23 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase { - protected - $_platform, - $_type; + /** + * @var MockPlatform + */ + private $platform; + + /** + * @var \Doctrine\DBAL\Types\DateIntervalType + */ + private $type; + /** + * {@inheritDoc} + */ protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('dateinterval'); + $this->platform = new MockPlatform(); + $this->type = Type::getType('dateinterval'); } public function testDateIntervalConvertsToDatabaseValue() @@ -22,14 +31,14 @@ public function testDateIntervalConvertsToDatabaseValue() $interval = new \DateInterval('P2Y1DT1H2M3S'); $expected = 'P0002-00-01T01:02:03'; - $actual = $this->_type->convertToDatabaseValue($interval, $this->_platform); + $actual = $this->type->convertToDatabaseValue($interval, $this->platform); $this->assertEquals($expected, $actual); } public function testDateIntervalConvertsToPHPValue() { - $date = $this->_type->convertToPHPValue('P0002-00-01T01:02:03', $this->_platform); + $date = $this->type->convertToPHPValue('P0002-00-01T01:02:03', $this->platform); $this->assertInstanceOf('DateInterval', $date); $this->assertEquals('P2Y0M1DT1H2M3S', $date->format('P%yY%mM%dDT%hH%iM%sS')); } @@ -37,12 +46,12 @@ public function testDateIntervalConvertsToPHPValue() public function testInvalidDateIntervalFormatConversion() { $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); - $this->_type->convertToPHPValue('abcdefg', $this->_platform); + $this->type->convertToPHPValue('abcdefg', $this->platform); } public function testDateIntervalNullConversion() { - $this->assertNull($this->_type->convertToPHPValue(null, $this->_platform)); + $this->assertNull($this->type->convertToPHPValue(null, $this->platform)); } /** @@ -50,6 +59,41 @@ public function testDateIntervalNullConversion() */ public function testRequiresSQLCommentHint() { - $this->assertTrue($this->_type->requiresSQLCommentHint($this->_platform)); + $this->assertTrue($this->type->requiresSQLCommentHint($this->platform)); + } + + /** + * @dataProvider invalidPHPValuesProvider + * + * @param mixed $value + */ + public function testInvalidTypeConversionToDatabaseValue($value) + { + $this->setExpectedException('Doctrine\DBAL\Types\ConversionException'); + + $this->type->convertToDatabaseValue($value, $this->platform); + } + + /** + * @return mixed[][] + */ + public function invalidPHPValuesProvider() + { + return [ + [0], + [''], + ['foo'], + ['10:11:12'], + ['2015-01-31'], + ['2015-01-31 10:11:12'], + [new \stdClass()], + [$this], + [27], + [-1], + [1.2], + [[]], + [['an array']], + [new \DateTime()], + ]; } } From 6c867a0ffacdea41447fcc76a332e8880def2313 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 6 Sep 2015 03:53:09 +0200 Subject: [PATCH 47/70] #869 - DBAL-1293 - `DateIntervalType` should throw on invalid types --- lib/Doctrine/DBAL/Types/DateIntervalType.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/DBAL/Types/DateIntervalType.php b/lib/Doctrine/DBAL/Types/DateIntervalType.php index d71b8e7283e..fa571785a98 100644 --- a/lib/Doctrine/DBAL/Types/DateIntervalType.php +++ b/lib/Doctrine/DBAL/Types/DateIntervalType.php @@ -33,20 +33,17 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - $spec = null; - if ($value !== null) { - /** @var \DateInterval $value */ - $spec = 'P' + if (null === $value) { + return null; + } + + if ($value instanceof \DateInterval) { + return 'P' . str_pad($value->y, 4, '0', STR_PAD_LEFT) . '-' - . $value->format('%M') . '-' - . $value->format('%D') . 'T' - . $value->format('%H') . ':' - . $value->format('%I') . ':' - . $value->format('%S') - ; + . $value->format('%M-%DT%H:%I:%S'); } - return $spec; + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateInterval']); } /** From 52fe0e464e3e68124289fbbed32b856750ab8dea Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 6 Sep 2015 03:55:14 +0200 Subject: [PATCH 48/70] #869 - DBAL-1293 - Removing whitespace --- lib/Doctrine/DBAL/Types/DateIntervalType.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Types/DateIntervalType.php b/lib/Doctrine/DBAL/Types/DateIntervalType.php index fa571785a98..69356af90c7 100644 --- a/lib/Doctrine/DBAL/Types/DateIntervalType.php +++ b/lib/Doctrine/DBAL/Types/DateIntervalType.php @@ -59,7 +59,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $interval = new \DateInterval($value); } catch (\Exception $e) { throw ConversionException::conversionFailedFormat($value, $this->getName(), 'PY-m-dTH:i:s'); - } return $interval; From a348e332fa7fe874e3d61a3db9f86ab5d2222d6c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 6 Sep 2015 03:58:40 +0200 Subject: [PATCH 49/70] #869 - DBAL-1293 - Previous exceptions should be preserved by the `ConversionException` --- .../Tests/DBAL/Types/ConversionExceptionTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php index 02196f5f21d..5aa797895fd 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php @@ -40,6 +40,16 @@ public function testConversionFailedInvalidTypeWithNonScalar($nonScalar) ); } + public function testConversionFailedFormatPreservesPreviousException() + { + $previous = new \Exception(); + + $exception = ConversionException::conversionFailedFormat('foo', 'bar', 'baz', $previous); + + $this->assertInstanceOf('Doctrine\DBAL\Types\ConversionException', $exception); + $this->assertSame($previous, $exception->getPrevious()); + } + /** * @return mixed[][] */ From 5eb3e046cf49e0c9c64183665c179af5a6e957c6 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 6 Sep 2015 03:59:18 +0200 Subject: [PATCH 50/70] #869 - DBAL-1293 - Preserving exceptions for invalid conversions --- lib/Doctrine/DBAL/Types/ConversionException.php | 17 ++++++++++------- lib/Doctrine/DBAL/Types/DateIntervalType.php | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/DBAL/Types/ConversionException.php b/lib/Doctrine/DBAL/Types/ConversionException.php index 931b7ee57cd..e37a79058f7 100644 --- a/lib/Doctrine/DBAL/Types/ConversionException.php +++ b/lib/Doctrine/DBAL/Types/ConversionException.php @@ -41,7 +41,7 @@ class ConversionException extends \Doctrine\DBAL\DBALException */ static public function conversionFailed($value, $toType) { - $value = (strlen($value) > 32) ? substr($value, 0, 20) . "..." : $value; + $value = (strlen($value) > 32) ? substr($value, 0, 20) . '...' : $value; return new self('Could not convert database value "' . $value . '" to Doctrine Type ' . $toType); } @@ -50,19 +50,22 @@ static public function conversionFailed($value, $toType) * Thrown when a Database to Doctrine Type Conversion fails and we can make a statement * about the expected format. * - * @param string $value - * @param string $toType - * @param string $expectedFormat + * @param string $value + * @param string $toType + * @param string $expectedFormat + * @param \Exception|null $previous * * @return \Doctrine\DBAL\Types\ConversionException */ - static public function conversionFailedFormat($value, $toType, $expectedFormat) + static public function conversionFailedFormat($value, $toType, $expectedFormat, \Exception $previous = null) { - $value = (strlen($value) > 32) ? substr($value, 0, 20) . "..." : $value; + $value = (strlen($value) > 32) ? substr($value, 0, 20) . '...' : $value; return new self( 'Could not convert database value "' . $value . '" to Doctrine Type ' . - $toType . '. Expected format: ' . $expectedFormat + $toType . '. Expected format: ' . $expectedFormat, + 0, + $previous ); } diff --git a/lib/Doctrine/DBAL/Types/DateIntervalType.php b/lib/Doctrine/DBAL/Types/DateIntervalType.php index 69356af90c7..5b86d5b0d0b 100644 --- a/lib/Doctrine/DBAL/Types/DateIntervalType.php +++ b/lib/Doctrine/DBAL/Types/DateIntervalType.php @@ -57,8 +57,8 @@ public function convertToPHPValue($value, AbstractPlatform $platform) try { $interval = new \DateInterval($value); - } catch (\Exception $e) { - throw ConversionException::conversionFailedFormat($value, $this->getName(), 'PY-m-dTH:i:s'); + } catch (\Exception $exception) { + throw ConversionException::conversionFailedFormat($value, $this->getName(), 'PY-m-dTH:i:s', $exception); } return $interval; From 73f3d2c8111280d9fc93eddf651bb415edf64886 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 6 Sep 2015 03:59:42 +0200 Subject: [PATCH 51/70] #869 - DBAL-1293 - Removing unused assignment --- lib/Doctrine/DBAL/Types/DateIntervalType.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Doctrine/DBAL/Types/DateIntervalType.php b/lib/Doctrine/DBAL/Types/DateIntervalType.php index 5b86d5b0d0b..27d1369bd93 100644 --- a/lib/Doctrine/DBAL/Types/DateIntervalType.php +++ b/lib/Doctrine/DBAL/Types/DateIntervalType.php @@ -56,12 +56,10 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } try { - $interval = new \DateInterval($value); + return new \DateInterval($value); } catch (\Exception $exception) { throw ConversionException::conversionFailedFormat($value, $this->getName(), 'PY-m-dTH:i:s', $exception); } - - return $interval; } /** From 8bfa9bdcb1f60e4506f7a47140d08e2a40ef0530 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 6 Sep 2015 04:03:04 +0200 Subject: [PATCH 52/70] #869 - DBAL-1293 - Correcting class names caused by incorrect refactoring --- tests/Doctrine/Tests/DBAL/Types/DateTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index 2d75928df72..108eb502755 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\Types\Type; -class DateTestCase extends BaseDateTypeTestCase +class DateTest extends BaseDateTypeTestCase { /** * {@inheritDoc} diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index a6d5c27eeea..9d9720118bf 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\Types\Type; -class DateTimeTestCase extends BaseDateTypeTestCase +class DateTimeTest extends BaseDateTypeTestCase { /** * {@inheritDoc} diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index f073089c751..94366e87d15 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\Types\Type; -class DateTimeTzTestCase extends BaseDateTypeTestCase +class DateTimeTzTest extends BaseDateTypeTestCase { /** * {@inheritDoc} diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index 85e12516fec..8e4dbb940b3 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\Types\Type; -class TimeTestCase extends BaseDateTypeTestCase +class TimeTest extends BaseDateTypeTestCase { /** * {@inheritDoc} From 155f5d754390ec7fabcf1a30015ffbbb2e096c86 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 6 Sep 2015 04:08:02 +0200 Subject: [PATCH 53/70] #869 - DBAL-1293 - Making sure `Type::getType('dateinterval')` retrieves a `DateIntervalType` instance --- tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php index 236ff1b7f24..8d212001a71 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php @@ -24,6 +24,8 @@ protected function setUp() { $this->platform = new MockPlatform(); $this->type = Type::getType('dateinterval'); + + $this->assertInstanceOf('Doctrine\DBAL\Types\DateIntervalType', $this->type); } public function testDateIntervalConvertsToDatabaseValue() From 40e8fc0933043dfb7ecfb1910f37d0a6d9e56934 Mon Sep 17 00:00:00 2001 From: Vincent CHALAMON Date: Tue, 18 Aug 2015 13:59:00 +0200 Subject: [PATCH 54/70] Override methods for sharding connection --- lib/Doctrine/DBAL/Connection.php | 4 +- .../DBAL/Sharding/PoolingShardConnection.php | 69 +++++++- .../DBAL/Sharding/PoolingShardManager.php | 8 +- .../Sharding/PoolingShardConnectionTest.php | 152 +++++++++++++++++- 4 files changed, 214 insertions(+), 19 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 84b2210aa6b..56a026c1174 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -354,10 +354,10 @@ public function connect() } $driverOptions = isset($this->_params['driverOptions']) ? - $this->_params['driverOptions'] : array(); + $this->_params['driverOptions'] : array(); $user = isset($this->_params['user']) ? $this->_params['user'] : null; $password = isset($this->_params['password']) ? - $this->_params['password'] : null; + $this->_params['password'] : null; $this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions); $this->_isConnected = true; diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php index 3b6c6e1067d..29c041e6dda 100644 --- a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php +++ b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php @@ -19,14 +19,12 @@ namespace Doctrine\DBAL\Sharding; +use Doctrine\Common\EventManager; +use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Events; -use Doctrine\DBAL\Driver; -use Doctrine\DBAL\Configuration; - -use Doctrine\Common\EventManager; - use Doctrine\DBAL\Sharding\ShardChoser\ShardChoser; /** @@ -128,6 +126,64 @@ public function __construct(array $params, Driver $driver, Configuration $config parent::__construct($params, $driver, $config, $eventManager); } + /** + * Get active shard id. + * + * @return integer + */ + public function getActiveShardId() + { + return $this->activeShardId; + } + + /** + * {@inheritdoc} + */ + public function getParams() + { + return $this->activeShardId ? $this->connections[$this->activeShardId] : parent::getParams(); + } + + /** + * {@inheritdoc} + */ + public function getHost() + { + $params = $this->getParams(); + + return isset($params['host']) ? $params['host'] : parent::getHost(); + } + + /** + * {@inheritdoc} + */ + public function getPort() + { + $params = $this->getParams(); + + return isset($params['port']) ? $params['port'] : parent::getPort(); + } + + /** + * {@inheritdoc} + */ + public function getUsername() + { + $params = $this->getParams(); + + return isset($params['user']) ? $params['user'] : parent::getUsername(); + } + + /** + * {@inheritdoc} + */ + public function getPassword() + { + $params = $this->getParams(); + + return isset($params['password']) ? $params['password'] : parent::getPassword(); + } + /** * Connects to a given shard. * @@ -151,7 +207,7 @@ public function connect($shardId = null) throw new ShardingException("Cannot switch shard when transaction is active."); } - $this->activeShardId = (int) $shardId; + $this->activeShardId = (int)$shardId; if (isset($this->activeConnections[$this->activeShardId])) { $this->_conn = $this->activeConnections[$this->activeShardId]; @@ -211,5 +267,6 @@ public function close() { $this->_conn = null; $this->activeConnections = null; + $this->activeShardId = null; } } diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php b/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php index d4bdee80fc3..64307ca6664 100644 --- a/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php +++ b/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php @@ -19,6 +19,8 @@ namespace Doctrine\DBAL\Sharding; +use Doctrine\DBAL\Sharding\ShardChoser\ShardChoser; + /** * Shard Manager for the Connection Pooling Shard Strategy * @@ -27,12 +29,12 @@ class PoolingShardManager implements ShardManager { /** - * @var \Doctrine\DBAL\Sharding\PoolingShardConnection + * @var PoolingShardConnection */ private $conn; /** - * @var \Doctrine\DBAL\Sharding\ShardChoser\ShardChoser + * @var ShardChoser */ private $choser; @@ -42,7 +44,7 @@ class PoolingShardManager implements ShardManager private $currentDistributionValue; /** - * @param \Doctrine\DBAL\Sharding\PoolingShardConnection $conn + * @param PoolingShardConnection $conn */ public function __construct(PoolingShardConnection $conn) { diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php index d77c11d2a47..caf669928f6 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php @@ -20,6 +20,7 @@ namespace Doctrine\Tests\DBAL\Sharding; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; class PoolingShardConnectionTest extends \PHPUnit_Framework_TestCase { @@ -61,7 +62,7 @@ public function testNoGlobalServerException() { $this->setExpectedException('InvalidArgumentException', "Connection Parameters require 'global' and 'shards' configurations."); - $conn = DriverManager::getConnection(array( + DriverManager::getConnection(array( 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'shards' => array( @@ -76,7 +77,7 @@ public function testNoShardsServersException() { $this->setExpectedException('InvalidArgumentException', "Connection Parameters require 'global' and 'shards' configurations."); - $conn = DriverManager::getConnection(array( + DriverManager::getConnection(array( 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'global' => array('memory' => true), @@ -88,7 +89,7 @@ public function testNoShardsChoserException() { $this->setExpectedException('InvalidArgumentException', "Missing Shard Choser configuration 'shardChoser'"); - $conn = DriverManager::getConnection(array( + DriverManager::getConnection(array( 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'global' => array('memory' => true), @@ -103,7 +104,7 @@ public function testShardChoserWrongInstance() { $this->setExpectedException('InvalidArgumentException', "The 'shardChoser' configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser"); - $conn = DriverManager::getConnection(array( + DriverManager::getConnection(array( 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'global' => array('memory' => true), @@ -119,7 +120,7 @@ public function testShardNonNumericId() { $this->setExpectedException('InvalidArgumentException', "Shard Id has to be a non-negative number."); - $conn = DriverManager::getConnection(array( + DriverManager::getConnection(array( 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'global' => array('memory' => true), @@ -134,7 +135,7 @@ public function testShardMissingId() { $this->setExpectedException('InvalidArgumentException', "Missing 'id' for one configured shard. Please specify a unique shard-id."); - $conn = DriverManager::getConnection(array( + DriverManager::getConnection(array( 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'global' => array('memory' => true), @@ -149,7 +150,7 @@ public function testDuplicateShardId() { $this->setExpectedException('InvalidArgumentException', "Shard 1 is duplicated in the configuration."); - $conn = DriverManager::getConnection(array( + DriverManager::getConnection(array( 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'global' => array('memory' => true), @@ -178,5 +179,140 @@ public function testSwitchShardWithOpenTransactionException() $this->setExpectedException('Doctrine\DBAL\Sharding\ShardingException', 'Cannot switch shard when transaction is active.'); $conn->connect(1); } -} + public function testGetActiveShardId() + { + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 1, 'memory' => true), + ), + 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + )); + + $this->assertNull($conn->getActiveShardId()); + + $conn->connect(0); + $this->assertEquals(0, $conn->getActiveShardId()); + + $conn->connect(1); + $this->assertEquals(1, $conn->getActiveShardId()); + + $conn->close(); + $this->assertNull($conn->getActiveShardId()); + } + + public function testGetParamsOverride() + { + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 1, 'memory' => true), + ), + 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + )); + + $this->assertEquals(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 1, 'memory' => true), + ), + 'shardChoser' => new MultiTenantShardChoser(), + ), $conn->getParams()); + + $conn->connect(1); + $this->assertEquals(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 1, 'memory' => true), + ), + 'shardChoser' => new MultiTenantShardChoser(), + 'id' => 1, + 'memory' => true, + ), $conn->getParams()); + } + + public function testGetHostOverride() + { + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'host' => 'localhost', + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 1, 'memory' => true, 'host' => 'foo'), + ), + 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + )); + + $this->assertEquals('localhost', $conn->getHost()); + + $conn->connect(1); + $this->assertEquals('foo', $conn->getHost()); + } + + public function testGetPortOverride() + { + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'port' => 3306, + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 1, 'memory' => true, 'port' => 3307), + ), + 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + )); + + $this->assertEquals(3306, $conn->getPort()); + + $conn->connect(1); + $this->assertEquals(3307, $conn->getPort()); + } + + public function testGetUsernameOverride() + { + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'user' => 'foo', + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 1, 'memory' => true, 'user' => 'bar'), + ), + 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + )); + + $this->assertEquals('foo', $conn->getUsername()); + + $conn->connect(1); + $this->assertEquals('bar', $conn->getUsername()); + } + + public function testGetPasswordOverride() + { + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'password' => 'foo', + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 1, 'memory' => true, 'password' => 'bar'), + ), + 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + )); + + $this->assertEquals('foo', $conn->getPassword()); + + $conn->connect(1); + $this->assertEquals('bar', $conn->getPassword()); + } +} From 30258780317fc25fe12faf37202404e6d6b59cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Thu, 10 Sep 2015 18:41:15 +0200 Subject: [PATCH 55/70] fix tear down of some test cases --- .../Tests/DBAL/Functional/ExceptionTest.php | 58 ++++++++++++++++--- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php index c63409eba72..27f1e0490dd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php @@ -64,8 +64,14 @@ public function testForeignKeyConstraintViolationExceptionOnInsert() $this->setUpForeignKeyConstraintViolationExceptionTest(); - $this->_conn->insert("constraint_error_table", array('id' => 1)); - $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); + try { + $this->_conn->insert("constraint_error_table", array('id' => 1)); + $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); + } catch (\Exception $exception) { + $this->tearDownForeignKeyConstraintViolationExceptionTest(); + + throw $exception; + } $this->setExpectedException('\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException'); @@ -74,6 +80,10 @@ public function testForeignKeyConstraintViolationExceptionOnInsert() } catch (ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); + throw $exception; + } catch (\Exception $exception) { + $this->tearDownForeignKeyConstraintViolationExceptionTest(); + throw $exception; } @@ -88,8 +98,14 @@ public function testForeignKeyConstraintViolationExceptionOnUpdate() $this->setUpForeignKeyConstraintViolationExceptionTest(); - $this->_conn->insert("constraint_error_table", array('id' => 1)); - $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); + try { + $this->_conn->insert("constraint_error_table", array('id' => 1)); + $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); + } catch (\Exception $exception) { + $this->tearDownForeignKeyConstraintViolationExceptionTest(); + + throw $exception; + } $this->setExpectedException('\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException'); @@ -98,6 +114,10 @@ public function testForeignKeyConstraintViolationExceptionOnUpdate() } catch (ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); + throw $exception; + } catch (\Exception $exception) { + $this->tearDownForeignKeyConstraintViolationExceptionTest(); + throw $exception; } @@ -112,8 +132,14 @@ public function testForeignKeyConstraintViolationExceptionOnDelete() $this->setUpForeignKeyConstraintViolationExceptionTest(); - $this->_conn->insert("constraint_error_table", array('id' => 1)); - $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); + try { + $this->_conn->insert("constraint_error_table", array('id' => 1)); + $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); + } catch (\Exception $exception) { + $this->tearDownForeignKeyConstraintViolationExceptionTest(); + + throw $exception; + } $this->setExpectedException('\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException'); @@ -122,6 +148,10 @@ public function testForeignKeyConstraintViolationExceptionOnDelete() } catch (ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); + throw $exception; + } catch (\Exception $exception) { + $this->tearDownForeignKeyConstraintViolationExceptionTest(); + throw $exception; } @@ -132,14 +162,20 @@ public function testForeignKeyConstraintViolationExceptionOnTruncate() { $platform = $this->_conn->getDatabasePlatform(); - if ( ! $platform->supportsForeignKeyConstraints()) { + if (!$platform->supportsForeignKeyConstraints()) { $this->markTestSkipped("Only fails on platforms with foreign key constraints."); } $this->setUpForeignKeyConstraintViolationExceptionTest(); - $this->_conn->insert("constraint_error_table", array('id' => 1)); - $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); + try { + $this->_conn->insert("constraint_error_table", array('id' => 1)); + $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); + } catch (\Exception $exception) { + $this->tearDownForeignKeyConstraintViolationExceptionTest(); + + throw $exception; + } $this->setExpectedException('\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException'); @@ -148,6 +184,10 @@ public function testForeignKeyConstraintViolationExceptionOnTruncate() } catch (ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); + throw $exception; + } catch (\Exception $exception) { + $this->tearDownForeignKeyConstraintViolationExceptionTest(); + throw $exception; } From 60333c040d544fadc9637abc1a60c6bf66bd2d6e Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Wed, 17 Jun 2015 12:24:44 -0400 Subject: [PATCH 56/70] Add DbalPerformanceTestCase --- .../Tests/DbalPerformanceTestCase.php | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/Doctrine/Tests/DbalPerformanceTestCase.php diff --git a/tests/Doctrine/Tests/DbalPerformanceTestCase.php b/tests/Doctrine/Tests/DbalPerformanceTestCase.php new file mode 100644 index 00000000000..4083d18d722 --- /dev/null +++ b/tests/Doctrine/Tests/DbalPerformanceTestCase.php @@ -0,0 +1,62 @@ +maxRunningTime != 0 && $time > $this->maxRunningTime) { + $this->fail( + sprintf( + 'expected running time: <= %s but was: %s', + + $this->maxRunningTime, + $time + ) + ); + } + } + + /** + * @param integer $maxRunningTime + * + * @return void + * + * @throws \InvalidArgumentException + */ + public function setMaxRunningTime($maxRunningTime) + { + if (is_integer($maxRunningTime) && $maxRunningTime >= 0) { + $this->maxRunningTime = $maxRunningTime; + } else { + throw new \InvalidArgumentException; + } + } + + /** + * @return integer + */ + public function getMaxRunningTime() + { + return $this->maxRunningTime; + } +} From 0208978648eb6994881c4f8986820eaa11e29f78 Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Wed, 17 Jun 2015 12:35:08 -0400 Subject: [PATCH 57/70] Add TypeConversionPerformanceTest --- .../TypeConversionPerformanceTest.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php diff --git a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php new file mode 100644 index 00000000000..16aa5c19d03 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php @@ -0,0 +1,29 @@ +_conn->getDatabasePlatform(); + for ($i = 0; $i < 100000; $i++) { + $type->convertToDatabaseValue($value, $platform); + } + echo __FUNCTION__ . " - " . (microtime(true) - $start) . " seconds" . PHP_EOL; + } +} From d73e63c87bf733f28e0458735e38a9923bd2289c Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Wed, 17 Jun 2015 12:36:44 -0400 Subject: [PATCH 58/70] Add exclusion for performance group to phpunit.xml.dist --- phpunit.xml.dist | 6 ++++++ .../DBAL/Performance/TypeConversionPerformanceTest.php | 1 + 2 files changed, 7 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index fe1d515e46b..d63ddeed485 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -48,4 +48,10 @@ ./tests/Doctrine/Tests/DBAL + + + + performance + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php index 16aa5c19d03..4a757502717 100644 --- a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php +++ b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php @@ -9,6 +9,7 @@ * Class TypeConversionPerformanceTest * @package Doctrine\Tests\DBAL\Performance * @author Bill Schaller + * @group performance */ class TypeConversionPerformanceTest extends DbalPerformanceTestCase { From 5dde3d0f37c14c45041f1738b242f845ca735853 Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Wed, 17 Jun 2015 13:03:51 -0400 Subject: [PATCH 59/70] remove MAXIMUM TIME comment --- .../Tests/DBAL/Performance/TypeConversionPerformanceTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php index 4a757502717..89eb4915cdc 100644 --- a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php +++ b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php @@ -13,9 +13,6 @@ */ class TypeConversionPerformanceTest extends DbalPerformanceTestCase { - /** - * MAXIMUM TIME: 2 seconds - */ public function testDateTimeTypeConversionPerformance100000Items() { $value = new \DateTime; From 669c03d6c06370f91f94c4079147585daf3a5036 Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Thu, 10 Sep 2015 16:54:29 -0400 Subject: [PATCH 60/70] Improve structure of performance test case. Add DbalPerformanceTestListener to collect & report performance test timing results. --- phpunit.xml.dist | 8 ++ .../TypeConversionPerformanceTest.php | 22 +++++- .../Tests/DbalPerformanceTestCase.php | 78 +++++++++++-------- .../Tests/DbalPerformanceTestListener.php | 39 ++++++++++ 4 files changed, 109 insertions(+), 38 deletions(-) create mode 100644 tests/Doctrine/Tests/DbalPerformanceTestListener.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d63ddeed485..79563caab02 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -46,9 +46,17 @@ ./tests/Doctrine/Tests/DBAL + ./tests/Doctrine/Tests/DBAL/Performance + + + ./tests/Doctrine/Tests/DBAL/Performance + + + + performance diff --git a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php index 89eb4915cdc..42c549aa399 100644 --- a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php +++ b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php @@ -13,15 +13,29 @@ */ class TypeConversionPerformanceTest extends DbalPerformanceTestCase { - public function testDateTimeTypeConversionPerformance100000Items() + /** + * @throws \Doctrine\DBAL\DBALException + * @dataProvider itemCountProvider + */ + public function testDateTimeTypeConversionPerformance($count) { $value = new \DateTime; - $start = microtime(true); $type = Type::getType("datetime"); $platform = $this->_conn->getDatabasePlatform(); - for ($i = 0; $i < 100000; $i++) { + $this->startTiming(); + for ($i = 0; $i < $count; $i++) { $type->convertToDatabaseValue($value, $platform); } - echo __FUNCTION__ . " - " . (microtime(true) - $start) . " seconds" . PHP_EOL; + $this->stopTiming(); + } + + public function itemCountProvider() + { + return [ + '100 items' => [100], + '1000 items' => [1000], + '10000 items' => [10000], + '100000 items' => [100000], + ]; } } diff --git a/tests/Doctrine/Tests/DbalPerformanceTestCase.php b/tests/Doctrine/Tests/DbalPerformanceTestCase.php index 4083d18d722..06bcee898bf 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestCase.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestCase.php @@ -3,60 +3,70 @@ namespace Doctrine\Tests; /** - * Class DbalPerformanceTestCase + * Base class for all DBAL performance tests. + * + * Tests implemented in this class must call startTiming at the beginning + * and stopTiming at the end of all tests. Tests that do not start or stop + * timing will fail. + * * @package Doctrine\Tests\DBAL * @author Bill Schaller - * @author robo */ class DbalPerformanceTestCase extends DbalFunctionalTestCase { /** - * @var integer + * time the test started + * + * @var float */ - protected $maxRunningTime = 0; + private $startTime; /** - * @return void + * elapsed run time of the last test + * + * @var float */ - protected function runTest() + private $lastRunTime; + + public function setUp() { - $s = microtime(true); - parent::runTest(); - $time = microtime(true) - $s; - - if ($this->maxRunningTime != 0 && $time > $this->maxRunningTime) { - $this->fail( - sprintf( - 'expected running time: <= %s but was: %s', - - $this->maxRunningTime, - $time - ) - ); - } + parent::setUp(); + + // Reset timing vars + $this->startTime = $this->lastRunTime = null; } /** - * @param integer $maxRunningTime - * - * @return void - * - * @throws \InvalidArgumentException + * {@inheritdoc} + */ + protected function assertPostConditions() + { + // If a perf test doesn't start or stop, it fails. + $this->assertNotNull($this->startTime, "Test timing was started"); + $this->assertNotNull($this->lastRunTime, "Test timing was stopped"); + } + + /** + * begin timing + */ + protected function startTiming() + { + $this->startTime = microtime(true); + } + + /** + * end timing */ - public function setMaxRunningTime($maxRunningTime) + protected function stopTiming() { - if (is_integer($maxRunningTime) && $maxRunningTime >= 0) { - $this->maxRunningTime = $maxRunningTime; - } else { - throw new \InvalidArgumentException; - } + $this->lastRunTime = microtime(true) - $this->startTime; } /** - * @return integer + * @return float elapsed test execution time */ - public function getMaxRunningTime() + public function getTime() { - return $this->maxRunningTime; + return $this->lastRunTime; } } diff --git a/tests/Doctrine/Tests/DbalPerformanceTestListener.php b/tests/Doctrine/Tests/DbalPerformanceTestListener.php new file mode 100644 index 00000000000..f062de381d6 --- /dev/null +++ b/tests/Doctrine/Tests/DbalPerformanceTestListener.php @@ -0,0 +1,39 @@ +timings[$class . "::" . $test->getName(true)] = $test->getTime(); + } + } + + /** + * {@inheritdoc} + */ + public function endTestSuite(\PHPUnit_Framework_TestSuite $suite) + { + if (!empty($this->timings)) { + print("\n"); + foreach($this->timings as $test => $time) { + printf("%s: %6.3f\n", $test, $time); + } + $this->timings = []; + } + } +} From 82411db8c5a70dfcdc28582ab8dd0dd0c79b9b93 Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Thu, 10 Sep 2015 17:05:54 -0400 Subject: [PATCH 61/70] Change DbalPerformanceTestListener to report timings in __destruct instead of endTestSuite. --- .../Tests/DbalPerformanceTestListener.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/DbalPerformanceTestListener.php b/tests/Doctrine/Tests/DbalPerformanceTestListener.php index f062de381d6..61ed9aa9748 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestListener.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestListener.php @@ -16,24 +16,32 @@ class DbalPerformanceTestListener extends \PHPUnit_Framework_BaseTestListener */ public function endTest(\PHPUnit_Framework_Test $test, $time) { + // This listener only applies to performance tests. if ($test instanceof \Doctrine\Tests\DbalPerformanceTestCase) { + // Identify perf tests by class, method, and dataset $class = str_replace('Doctrine\Tests\DBAL\Performance\\', '', get_class($test)); + + // Store timing data for each test in the order they were run. $this->timings[$class . "::" . $test->getName(true)] = $test->getTime(); } } /** - * {@inheritdoc} + * Report performance test timings. + * + * Note: __destruct is used here because PHPUnit doesn't have a + * 'All tests over' hook. */ - public function endTestSuite(\PHPUnit_Framework_TestSuite $suite) + public function __destruct() { if (!empty($this->timings)) { - print("\n"); + // Report timings. + print("\n\nPerformance test results:\n\n"); + foreach($this->timings as $test => $time) { - printf("%s: %6.3f\n", $test, $time); + printf("%s: %.3f\n", $test, $time); } - $this->timings = []; } } } From 45007d37676a79a7b84ad21ee1bf7ee768b3edf7 Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Fri, 11 Sep 2015 11:39:20 -0400 Subject: [PATCH 62/70] remove DbalPerformanceTestCase::setUp and rename lastRunTime var to just runTime --- tests/Doctrine/Tests/DbalPerformanceTestCase.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tests/Doctrine/Tests/DbalPerformanceTestCase.php b/tests/Doctrine/Tests/DbalPerformanceTestCase.php index 06bcee898bf..236cdf5acec 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestCase.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestCase.php @@ -26,15 +26,7 @@ class DbalPerformanceTestCase extends DbalFunctionalTestCase * * @var float */ - private $lastRunTime; - - public function setUp() - { - parent::setUp(); - - // Reset timing vars - $this->startTime = $this->lastRunTime = null; - } + private $runTime; /** * {@inheritdoc} @@ -43,7 +35,7 @@ protected function assertPostConditions() { // If a perf test doesn't start or stop, it fails. $this->assertNotNull($this->startTime, "Test timing was started"); - $this->assertNotNull($this->lastRunTime, "Test timing was stopped"); + $this->assertNotNull($this->runTime, "Test timing was stopped"); } /** @@ -59,7 +51,7 @@ protected function startTiming() */ protected function stopTiming() { - $this->lastRunTime = microtime(true) - $this->startTime; + $this->runTime = microtime(true) - $this->startTime; } /** @@ -67,6 +59,6 @@ protected function stopTiming() */ public function getTime() { - return $this->lastRunTime; + return $this->runTime; } } From b5c69fd3738d21b60deb4bd8cd25d88f8eb75d11 Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Fri, 11 Sep 2015 11:51:55 -0400 Subject: [PATCH 63/70] Make output of DbalPerformanceTestListener cleaner --- .../Tests/DbalPerformanceTestListener.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/DbalPerformanceTestListener.php b/tests/Doctrine/Tests/DbalPerformanceTestListener.php index 61ed9aa9748..485a8706446 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestListener.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestListener.php @@ -19,11 +19,15 @@ public function endTest(\PHPUnit_Framework_Test $test, $time) // This listener only applies to performance tests. if ($test instanceof \Doctrine\Tests\DbalPerformanceTestCase) { - // Identify perf tests by class, method, and dataset + // we identify perf tests by class, method, and dataset $class = str_replace('Doctrine\Tests\DBAL\Performance\\', '', get_class($test)); + if (!isset($this->timings[$class])) { + $this->timings[$class] = []; + } + // Store timing data for each test in the order they were run. - $this->timings[$class . "::" . $test->getName(true)] = $test->getTime(); + $this->timings[$class][$test->getName(true)] = $test->getTime(); } } @@ -37,10 +41,13 @@ public function __destruct() { if (!empty($this->timings)) { // Report timings. - print("\n\nPerformance test results:\n\n"); + print("\nPerformance test results:\n\n"); - foreach($this->timings as $test => $time) { - printf("%s: %.3f\n", $test, $time); + foreach($this->timings as $class => $tests) { + printf("%s:\n", $class); + foreach($tests as $test => $time) { + printf("\t%s: %.3f\n", $test, $time); + } } } } From 888ccd48314c9cff0681142c18d03f8b16b6048b Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Fri, 11 Sep 2015 11:58:59 -0400 Subject: [PATCH 64/70] add 'seconds' to output --- tests/Doctrine/Tests/DbalPerformanceTestListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DbalPerformanceTestListener.php b/tests/Doctrine/Tests/DbalPerformanceTestListener.php index 485a8706446..62e3f937b23 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestListener.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestListener.php @@ -46,7 +46,7 @@ public function __destruct() foreach($this->timings as $class => $tests) { printf("%s:\n", $class); foreach($tests as $test => $time) { - printf("\t%s: %.3f\n", $test, $time); + printf( "\t%s: %.3f seconds\n", $test, $time); } } } From 27efd8664fd1292c9760dcfa51b2accd40b3ce98 Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Fri, 11 Sep 2015 11:59:46 -0400 Subject: [PATCH 65/70] remove weird whitespace --- tests/Doctrine/Tests/DbalPerformanceTestListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DbalPerformanceTestListener.php b/tests/Doctrine/Tests/DbalPerformanceTestListener.php index 62e3f937b23..2ae784ffca4 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestListener.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestListener.php @@ -46,7 +46,7 @@ public function __destruct() foreach($this->timings as $class => $tests) { printf("%s:\n", $class); foreach($tests as $test => $time) { - printf( "\t%s: %.3f seconds\n", $test, $time); + printf("\t%s: %.3f seconds\n", $test, $time); } } } From a9ff4503ee6f076b4e2d5771df708b3b0252a3f7 Mon Sep 17 00:00:00 2001 From: mRoca Date: Thu, 17 Sep 2015 11:04:54 +0200 Subject: [PATCH 66/70] Fix Mysql collation support documentation --- docs/en/reference/schema-representation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/schema-representation.rst b/docs/en/reference/schema-representation.rst index 94669a1550a..0a56dcc2e6a 100644 --- a/docs/en/reference/schema-representation.rst +++ b/docs/en/reference/schema-representation.rst @@ -134,7 +134,7 @@ The following options are completely vendor specific and absolutely not portable - **charset** (string): The character set to use for the column. Currently only supported on MySQL and Drizzle. - - **collate** (string): The collation to use for the column. Currently only supported on - SQL Server. + - **collation** (string): The collation to use for the column. Supported by MySQL, PostgreSQL, + Sqlite, SQL Server and Drizzle. - **check** (string): The check constraint clause to add to the column. Defaults to ``null``. From 9d2cab4011f0727fb8f098f2e4972d104e48a117 Mon Sep 17 00:00:00 2001 From: xelan Date: Fri, 18 Sep 2015 14:49:51 +0200 Subject: [PATCH 67/70] fix typo --- docs/en/reference/transactions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/transactions.rst b/docs/en/reference/transactions.rst index 83a32067b70..c8da7d4c75e 100644 --- a/docs/en/reference/transactions.rst +++ b/docs/en/reference/transactions.rst @@ -120,7 +120,7 @@ to avoid nesting transaction blocks. If this is not possible because the nested transaction blocks are in a third-party API you're out of luck. -All that is guaruanteed to the inner transaction is that it still +All that is guaranteed to the inner transaction is that it still happens atomically, all or nothing, the transaction just gets a wider scope and the control is handed to the outer scope. From 9b2f6484f4a2ac382cf6706584208cd965427de1 Mon Sep 17 00:00:00 2001 From: Vincent CHALAMON Date: Tue, 6 Oct 2015 10:06:16 +0200 Subject: [PATCH 68/70] Fix bug about get default params on PoolingShardConnection --- .../DBAL/Sharding/PoolingShardConnection.php | 2 +- .../DBAL/Sharding/PoolingShardConnectionTest.php | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php index 29c041e6dda..c5fb77681a6 100644 --- a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php +++ b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php @@ -141,7 +141,7 @@ public function getActiveShardId() */ public function getParams() { - return $this->activeShardId ? $this->connections[$this->activeShardId] : parent::getParams(); + return $this->activeShardId ? $this->connections[$this->activeShardId] : $this->connections[0]; } /** diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php index caf669928f6..a91fe5122b4 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php @@ -209,9 +209,9 @@ public function testGetParamsOverride() $conn = DriverManager::getConnection(array( 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), + 'global' => array('memory' => true, 'host' => 'localhost'), 'shards' => array( - array('id' => 1, 'memory' => true), + array('id' => 1, 'memory' => true, 'host' => 'foo'), ), 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', )); @@ -219,24 +219,27 @@ public function testGetParamsOverride() $this->assertEquals(array( 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), + 'global' => array('memory' => true, 'host' => 'localhost'), 'shards' => array( - array('id' => 1, 'memory' => true), + array('id' => 1, 'memory' => true, 'host' => 'foo'), ), 'shardChoser' => new MultiTenantShardChoser(), + 'memory' => true, + 'host' => 'localhost', ), $conn->getParams()); $conn->connect(1); $this->assertEquals(array( 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), + 'global' => array('memory' => true, 'host' => 'localhost'), 'shards' => array( - array('id' => 1, 'memory' => true), + array('id' => 1, 'memory' => true, 'host' => 'foo'), ), 'shardChoser' => new MultiTenantShardChoser(), 'id' => 1, 'memory' => true, + 'host' => 'foo', ), $conn->getParams()); } From 934c509a884182c6e8d30b3422ba799ebeeb4731 Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 12 Oct 2015 11:56:16 +0200 Subject: [PATCH 69/70] Correcting 2 anchors in the docs that didn't existed anymore --- docs/en/reference/data-retrieval-and-manipulation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/data-retrieval-and-manipulation.rst b/docs/en/reference/data-retrieval-and-manipulation.rst index c571b207182..7f45e98d3bf 100644 --- a/docs/en/reference/data-retrieval-and-manipulation.rst +++ b/docs/en/reference/data-retrieval-and-manipulation.rst @@ -327,7 +327,7 @@ returns the affected rows count: The ``$types`` variable contains the PDO or Doctrine Type constants to perform necessary type conversions between actual input parameters and expected database values. See the -`Types <./types#type-conversion>`_ section for more information. +`Types <./types#mapping-matrix>`_ section for more information. executeQuery() ~~~~~~~~~~~~~~ @@ -351,7 +351,7 @@ parameters to the execute method, then returning the statement: The ``$types`` variable contains the PDO or Doctrine Type constants to perform necessary type conversions between actual input parameters and expected database values. See the -`Types <./types#type-conversion>`_ section for more information. +`Types <./types#mapping-matrix>`_ section for more information. fetchAll() ~~~~~~~~~~ From 4fb3efa2af86bada7bfc1f06bf4b85d95a31112c Mon Sep 17 00:00:00 2001 From: Ilya Antipenko Date: Mon, 12 Oct 2015 17:47:50 +0300 Subject: [PATCH 70/70] Fix return type and mark as deprecated for Table::renameColumn --- lib/Doctrine/DBAL/Schema/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 857caeb0859..70157769839 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -331,7 +331,7 @@ public function addColumn($columnName, $typeName, array $options=array()) * @param string $oldColumnName * @param string $newColumnName * - * @return self + * @deprecated * * @throws DBALException */