Commit 3f592b4a authored by Steve Müller's avatar Steve Müller

Merge branch 'master' into 2.5

Conflicts:
	lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
parents 99cad2c8 7d17c013
...@@ -21,6 +21,18 @@ You can get a DBAL Connection through the ...@@ -21,6 +21,18 @@ You can get a DBAL Connection through the
); );
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
Or, using the simpler URL form:
.. code-block:: php
<?php
$config = new \Doctrine\DBAL\Configuration();
//..
$connectionParams = array(
'url' => 'mysql://user:secret@localhost/mydb',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
The ``DriverManager`` returns an instance of The ``DriverManager`` returns an instance of
``Doctrine\DBAL\Connection`` which is a wrapper around the ``Doctrine\DBAL\Connection`` which is a wrapper around the
underlying driver connection (which is often a PDO instance). underlying driver connection (which is often a PDO instance).
...@@ -28,6 +40,84 @@ underlying driver connection (which is often a PDO instance). ...@@ -28,6 +40,84 @@ underlying driver connection (which is often a PDO instance).
The following sections describe the available connection parameters The following sections describe the available connection parameters
in detail. in detail.
Connecting using a URL
~~~~~~~~~~~~~~~~~~~~~~
The easiest way to specify commonly used connection parameters is
using a database URL. The scheme is used to specify a driver, the
user and password in the URL encode user and password for the
connection, followed by the host and port parts (the "authority").
The path after the authority part represents the name of the
database, sans the leading slash. Any query parameters are used as
additional connection parameters.
The scheme names representing the drivers are either the regular
driver names (see below) with any underscores in their name replaced
with a hyphen (to make them legal in URL scheme names), or one of the
following simplified driver names that serve as aliases:
- ``db2``: alias for ``ibm_db2``
- ``mssql``: alias for ``pdo_sqlsrv``
- ``mysql``/``mysql2``: alias for ``pdo_mysql``
- ``pgsql``/``postgres``/``postgresql``: alias for ``pdo_pgsql``
- ``sqlite``/``sqlite3``: alias for ``pdo_sqlite``
For example, to connect to a "foo" MySQL DB using the ``pdo_mysql``
driver on localhost port 4486 with the charset set to UTF-8, you
would use the following URL::
mysql://localhost:4486/foo?charset=UTF-8
This is identical to the following connection string using the
full driver name::
pdo-mysql://localhost:4486/foo?charset=UTF-8
If you wanted to use the ``drizzle_pdo__mysql`` driver instead::
drizzle-pdo-mysql://localhost:4486/foo?charset=UTF-8
In the two last example above, mind the dashes instead of the
underscores in the URL schemes.
For connecting to an SQLite database, the authority portion of the
URL is obviously irrelevant and thus can be omitted. The path part
of the URL is, like for all other drivers, stripped of its leading
slash, resulting in a relative file name for the database::
sqlite:///somedb.sqlite
This would access ``somedb.sqlite`` in the current working directory
and is identical to the following::
sqlite://ignored:ignored@ignored:1234/somedb.sqlite
To specify an absolute file path, e.g. ``/usr/local/var/db.sqlite``,
simply use that as the database name, which results in two leading
slashes for the path part of the URL, and four slashes in total after
the URL scheme name and its following colon::
sqlite:////usr/local/var/db.sqlite
Which is, again, identical to supplying ignored user/pass/authority::
sqlite://notused:inthis@case//usr/local/var/db.sqlite
To connect to an in-memory SQLite instance, use ``:memory::`` as the
database name::
sqlite:///:memory:
.. note::
Any information extracted from the URL overwrites existing values
for the parameter in question, but the rest of the information
is merged together. You could, for example, have a URL without
the ``charset`` setting in the query string, and then add a
``charset`` connection parameter next to ``url``, to provide a
default value in case the URL doesn't contain a charset value.
Driver Driver
~~~~~~ ~~~~~~
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
namespace Doctrine\DBAL; namespace Doctrine\DBAL;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use PDO; use PDO;
use Closure; use Closure;
use Exception; use Exception;
...@@ -570,9 +571,15 @@ class Connection implements DriverConnection ...@@ -570,9 +571,15 @@ class Connection implements DriverConnection
* @param array $types The types of identifiers. * @param array $types The types of identifiers.
* *
* @return integer The number of affected rows. * @return integer The number of affected rows.
*
* @throws InvalidArgumentException
*/ */
public function delete($tableExpression, array $identifier, array $types = array()) public function delete($tableExpression, array $identifier, array $types = array())
{ {
if (empty($identifier)) {
throw InvalidArgumentException::fromEmptyCriteria();
}
$this->connect(); $this->connect();
$criteria = array(); $criteria = array();
...@@ -581,13 +588,11 @@ class Connection implements DriverConnection ...@@ -581,13 +588,11 @@ class Connection implements DriverConnection
$criteria[] = $columnName . ' = ?'; $criteria[] = $columnName . ' = ?';
} }
if (is_string(key($types))) { return $this->executeUpdate(
$types = $this->extractTypeValues($identifier, $types); 'DELETE FROM ' . $tableExpression . ' WHERE ' . implode(' AND ', $criteria),
} array_values($identifier),
is_string(key($types)) ? $this->extractTypeValues($identifier, $types) : $types
$query = 'DELETE FROM ' . $tableExpression . ' WHERE ' . implode(' AND ', $criteria); );
return $this->executeUpdate($query, array_values($identifier), $types);
} }
/** /**
......
...@@ -290,6 +290,9 @@ class MasterSlaveConnection extends Connection ...@@ -290,6 +290,9 @@ class MasterSlaveConnection extends Connection
unset($this->connections['slave']); unset($this->connections['slave']);
parent::close(); parent::close();
$this->_conn = null;
$this->connections = array('master' => null, 'slave' => null);
} }
/** /**
......
...@@ -23,6 +23,7 @@ use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; ...@@ -23,6 +23,7 @@ use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use PDOException; use PDOException;
use PDO;
/** /**
* Driver that connects through pdo_pgsql. * Driver that connects through pdo_pgsql.
...@@ -37,12 +38,22 @@ class Driver extends AbstractPostgreSQLDriver ...@@ -37,12 +38,22 @@ class Driver extends AbstractPostgreSQLDriver
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{ {
try { try {
return new PDOConnection( $pdo = new PDOConnection(
$this->_constructPdoDsn($params), $this->_constructPdoDsn($params),
$username, $username,
$password, $password,
$driverOptions $driverOptions
); );
if (PHP_VERSION_ID >= 50600
&& (! isset($driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES])
|| true === $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES]
)
) {
$pdo->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true);
}
return $pdo;
} catch (PDOException $e) { } catch (PDOException $e) {
throw DBALException::driverException($this, $e); throw DBALException::driverException($this, $e);
} }
......
...@@ -51,6 +51,21 @@ final class DriverManager ...@@ -51,6 +51,21 @@ final class DriverManager
'sqlsrv' => 'Doctrine\DBAL\Driver\SQLSrv\Driver', 'sqlsrv' => 'Doctrine\DBAL\Driver\SQLSrv\Driver',
); );
/**
* List of URL schemes from a database URL and their mappings to driver.
*/
private static $driverSchemeAliases = array(
'db2' => 'ibm_db2',
'mssql' => 'pdo_sqlsrv',
'mysql' => 'pdo_mysql',
'mysql2' => 'pdo_mysql', // Amazon RDS, for some weird reason
'postgres' => 'pdo_pgsql',
'postgresql' => 'pdo_pgsql',
'pgsql' => 'pdo_pgsql',
'sqlite' => 'pdo_sqlite',
'sqlite3' => 'pdo_sqlite',
);
/** /**
* Private constructor. This class cannot be instantiated. * Private constructor. This class cannot be instantiated.
*/ */
...@@ -126,6 +141,8 @@ final class DriverManager ...@@ -126,6 +141,8 @@ final class DriverManager
$eventManager = new EventManager(); $eventManager = new EventManager();
} }
$params = self::parseDatabaseUrl($params);
// check for existing pdo object // check for existing pdo object
if (isset($params['pdo']) && ! $params['pdo'] instanceof \PDO) { if (isset($params['pdo']) && ! $params['pdo'] instanceof \PDO) {
throw DBALException::invalidPdoInstance(); throw DBALException::invalidPdoInstance();
...@@ -194,4 +211,66 @@ final class DriverManager ...@@ -194,4 +211,66 @@ final class DriverManager
throw DBALException::invalidDriverClass($params['driverClass']); throw DBALException::invalidDriverClass($params['driverClass']);
} }
} }
/**
* Extracts parts from a database URL, if present, and returns an
* updated list of parameters.
*
* @param array $params The list of parameters.
*
* @param array A modified list of parameters with info from a database
* URL extracted into indidivual parameter parts.
*
*/
private static function parseDatabaseUrl(array $params)
{
if (!isset($params['url'])) {
return $params;
}
// (pdo_)?sqlite3?:///... => (pdo_)?sqlite3?://localhost/... or else the URL will be invalid
$url = preg_replace('#^((?:pdo_)?sqlite3?):///#', '$1://localhost/', $params['url']);
$url = parse_url($url);
if ($url === false) {
throw new DBALException('Malformed parameter "url".');
}
if (isset($url['scheme'])) {
$params['driver'] = str_replace('-', '_', $url['scheme']); // URL schemes must not contain underscores, but dashes are ok
if (isset(self::$driverSchemeAliases[$params['driver']])) {
$params['driver'] = self::$driverSchemeAliases[$params['driver']]; // use alias like "postgres", else we just let checkParams decide later if the driver exists (for literal "pdo-pgsql" etc)
}
}
if (isset($url['host'])) {
$params['host'] = $url['host'];
}
if (isset($url['port'])) {
$params['port'] = $url['port'];
}
if (isset($url['user'])) {
$params['user'] = $url['user'];
}
if (isset($url['pass'])) {
$params['password'] = $url['pass'];
}
if (isset($url['path'])) {
if (!isset($url['scheme']) || (strpos($url['scheme'], 'sqlite') !== false && $url['path'] == ':memory:')) {
$params['dbname'] = $url['path']; // if the URL was just "sqlite::memory:", which parses to scheme and path only
} else {
$params['dbname'] = substr($url['path'], 1); // strip the leading slash from the URL
}
}
if (isset($url['query'])) {
$query = array();
parse_str($url['query'], $query); // simply ingest query as extra params, e.g. charset or sslmode
$params = array_merge($params, $query); // parse_str wipes existing array elements
}
return $params;
}
} }
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Exception;
use Doctrine\DBAL\DBALException;
/**
* Exception to be thrown when invalid arguments are passed to any DBAL API
*
* @author Marco Pivetta <ocramius@gmail.com>
* @link www.doctrine-project.org
* @since 2.5
*/
class InvalidArgumentException extends DBALException
{
/**
* @return self
*/
public static function fromEmptyCriteria()
{
return new self('Empty criteria was used, expected non-empty criteria');
}
}
...@@ -264,7 +264,8 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -264,7 +264,8 @@ class PostgreSqlPlatform extends AbstractPlatform
WHERE table_schema NOT LIKE 'pg_%' WHERE table_schema NOT LIKE 'pg_%'
AND table_schema != 'information_schema' AND table_schema != 'information_schema'
AND table_name != 'geometry_columns' AND table_name != 'geometry_columns'
AND table_name != 'spatial_ref_sys'"; AND table_name != 'spatial_ref_sys'
AND table_type != 'VIEW'";
} }
/** /**
......
...@@ -813,7 +813,8 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -813,7 +813,8 @@ class SQLServerPlatform extends AbstractPlatform
public function getListTablesSQL() public function getListTablesSQL()
{ {
// "sysdiagrams" table must be ignored as it's internal SQL Server table for Database Diagrams // "sysdiagrams" table must be ignored as it's internal SQL Server table for Database Diagrams
return "SELECT name FROM sysobjects WHERE type = 'U' AND name != 'sysdiagrams' ORDER BY name"; // Category 2 must be ignored as it is "MS SQL Server 'pseudo-system' object[s]" for replication
return "SELECT name FROM sysobjects WHERE type = 'U' AND name != 'sysdiagrams' AND category != 2 ORDER BY name";
} }
/** /**
......
...@@ -198,7 +198,7 @@ class QueryBuilder ...@@ -198,7 +198,7 @@ class QueryBuilder
* Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate} * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate}
* for insert, update and delete statements. * for insert, update and delete statements.
* *
* @return mixed * @return \Doctrine\DBAL\Driver\Statement|int
*/ */
public function execute() public function execute()
{ {
......
...@@ -466,4 +466,20 @@ SQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\""); ...@@ -466,4 +466,20 @@ SQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\"");
$this->assertTrue($conn->isConnected(), "Connection is not connected after passing external PDO"); $this->assertTrue($conn->isConnected(), "Connection is not connected after passing external PDO");
} }
public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException()
{
/* @var $driver \Doctrine\DBAL\Driver */
$driver = $this->getMock('Doctrine\DBAL\Driver');
$pdoMock = $this->getMock('Doctrine\DBAL\Driver\Connection');
// should never execute queries with invalid arguments
$pdoMock->expects($this->never())->method('exec');
$pdoMock->expects($this->never())->method('prepare');
$conn = new Connection(array('pdo' => $pdoMock), $driver);
$this->setExpectedException('Doctrine\DBAL\Exception\InvalidArgumentException');
$conn->delete('kittens', array());
}
} }
...@@ -4,6 +4,8 @@ namespace Doctrine\Tests\DBAL\Driver\PDOPgSql; ...@@ -4,6 +4,8 @@ namespace Doctrine\Tests\DBAL\Driver\PDOPgSql;
use Doctrine\DBAL\Driver\PDOPgSql\Driver; use Doctrine\DBAL\Driver\PDOPgSql\Driver;
use Doctrine\Tests\DBAL\Driver\AbstractPostgreSQLDriverTest; use Doctrine\Tests\DBAL\Driver\AbstractPostgreSQLDriverTest;
use PDO;
use PDOException;
class DriverTest extends AbstractPostgreSQLDriverTest class DriverTest extends AbstractPostgreSQLDriverTest
{ {
...@@ -12,8 +14,105 @@ class DriverTest extends AbstractPostgreSQLDriverTest ...@@ -12,8 +14,105 @@ class DriverTest extends AbstractPostgreSQLDriverTest
$this->assertSame('pdo_pgsql', $this->driver->getName()); $this->assertSame('pdo_pgsql', $this->driver->getName());
} }
/**
* @group DBAL-920
*/
public function testConnectionDisablesPreparesOnPhp56()
{
$this->skipWhenNotUsingPhp56AndPdoPgsql();
$connection = $this->createDriver()->connect(
array(
'host' => $GLOBALS['db_host'],
'port' => $GLOBALS['db_port']
),
$GLOBALS['db_username'],
$GLOBALS['db_password']
);
$this->assertInstanceOf('Doctrine\DBAL\Driver\PDOConnection', $connection);
try {
$this->assertTrue($connection->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES));
} catch (PDOException $ignored) {
/** @link https://bugs.php.net/bug.php?id=68371 */
$this->markTestIncomplete('See https://bugs.php.net/bug.php?id=68371');
}
}
/**
* @group DBAL-920
*/
public function testConnectionDoesNotDisablePreparesOnPhp56WhenAttributeDefined()
{
$this->skipWhenNotUsingPhp56AndPdoPgsql();
$connection = $this->createDriver()->connect(
array(
'host' => $GLOBALS['db_host'],
'port' => $GLOBALS['db_port']
),
$GLOBALS['db_username'],
$GLOBALS['db_password'],
array(PDO::PGSQL_ATTR_DISABLE_PREPARES => false)
);
$this->assertInstanceOf('Doctrine\DBAL\Driver\PDOConnection', $connection);
try {
$this->assertNotSame(true, $connection->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES));
} catch (PDOException $ignored) {
/** @link https://bugs.php.net/bug.php?id=68371 */
$this->markTestIncomplete('See https://bugs.php.net/bug.php?id=68371');
}
}
/**
* @group DBAL-920
*/
public function testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplicitlyDefined()
{
$this->skipWhenNotUsingPhp56AndPdoPgsql();
$connection = $this->createDriver()->connect(
array(
'host' => $GLOBALS['db_host'],
'port' => $GLOBALS['db_port']
),
$GLOBALS['db_username'],
$GLOBALS['db_password'],
array(PDO::PGSQL_ATTR_DISABLE_PREPARES => true)
);
$this->assertInstanceOf('Doctrine\DBAL\Driver\PDOConnection', $connection);
try {
$this->assertTrue($connection->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES));
} catch (PDOException $ignored) {
/** @link https://bugs.php.net/bug.php?id=68371 */
$this->markTestIncomplete('See https://bugs.php.net/bug.php?id=68371');
}
}
/**
* {@inheritDoc}
*/
protected function createDriver() protected function createDriver()
{ {
return new Driver(); return new Driver();
} }
/**
* @throws \PHPUnit_Framework_SkippedTestError
*/
private function skipWhenNotUsingPhp56AndPdoPgsql()
{
if (PHP_VERSION_ID < 50600) {
$this->markTestSkipped('Test requires PHP 5.6+');
}
if (! (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_pgsql')) {
$this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml');
}
}
} }
...@@ -114,4 +114,91 @@ class DriverManagerTest extends \Doctrine\Tests\DbalTestCase ...@@ -114,4 +114,91 @@ class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
$conn = \Doctrine\DBAL\DriverManager::getConnection($options); $conn = \Doctrine\DBAL\DriverManager::getConnection($options);
$this->assertInstanceOf('Doctrine\DBAL\Driver\PDOMySql\Driver', $conn->getDriver()); $this->assertInstanceOf('Doctrine\DBAL\Driver\PDOMySql\Driver', $conn->getDriver());
} }
/**
* @dataProvider databaseUrls
*/
public function testDatabaseUrl($url, $expected)
{
$options = is_array($url) ? $url : array(
'url' => $url,
);
if ($expected === false) {
$this->setExpectedException('Doctrine\DBAL\DBALException');
}
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
$params = $conn->getParams();
foreach ($expected as $key => $value) {
if ($key == 'driver') {
$this->assertInstanceOf($value, $conn->getDriver());
} else {
$this->assertEquals($value, $params[$key]);
}
}
}
public function databaseUrls()
{
return array(
'simple URL' => array(
'mysql://foo:bar@localhost/baz',
array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'),
),
'simple URL with port' => array(
'mysql://foo:bar@localhost:11211/baz',
array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'port' => 11211, 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'),
),
'sqlite relative URL with host' => array(
'sqlite://localhost/foo/dbname.sqlite',
array('dbname' => 'foo/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
),
'sqlite absolute URL with host' => array(
'sqlite://localhost//tmp/dbname.sqlite',
array('dbname' => '/tmp/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
),
'sqlite relative URL without host' => array(
'sqlite:///foo/dbname.sqlite',
array('dbname' => 'foo/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
),
'sqlite absolute URL without host' => array(
'sqlite:////tmp/dbname.sqlite',
array('dbname' => '/tmp/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
),
'sqlite memory' => array(
'sqlite:///:memory:',
array('dbname' => ':memory:', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
),
'sqlite memory with host' => array(
'sqlite://localhost/:memory:',
array('dbname' => ':memory:', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'),
),
'params parsed from URL override individual params' => array(
array('url' => 'mysql://foo:bar@localhost/baz', 'password' => 'lulz'),
array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'),
),
'params not parsed from URL but individual params are preserved' => array(
array('url' => 'mysql://foo:bar@localhost/baz', 'port' => 1234),
array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'port' => 1234, 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'),
),
'query params from URL are used as extra params' => array(
'url' => 'mysql://foo:bar@localhost/dbname?charset=UTF-8',
array('charset' => 'UTF-8'),
),
'simple URL with fallthrough scheme not defined in map' => array(
'sqlsrv://foo:bar@localhost/baz',
array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\SQLSrv\Driver'),
),
'simple URL with fallthrough scheme containing underscores fails' => array(
'drizzle_pdo_mysql://foo:bar@localhost/baz',
false,
),
'simple URL with fallthrough scheme containing dashes works' => array(
'drizzle-pdo-mysql://foo:bar@localhost/baz',
array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver'),
),
);
}
} }
\ No newline at end of file
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Tests\DBAL\Exception;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use PHPUnit_Framework_TestCase;
/**
* Tests for {@see \Doctrine\DBAL\Exception\InvalidArgumentException}
*
* @covers \Doctrine\DBAL\Exception\InvalidArgumentException
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class InvalidArgumentExceptionTest extends PHPUnit_Framework_TestCase
{
public function testFromEmptyCriteria()
{
$exception = InvalidArgumentException::fromEmptyCriteria();
$this->assertInstanceOf('Doctrine\DBAL\Exception\InvalidArgumentException', $exception);
$this->assertSame('Empty criteria was used, expected non-empty criteria', $exception->getMessage());
}
}
...@@ -126,4 +126,17 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase ...@@ -126,4 +126,17 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase
$conn->connect('slave'); $conn->connect('slave');
$this->assertFalse($conn->isConnectedToMaster()); $this->assertFalse($conn->isConnectedToMaster());
} }
public function testMasterSlaveConnectionCloseAndReconnect()
{
$conn = $this->createMasterSlaveConnection();
$conn->connect('master');
$this->assertTrue($conn->isConnectedToMaster());
$conn->close();
$this->assertFalse($conn->isConnectedToMaster());
$conn->connect('master');
$this->assertTrue($conn->isConnectedToMaster());
}
} }
...@@ -319,6 +319,30 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -319,6 +319,30 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertFalse($comparator->diffTable($offlineTable, $onlineTable)); $this->assertFalse($comparator->diffTable($offlineTable, $onlineTable));
} }
public function testListTablesExcludesViews()
{
$this->createTestTable('list_tables_excludes_views');
$name = "list_tables_excludes_views_test_view";
$sql = "SELECT * from list_tables_excludes_views";
$view = new Schema\View($name, $sql);
$this->_sm->dropAndCreateView($view);
$tables = $this->_sm->listTables();
$foundTable = false;
foreach ($tables as $table) {
$this->assertInstanceOf('Doctrine\DBAL\Schema\Table', $table, 'No Table instance was found in tables array.');
if (strtolower($table->getName()) == 'list_tables_excludes_views_test_view') {
$foundTable = true;
}
}
$this->assertFalse($foundTable, 'View "list_tables_excludes_views_test_view" must not be found in table list');
}
} }
class MoneyType extends Type class MoneyType extends Type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment