diff --git a/.travis.yml b/.travis.yml
index 6dffaf89733..5d2223e955c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,6 @@
language: php
php:
- - 5.3
- 5.4
- 5.5
- 5.6
@@ -29,6 +28,69 @@ before_script:
script: ./vendor/bin/phpunit --configuration tests/travis/$DB.travis.xml
matrix:
+ include:
+ - 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.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.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/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
diff --git a/composer.json b/composer.json
index 9d9e7d3b1c5..516d079d16e 100644
--- a/composer.json
+++ b/composer.json
@@ -12,8 +12,8 @@
{"name": "Jonathan Wage", "email": "jonwage@gmail.com"}
],
"require": {
- "php": ">=5.3.2",
- "doctrine/common": ">=2.4,<2.6-dev"
+ "php": ">=5.4",
+ "doctrine/common": "~2.4"
},
"require-dev": {
"phpunit/phpunit": "4.*",
diff --git a/docs/README.md b/docs/README.md
index 8b42be3833f..4945e9de7df 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -1,8 +1,18 @@
# 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
-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
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
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.
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()
~~~~~~~~~~
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``.
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
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.
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/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/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/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/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/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
index 0e25b16ff90..db9d6829f46 100644
--- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
@@ -1043,7 +1043,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/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 8b3b284c932..8c8caa0a855 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/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/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/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
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/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
index 7d9e3c80147..6fc17583bd3 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/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
*/
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
+ );
}
}
diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php
index 3b6c6e1067d..c5fb77681a6 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] : $this->connections[0];
+ }
+
+ /**
+ * {@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/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.
*
diff --git a/lib/Doctrine/DBAL/Types/ConversionException.php b/lib/Doctrine/DBAL/Types/ConversionException.php
index 4675101b305..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,53 @@ 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
);
}
+
+ /**
+ * Thrown when the PHP value passed to the converter was not of the expected type.
+ *
+ * @param mixed $value
+ * @param string $toType
+ * @param string[] $possibleTypes
+ *
+ * @return \Doctrine\DBAL\Types\ConversionException
+ */
+ static public function conversionFailedInvalidType($value, $toType, array $possibleTypes)
+ {
+ $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)
+ ));
+ }
+
+ return new self(sprintf(
+ "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/lib/Doctrine/DBAL/Types/DateIntervalType.php b/lib/Doctrine/DBAL/Types/DateIntervalType.php
index 8b2c18e4710..27d1369bd93 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']);
}
/**
@@ -59,12 +56,17 @@ 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');
-
+ return new \DateInterval($value);
+ } catch (\Exception $exception) {
+ throw ConversionException::conversionFailedFormat($value, $this->getName(), 'PY-m-dTH:i:s', $exception);
}
-
- return $interval;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function requiresSQLCommentHint(AbstractPlatform $platform)
+ {
+ return true;
}
}
diff --git a/lib/Doctrine/DBAL/Types/DateTimeType.php b/lib/Doctrine/DBAL/Types/DateTimeType.php
index c5715a795c0..83ea69e4eed 100644
--- a/lib/Doctrine/DBAL/Types/DateTimeType.php
+++ b/lib/Doctrine/DBAL/Types/DateTimeType.php
@@ -49,8 +49,15 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
- return ($value !== null)
- ? $value->format($platform->getDateTimeFormatString()) : null;
+ if (null === $value) {
+ return $value;
+ }
+
+ if ($value instanceof \DateTime) {
+ return $value->format($platform->getDateTimeFormatString());
+ }
+
+ 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 2a9c6fa7b74..527aed19d2d 100644
--- a/lib/Doctrine/DBAL/Types/DateTimeTzType.php
+++ b/lib/Doctrine/DBAL/Types/DateTimeTzType.php
@@ -67,8 +67,15 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
- return ($value !== null)
- ? $value->format($platform->getDateTimeTzFormatString()) : null;
+ if (null === $value) {
+ return $value;
+ }
+
+ if ($value instanceof \DateTime) {
+ return $value->format($platform->getDateTimeTzFormatString());
+ }
+
+ 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 9d337558639..a5642a598f4 100644
--- a/lib/Doctrine/DBAL/Types/DateType.php
+++ b/lib/Doctrine/DBAL/Types/DateType.php
@@ -49,8 +49,15 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
- return ($value !== null)
- ? $value->format($platform->getDateFormatString()) : null;
+ if (null === $value) {
+ return $value;
+ }
+
+ if ($value instanceof \DateTime) {
+ return $value->format($platform->getDateFormatString());
+ }
+
+ 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 554d56dc062..34533d6ea1e 100644
--- a/lib/Doctrine/DBAL/Types/TimeType.php
+++ b/lib/Doctrine/DBAL/Types/TimeType.php
@@ -49,8 +49,15 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
- return ($value !== null)
- ? $value->format($platform->getTimeFormatString()) : null;
+ if (null === $value) {
+ return $value;
+ }
+
+ if ($value instanceof \DateTime) {
+ return $value->format($platform->getTimeFormatString());
+ }
+
+ throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateTime']);
}
/**
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index fe1d515e46b..79563caab02 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -46,6 +46,20 @@
./tests/Doctrine/Tests/DBAL
+ ./tests/Doctrine/Tests/DBAL/Performance
+
+
+ ./tests/Doctrine/Tests/DBAL/Performance
+
+
+
+
+
+
+
+ performance
+
+
\ No newline at end of file
diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
index 418aa15e8d7..cafc5f8feaf 100644
--- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
+++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
@@ -535,11 +535,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/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()
{
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..f345e88d92c
--- /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();
+ }
+}
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();
+ }
+}
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();
+ }
+}
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();
+ }
+}
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();
+ }
+}
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();
+ }
+}
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/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();
+ }
+}
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';
+ }
+}
diff --git a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
index ce5f20e70bb..25048d9b86f 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.");
@@ -64,8 +64,14 @@ public function testForeignKeyContraintViolationExceptionOnInsert()
$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,13 +80,17 @@ public function testForeignKeyContraintViolationExceptionOnInsert()
} catch (ForeignKeyConstraintViolationException $exception) {
$this->tearDownForeignKeyConstraintViolationExceptionTest();
+ throw $exception;
+ } catch (\Exception $exception) {
+ $this->tearDownForeignKeyConstraintViolationExceptionTest();
+
throw $exception;
}
$this->tearDownForeignKeyConstraintViolationExceptionTest();
}
- public function testForeignKeyContraintViolationExceptionOnUpdate()
+ public function testForeignKeyConstraintViolationExceptionOnUpdate()
{
if ( ! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) {
$this->markTestSkipped("Only fails on platforms with foreign key constraints.");
@@ -88,8 +98,14 @@ public function testForeignKeyContraintViolationExceptionOnUpdate()
$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,13 +114,17 @@ public function testForeignKeyContraintViolationExceptionOnUpdate()
} catch (ForeignKeyConstraintViolationException $exception) {
$this->tearDownForeignKeyConstraintViolationExceptionTest();
+ throw $exception;
+ } catch (\Exception $exception) {
+ $this->tearDownForeignKeyConstraintViolationExceptionTest();
+
throw $exception;
}
$this->tearDownForeignKeyConstraintViolationExceptionTest();
}
- public function testForeignKeyContraintViolationExceptionOnDelete()
+ public function testForeignKeyConstraintViolationExceptionOnDelete()
{
if ( ! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) {
$this->markTestSkipped("Only fails on platforms with foreign key constraints.");
@@ -112,8 +132,14 @@ public function testForeignKeyContraintViolationExceptionOnDelete()
$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,24 +148,34 @@ public function testForeignKeyContraintViolationExceptionOnDelete()
} catch (ForeignKeyConstraintViolationException $exception) {
$this->tearDownForeignKeyConstraintViolationExceptionTest();
+ throw $exception;
+ } catch (\Exception $exception) {
+ $this->tearDownForeignKeyConstraintViolationExceptionTest();
+
throw $exception;
}
$this->tearDownForeignKeyConstraintViolationExceptionTest();
}
- public function testForeignKeyContraintViolationExceptionOnTruncate()
+ 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 testForeignKeyContraintViolationExceptionOnTruncate()
} catch (ForeignKeyConstraintViolationException $exception) {
$this->tearDownForeignKeyConstraintViolationExceptionTest();
+ throw $exception;
+ } catch (\Exception $exception) {
+ $this->tearDownForeignKeyConstraintViolationExceptionTest();
+
throw $exception;
}
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/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
index a2cf7311d6d..dbeecab8480 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
*/
@@ -706,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
*/
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/Performance/TypeConversionPerformanceTest.php b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php
new file mode 100644
index 00000000000..42c549aa399
--- /dev/null
+++ b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php
@@ -0,0 +1,41 @@
+_conn->getDatabasePlatform();
+ $this->startTiming();
+ for ($i = 0; $i < $count; $i++) {
+ $type->convertToDatabaseValue($value, $platform);
+ }
+ $this->stopTiming();
+ }
+
+ public function itemCountProvider()
+ {
+ return [
+ '100 items' => [100],
+ '1000 items' => [1000],
+ '10000 items' => [10000],
+ '100000 items' => [100000],
+ ];
+ }
+}
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 58da19b7397..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
*/
@@ -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/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/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')
+ );
+ }
}
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');
}
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/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
+}
diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php
index c0a446bddf1..a91fe5122b4 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(
@@ -72,11 +73,11 @@ public function testNoGlobalServerException()
));
}
- public function testNoShardsServersExecption()
+ 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),
@@ -84,11 +85,11 @@ public function testNoShardsServersExecption()
));
}
- public function testNoShardsChoserExecption()
+ 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,143 @@ 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, 'host' => 'localhost'),
+ 'shards' => array(
+ array('id' => 1, 'memory' => true, 'host' => 'foo'),
+ ),
+ 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser',
+ ));
+
+ $this->assertEquals(array(
+ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection',
+ 'driver' => 'pdo_sqlite',
+ 'global' => array('memory' => true, 'host' => 'localhost'),
+ 'shards' => array(
+ 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, 'host' => 'localhost'),
+ 'shards' => array(
+ array('id' => 1, 'memory' => true, 'host' => 'foo'),
+ ),
+ 'shardChoser' => new MultiTenantShardChoser(),
+ 'id' => 1,
+ 'memory' => true,
+ 'host' => 'foo',
+ ), $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());
+ }
+}
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));
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/ConversionExceptionTest.php b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php
new file mode 100644
index 00000000000..5aa797895fd
--- /dev/null
+++ b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php
@@ -0,0 +1,83 @@
+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()
+ );
+ }
+ /**
+ * @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()
+ );
+ }
+
+ 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[][]
+ */
+ public function nonScalarsProvider()
+ {
+ return [
+ [[]],
+ [['foo']],
+ [null],
+ [$this],
+ [new \stdClass()],
+ [tmpfile()],
+ ];
+ }
+
+ /**
+ * @return mixed[][]
+ */
+ public function scalarsProvider()
+ {
+ return [
+ [''],
+ ['foo'],
+ [123],
+ [-123],
+ [12.34],
+ [true],
+ [false],
+ ];
+ }
+}
diff --git a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php
index 95f5233a12c..8d212001a71 100644
--- a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php
+++ b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php
@@ -7,14 +7,25 @@
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');
+
+ $this->assertInstanceOf('Doctrine\DBAL\Types\DateIntervalType', $this->type);
}
public function testDateIntervalConvertsToDatabaseValue()
@@ -22,14 +33,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,11 +48,54 @@ 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));
+ }
+
+ /**
+ * @group DBAL-1288
+ */
+ public function testRequiresSQLCommentHint()
+ {
+ $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()],
+ ];
}
}
diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php
index f90ebb581ca..108eb502755 100644
--- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php
+++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php
@@ -3,46 +3,31 @@
namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Types\Type;
-use Doctrine\Tests\DBAL\Mocks\MockPlatform;
-class DateTest extends \Doctrine\Tests\DbalTestCase
+class DateTest extends BaseDateTypeTestCase
{
- protected
- $_platform,
- $_type,
- $_tz;
-
+ /**
+ * {@inheritDoc}
+ */
protected function setUp()
{
- $this->_platform = new MockPlatform();
- $this->_type = Type::getType('date');
- $this->_tz = date_default_timezone_get();
- }
+ $this->type = Type::getType('date');
- public function tearDown()
- {
- date_default_timezone_set($this->_tz);
- }
-
- public function testDateConvertsToDatabaseValue()
- {
- $this->assertTrue(
- is_string($this->_type->convertToDatabaseValue(new \DateTime(), $this->_platform))
- );
+ parent::setUp();
}
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'));
}
@@ -51,11 +36,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'));
}
@@ -63,17 +48,6 @@ public function testDateRests_SummerTimeAffection()
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));
+ $this->type->convertToPHPValue('abcdefg', $this->platform);
}
}
diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php
index 3fac40c13d0..9d9720118bf 100644
--- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php
+++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php
@@ -3,26 +3,25 @@
namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Types\Type;
-use Doctrine\Tests\DBAL\Mocks\MockPlatform;
-class DateTimeTest extends \Doctrine\Tests\DbalTestCase
+class DateTimeTest extends BaseDateTypeTestCase
{
- protected
- $_platform,
- $_type;
-
+ /**
+ * {@inheritDoc}
+ */
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);
}
@@ -30,7 +29,7 @@ public function testDateTimeConvertsToDatabaseValue()
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'));
}
@@ -38,25 +37,14 @@ 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'));
}
diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php
index cf9c4779a8c..94366e87d15 100644
--- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php
+++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php
@@ -3,26 +3,25 @@
namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Types\Type;
-use Doctrine\Tests\DBAL\Mocks\MockPlatform;
-class DateTimeTzTest extends \Doctrine\Tests\DbalTestCase
+class DateTimeTzTest extends BaseDateTypeTestCase
{
- protected
- $_platform,
- $_type;
-
+ /**
+ * {@inheritDoc}
+ */
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);
}
@@ -30,7 +29,7 @@ public function testDateTimeConvertsToDatabaseValue()
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'));
}
@@ -38,17 +37,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));
+ $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 6ba6b9f9221..8e4dbb940b3 100644
--- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php
+++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php
@@ -3,38 +3,28 @@
namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Types\Type;
-use Doctrine\Tests\DBAL\Mocks\MockPlatform;
-class TimeTest extends \Doctrine\Tests\DbalTestCase
+class TimeTest extends BaseDateTypeTestCase
{
- protected
- $_platform,
- $_type;
-
+ /**
+ * {@inheritDoc}
+ */
protected function setUp()
{
- $this->_platform = new MockPlatform();
- $this->_type = Type::getType('time');
- }
+ $this->type = Type::getType('time');
- public function testTimeConvertsToDatabaseValue()
- {
- $this->assertTrue(
- is_string($this->_type->convertToDatabaseValue(new \DateTime(), $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'));
}
@@ -42,17 +32,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));
+ $this->type->convertToPHPValue('abcdefg', $this->platform);
}
}
diff --git a/tests/Doctrine/Tests/DbalPerformanceTestCase.php b/tests/Doctrine/Tests/DbalPerformanceTestCase.php
new file mode 100644
index 00000000000..236cdf5acec
--- /dev/null
+++ b/tests/Doctrine/Tests/DbalPerformanceTestCase.php
@@ -0,0 +1,64 @@
+assertNotNull($this->startTime, "Test timing was started");
+ $this->assertNotNull($this->runTime, "Test timing was stopped");
+ }
+
+ /**
+ * begin timing
+ */
+ protected function startTiming()
+ {
+ $this->startTime = microtime(true);
+ }
+
+ /**
+ * end timing
+ */
+ protected function stopTiming()
+ {
+ $this->runTime = microtime(true) - $this->startTime;
+ }
+
+ /**
+ * @return float elapsed test execution time
+ */
+ public function getTime()
+ {
+ return $this->runTime;
+ }
+}
diff --git a/tests/Doctrine/Tests/DbalPerformanceTestListener.php b/tests/Doctrine/Tests/DbalPerformanceTestListener.php
new file mode 100644
index 00000000000..2ae784ffca4
--- /dev/null
+++ b/tests/Doctrine/Tests/DbalPerformanceTestListener.php
@@ -0,0 +1,54 @@
+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();
+ }
+ }
+
+ /**
+ * Report performance test timings.
+ *
+ * Note: __destruct is used here because PHPUnit doesn't have a
+ * 'All tests over' hook.
+ */
+ public function __destruct()
+ {
+ if (!empty($this->timings)) {
+ // Report timings.
+ print("\nPerformance test results:\n\n");
+
+ foreach($this->timings as $class => $tests) {
+ printf("%s:\n", $class);
+ foreach($tests as $test => $time) {
+ printf("\t%s: %.3f seconds\n", $test, $time);
+ }
+ }
+ }
+ }
+}
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
+
+
+
+
+