Vendor update && Started using DoctrineMigrations
This commit is contained in:
6
vendor/doctrine/dbal/.gitignore
vendored
Normal file
6
vendor/doctrine/dbal/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
build/
|
||||
logs/
|
||||
reports/
|
||||
dist/
|
||||
download/
|
||||
lib/Doctrine/Common/
|
9
vendor/doctrine/dbal/.gitmodules
vendored
Normal file
9
vendor/doctrine/dbal/.gitmodules
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
[submodule "lib/vendor/doctrine-common"]
|
||||
path = lib/vendor/doctrine-common
|
||||
url = git://github.com/doctrine/common.git
|
||||
[submodule "lib/vendor/Symfony/Component/Console"]
|
||||
path = lib/vendor/Symfony/Component/Console
|
||||
url = git://github.com/symfony/Console.git
|
||||
[submodule "lib/vendor/doctrine-build-common"]
|
||||
path = lib/vendor/doctrine-build-common
|
||||
url = git://github.com/doctrine/doctrine-build-common.git
|
4
vendor/doctrine/dbal/bin/doctrine-dbal
vendored
Normal file
4
vendor/doctrine/dbal/bin/doctrine-dbal
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
include('doctrine-dbal.php');
|
43
vendor/doctrine/dbal/bin/doctrine-dbal.php
vendored
Normal file
43
vendor/doctrine/dbal/bin/doctrine-dbal.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
require_once 'Doctrine/Common/ClassLoader.php';
|
||||
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine');
|
||||
$classLoader->register();
|
||||
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'Doctrine');
|
||||
$classLoader->register();
|
||||
|
||||
$configFile = getcwd() . DIRECTORY_SEPARATOR . 'cli-config.php';
|
||||
|
||||
$helperSet = null;
|
||||
if (file_exists($configFile)) {
|
||||
if ( ! is_readable($configFile)) {
|
||||
trigger_error(
|
||||
'Configuration file [' . $configFile . '] does not have read permission.', E_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
require $configFile;
|
||||
|
||||
foreach ($GLOBALS as $helperSetCandidate) {
|
||||
if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) {
|
||||
$helperSet = $helperSetCandidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$helperSet = ($helperSet) ?: new \Symfony\Component\Console\Helper\HelperSet();
|
||||
|
||||
$cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', Doctrine\DBAL\Version::VERSION);
|
||||
$cli->setCatchExceptions(true);
|
||||
$cli->setHelperSet($helperSet);
|
||||
$cli->addCommands(array(
|
||||
// DBAL Commands
|
||||
new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(),
|
||||
new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(),
|
||||
new \Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand(),
|
||||
|
||||
));
|
||||
$cli->run();
|
42
vendor/doctrine/dbal/bin/doctrine.php
vendored
Normal file
42
vendor/doctrine/dbal/bin/doctrine.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
require_once 'Doctrine/Common/ClassLoader.php';
|
||||
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine');
|
||||
$classLoader->register();
|
||||
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'Doctrine');
|
||||
$classLoader->register();
|
||||
|
||||
$configFile = getcwd() . DIRECTORY_SEPARATOR . 'cli-config.php';
|
||||
|
||||
$helperSet = null;
|
||||
if (file_exists($configFile)) {
|
||||
if ( ! is_readable($configFile)) {
|
||||
trigger_error(
|
||||
'Configuration file [' . $configFile . '] does not have read permission.', E_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
require $configFile;
|
||||
|
||||
foreach ($GLOBALS as $helperSetCandidate) {
|
||||
if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) {
|
||||
$helperSet = $helperSetCandidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$helperSet = ($helperSet) ?: new \Symfony\Component\Console\Helper\HelperSet();
|
||||
|
||||
$cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', Doctrine\DBAL\Version::VERSION);
|
||||
$cli->setCatchExceptions(true);
|
||||
$cli->setHelperSet($helperSet);
|
||||
$cli->addCommands(array(
|
||||
// DBAL Commands
|
||||
new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(),
|
||||
new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(),
|
||||
|
||||
));
|
||||
$cli->run();
|
10
vendor/doctrine/dbal/build.properties
vendored
Normal file
10
vendor/doctrine/dbal/build.properties
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# Project Name
|
||||
project.name=DoctrineDBAL
|
||||
|
||||
# Dependency minimum versions
|
||||
dependencies.common=2.0.1
|
||||
dependencies.sfconsole=2.0.0
|
||||
|
||||
# Version class and file
|
||||
project.version_class = Doctrine\DBAL\Version
|
||||
project.version_file = lib/Doctrine/DBAL/Version.php
|
91
vendor/doctrine/dbal/build.xml
vendored
Normal file
91
vendor/doctrine/dbal/build.xml
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0"?>
|
||||
<project name="DoctrineDBAL" default="build" basedir=".">
|
||||
<taskdef classname="phing.tasks.ext.d51PearPkg2Task" name="d51pearpkg2" />
|
||||
<import file="${project.basedir}/lib/vendor/doctrine-build-common/packaging.xml" />
|
||||
|
||||
<property file="build.properties" />
|
||||
|
||||
<!--
|
||||
Fileset for artifacts shared across all distributed packages.
|
||||
-->
|
||||
<fileset id="shared-artifacts" dir=".">
|
||||
<include name="LICENSE"/>
|
||||
</fileset>
|
||||
|
||||
<!--
|
||||
Fileset for command line scripts
|
||||
-->
|
||||
<fileset id="bin-scripts" dir="./bin">
|
||||
<include name="doctrine-dbal"/>
|
||||
<include name="doctrine-dbal.php"/>
|
||||
</fileset>
|
||||
|
||||
<!--
|
||||
Fileset for the sources of the Doctrine Common dependency.
|
||||
-->
|
||||
<fileset id="common-sources" dir="./lib/vendor/doctrine-common/lib">
|
||||
<include name="Doctrine/Common/**"/>
|
||||
</fileset>
|
||||
|
||||
<!--
|
||||
Fileset for the sources of the Doctrine DBAL package.
|
||||
-->
|
||||
<fileset id="dbal-sources" dir="./lib">
|
||||
<include name="Doctrine/DBAL/**"/>
|
||||
</fileset>
|
||||
|
||||
<!--
|
||||
Fileset for source of the Symfony YAML and Console components.
|
||||
-->
|
||||
<fileset id="external-sources" dir="./lib/vendor">
|
||||
<include name="Symfony/Component**"/>
|
||||
</fileset>
|
||||
|
||||
<target name="copy-files" depends="prepare">
|
||||
<echo msg="Checking for ${version} in ${project.version_file}" />
|
||||
<exec command="grep '${version}' ${project.basedir}/${project.version_file}" checkreturn="true"/>
|
||||
<copy todir="${build.dir}/${project.name}-${version}">
|
||||
<fileset refid="shared-artifacts"/>
|
||||
</copy>
|
||||
<copy todir="${build.dir}/${project.name}-${version}">
|
||||
<fileset refid="common-sources"/>
|
||||
<fileset refid="dbal-sources"/>
|
||||
</copy>
|
||||
<copy todir="${build.dir}/${project.name}-${version}/Doctrine">
|
||||
<fileset refid="external-sources"/>
|
||||
</copy>
|
||||
<copy todir="${build.dir}/${project.name}-${version}/bin">
|
||||
<fileset refid="bin-scripts"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="define-pear-package" depends="copy-files">
|
||||
<d51pearpkg2 baseinstalldir="/" dir="${build.dir}/${project.name}-${version}">
|
||||
<name>${project.name}</name>
|
||||
<summary>Doctrine Database Abstraction Layer</summary>
|
||||
<channel>pear.doctrine-project.org</channel>
|
||||
<description>The Doctrine DBAL package is the database abstraction layer used to power the ORM package.</description>
|
||||
<lead user="jwage" name="Jonathan H. Wage" email="jonwage@gmail.com" />
|
||||
<lead user="guilhermeblanco" name="Guilherme Blanco" email="guilhermeblanco@gmail.com" />
|
||||
<lead user="romanb" name="Roman Borschel" email="roman@code-factory.org" />
|
||||
<lead user="beberlei" name="Benjamin Eberlei" email="kontakt@beberlei.de" />
|
||||
<license>LGPL</license>
|
||||
<version release="${pear.version}" api="${pear.version}" />
|
||||
<stability release="${pear.stability}" api="${pear.stability}" />
|
||||
<notes>-</notes>
|
||||
<dependencies>
|
||||
<php minimum_version="5.3.2" />
|
||||
<pear minimum_version="1.6.0" recommended_version="1.6.1" />
|
||||
<package name="DoctrineCommon" channel="pear.doctrine-project.org" minimum_version="${dependencies.common}" />
|
||||
<package name="Console" channel="pear.symfony.com" minimum_version="${dependencies.sfconsole}" />
|
||||
</dependencies>
|
||||
<dirroles key="bin">script</dirroles>
|
||||
<ignore>Doctrine/Common/</ignore>
|
||||
<ignore>Doctrine/Symfony/</ignore>
|
||||
<release>
|
||||
<install as="doctrine-dbal" name="bin/doctrine-dbal" />
|
||||
<install as="doctrine-dbal.php" name="bin/doctrine-dbal.php" />
|
||||
</release>
|
||||
</d51pearpkg2>
|
||||
</target>
|
||||
</project>
|
3
vendor/doctrine/dbal/tests/.gitignore
vendored
Normal file
3
vendor/doctrine/dbal/tests/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
Doctrine/Tests/Proxies/
|
||||
Doctrine/Tests/ORM/Proxy/generated/
|
||||
Doctrine/Tests/ORM/Tools/Export/export
|
148
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/ConnectionTest.php
vendored
Normal file
148
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/ConnectionTest.php
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL;
|
||||
|
||||
require_once __DIR__ . '/../TestInit.php';
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\DBAL\Configuration;
|
||||
use Doctrine\DBAL\Events;
|
||||
|
||||
class ConnectionTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
/**
|
||||
* @var Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $_conn = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$params = array(
|
||||
'driver' => 'pdo_mysql',
|
||||
'host' => 'localhost',
|
||||
'user' => 'root',
|
||||
'password' => 'password',
|
||||
'port' => '1234'
|
||||
);
|
||||
$this->_conn = \Doctrine\DBAL\DriverManager::getConnection($params);
|
||||
}
|
||||
|
||||
public function testIsConnected()
|
||||
{
|
||||
$this->assertFalse($this->_conn->isConnected());
|
||||
}
|
||||
|
||||
public function testNoTransactionActiveByDefault()
|
||||
{
|
||||
$this->assertFalse($this->_conn->isTransactionActive());
|
||||
}
|
||||
|
||||
public function testCommitWithNoActiveTransaction_ThrowsException()
|
||||
{
|
||||
$this->setExpectedException('Doctrine\DBAL\ConnectionException');
|
||||
$this->_conn->commit();
|
||||
}
|
||||
|
||||
public function testRollbackWithNoActiveTransaction_ThrowsException()
|
||||
{
|
||||
$this->setExpectedException('Doctrine\DBAL\ConnectionException');
|
||||
$this->_conn->rollback();
|
||||
}
|
||||
|
||||
public function testSetRollbackOnlyNoActiveTransaction_ThrowsException()
|
||||
{
|
||||
$this->setExpectedException('Doctrine\DBAL\ConnectionException');
|
||||
$this->_conn->setRollbackOnly();
|
||||
}
|
||||
|
||||
public function testIsRollbackOnlyNoActiveTransaction_ThrowsException()
|
||||
{
|
||||
$this->setExpectedException('Doctrine\DBAL\ConnectionException');
|
||||
$this->_conn->isRollbackOnly();
|
||||
}
|
||||
|
||||
public function testGetConfiguration()
|
||||
{
|
||||
$config = $this->_conn->getConfiguration();
|
||||
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Configuration', $config);
|
||||
}
|
||||
|
||||
public function testGetHost()
|
||||
{
|
||||
$this->assertEquals('localhost', $this->_conn->getHost());
|
||||
}
|
||||
|
||||
public function testGetPort()
|
||||
{
|
||||
$this->assertEquals('1234', $this->_conn->getPort());
|
||||
}
|
||||
|
||||
public function testGetUsername()
|
||||
{
|
||||
$this->assertEquals('root', $this->_conn->getUsername());
|
||||
}
|
||||
|
||||
public function testGetPassword()
|
||||
{
|
||||
$this->assertEquals('password', $this->_conn->getPassword());
|
||||
}
|
||||
|
||||
public function testGetDriver()
|
||||
{
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Driver\PDOMySql\Driver', $this->_conn->getDriver());
|
||||
}
|
||||
|
||||
public function testGetEventManager()
|
||||
{
|
||||
$this->assertInstanceOf('Doctrine\Common\EventManager', $this->_conn->getEventManager());
|
||||
}
|
||||
|
||||
public function testConnectDispatchEvent()
|
||||
{
|
||||
$listenerMock = $this->getMock('ConnectDispatchEventListener', array('postConnect'));
|
||||
$listenerMock->expects($this->once())->method('postConnect');
|
||||
|
||||
$eventManager = new EventManager();
|
||||
$eventManager->addEventListener(array(Events::postConnect), $listenerMock);
|
||||
|
||||
$driverMock = $this->getMock('Doctrine\DBAL\Driver');
|
||||
$driverMock->expects(($this->at(0)))
|
||||
->method('connect');
|
||||
$platform = new Mocks\MockPlatform();
|
||||
|
||||
$conn = new Connection(array('platform' => $platform), $driverMock, new Configuration(), $eventManager);
|
||||
$conn->connect();
|
||||
}
|
||||
|
||||
public function testEventManagerPassedToPlatform()
|
||||
{
|
||||
$this->assertInstanceOf('Doctrine\Common\EventManager', $this->_conn->getDatabasePlatform()->getEventManager());
|
||||
$this->assertSame($this->_conn->getEventManager(), $this->_conn->getDatabasePlatform()->getEventManager());
|
||||
}
|
||||
|
||||
/**
|
||||
* Pretty dumb test, however we want to check that the EchoSQLLogger correctly implements the interface.
|
||||
*
|
||||
* @group DBAL-11
|
||||
*/
|
||||
public function testEchoSQLLogger()
|
||||
{
|
||||
$logger = new \Doctrine\DBAL\Logging\EchoSQLLogger();
|
||||
$this->_conn->getConfiguration()->setSQLLogger($logger);
|
||||
$this->assertSame($logger, $this->_conn->getConfiguration()->getSQLLogger());
|
||||
}
|
||||
|
||||
/**
|
||||
* Pretty dumb test, however we want to check that the DebugStack correctly implements the interface.
|
||||
*
|
||||
* @group DBAL-11
|
||||
*/
|
||||
public function testDebugSQLStack()
|
||||
{
|
||||
$logger = new \Doctrine\DBAL\Logging\DebugStack();
|
||||
$this->_conn->getConfiguration()->setSQLLogger($logger);
|
||||
$this->assertSame($logger, $this->_conn->getConfiguration()->getSQLLogger());
|
||||
}
|
||||
}
|
82
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php
vendored
Normal file
82
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class OCI8StatementTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!extension_loaded('oci8')) {
|
||||
$this->markTestSkipped('oci8 is not installed.');
|
||||
}
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* This scenario shows that when the first parameter is not null
|
||||
* it properly sets $hasZeroIndex to 1 and calls bindValue starting at 1.
|
||||
*
|
||||
* This also verifies that the statement will check with the connection to
|
||||
* see what the current execution mode is.
|
||||
*
|
||||
* The expected exception is due to oci_execute failing due to no valid connection.
|
||||
*
|
||||
* @dataProvider executeDataProvider
|
||||
* @expectedException \Doctrine\DBAL\Driver\OCI8\OCI8Exception
|
||||
*/
|
||||
public function testExecute(array $params)
|
||||
{
|
||||
$statement = $this->getMock('\Doctrine\DBAL\Driver\OCI8\OCI8Statement',
|
||||
array('bindValue', 'errorInfo'),
|
||||
array(), '', false);
|
||||
|
||||
$statement->expects($this->at(0))
|
||||
->method('bindValue')
|
||||
->with(
|
||||
$this->equalTo(1),
|
||||
$this->equalTo($params[0])
|
||||
);
|
||||
$statement->expects($this->at(1))
|
||||
->method('bindValue')
|
||||
->with(
|
||||
$this->equalTo(2),
|
||||
$this->equalTo($params[1])
|
||||
);
|
||||
$statement->expects($this->at(2))
|
||||
->method('bindValue')
|
||||
->with(
|
||||
$this->equalTo(3),
|
||||
$this->equalTo($params[2])
|
||||
);
|
||||
|
||||
// can't pass to constructor since we don't have a real database handle,
|
||||
// but execute must check the connection for the executeMode
|
||||
$conn = $this->getMock('\Doctrine\DBAL\Driver\OCI8\OCI8Connection', array('getExecuteMode'), array(), '', false);
|
||||
$conn->expects($this->once())
|
||||
->method('getExecuteMode');
|
||||
|
||||
$reflProperty = new \ReflectionProperty($statement, '_conn');
|
||||
$reflProperty->setAccessible(true);
|
||||
$reflProperty->setValue($statement, $conn);
|
||||
|
||||
$statement->execute($params);
|
||||
}
|
||||
|
||||
public static function executeDataProvider()
|
||||
{
|
||||
return array(
|
||||
// $hasZeroIndex = isset($params[0]); == true
|
||||
array(
|
||||
array(0 => 'test', 1 => null, 2 => 'value')
|
||||
),
|
||||
// $hasZeroIndex = isset($params[0]); == false
|
||||
array(
|
||||
array(0 => null, 1 => 'test', 2 => 'value')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
117
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/DriverManagerTest.php
vendored
Normal file
117
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/DriverManagerTest.php
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL;
|
||||
|
||||
require_once __DIR__ . '/../TestInit.php';
|
||||
|
||||
class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function testInvalidPdoInstance()
|
||||
{
|
||||
$options = array(
|
||||
'pdo' => 'test'
|
||||
);
|
||||
$test = \Doctrine\DBAL\DriverManager::getConnection($options);
|
||||
}
|
||||
|
||||
public function testValidPdoInstance()
|
||||
{
|
||||
$options = array(
|
||||
'pdo' => new \PDO('sqlite::memory:')
|
||||
);
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
||||
$this->assertEquals('sqlite', $conn->getDatabasePlatform()->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-32
|
||||
*/
|
||||
public function testPdoInstanceSetErrorMode()
|
||||
{
|
||||
$pdo = new \PDO('sqlite::memory:');
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT);
|
||||
$options = array(
|
||||
'pdo' => $pdo
|
||||
);
|
||||
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
||||
$this->assertEquals(\PDO::ERRMODE_EXCEPTION, $pdo->getAttribute(\PDO::ATTR_ERRMODE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function testCheckParams()
|
||||
{
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function testInvalidDriver()
|
||||
{
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection(array('driver' => 'invalid_driver'));
|
||||
}
|
||||
|
||||
public function testCustomPlatform()
|
||||
{
|
||||
$mockPlatform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$options = array(
|
||||
'pdo' => new \PDO('sqlite::memory:'),
|
||||
'platform' => $mockPlatform
|
||||
);
|
||||
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
||||
$this->assertSame($mockPlatform, $conn->getDatabasePlatform());
|
||||
}
|
||||
|
||||
public function testCustomWrapper()
|
||||
{
|
||||
$wrapperClass = 'Doctrine\Tests\Mocks\ConnectionMock';
|
||||
|
||||
$options = array(
|
||||
'pdo' => new \PDO('sqlite::memory:'),
|
||||
'wrapperClass' => $wrapperClass,
|
||||
);
|
||||
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
||||
$this->assertInstanceOf($wrapperClass, $conn);
|
||||
}
|
||||
|
||||
public function testInvalidWrapperClass()
|
||||
{
|
||||
$this->setExpectedException('\Doctrine\DBAL\DBALException');
|
||||
|
||||
$options = array(
|
||||
'pdo' => new \PDO('sqlite::memory:'),
|
||||
'wrapperClass' => 'stdClass',
|
||||
);
|
||||
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
||||
}
|
||||
|
||||
public function testInvalidDriverClass()
|
||||
{
|
||||
$this->setExpectedException('\Doctrine\DBAL\DBALException');
|
||||
|
||||
$options = array(
|
||||
'driverClass' => 'stdClass'
|
||||
);
|
||||
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
||||
}
|
||||
|
||||
public function testValidDriverClass()
|
||||
{
|
||||
$options = array(
|
||||
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
|
||||
);
|
||||
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Driver\PDOMySql\Driver', $conn->getDriver());
|
||||
}
|
||||
}
|
33
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php
vendored
Normal file
33
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Events;
|
||||
|
||||
use Doctrine\Tests\DbalTestCase;
|
||||
use Doctrine\DBAL\Event\Listeners\MysqlSessionInit;
|
||||
use Doctrine\DBAL\Event\ConnectionEventArgs;
|
||||
use Doctrine\DBAL\Events;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class MysqlSessionInitTest extends DbalTestCase
|
||||
{
|
||||
public function testPostConnect()
|
||||
{
|
||||
$connectionMock = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
|
||||
$connectionMock->expects($this->once())
|
||||
->method('executeUpdate')
|
||||
->with($this->equalTo("SET NAMES foo COLLATE bar"));
|
||||
|
||||
$eventArgs = new ConnectionEventArgs($connectionMock);
|
||||
|
||||
|
||||
$listener = new MysqlSessionInit('foo', 'bar');
|
||||
$listener->postConnect($eventArgs);
|
||||
}
|
||||
|
||||
public function testGetSubscribedEvents()
|
||||
{
|
||||
$listener = new MysqlSessionInit();
|
||||
$this->assertEquals(array(Events::postConnect), $listener->getSubscribedEvents());
|
||||
}
|
||||
}
|
33
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php
vendored
Normal file
33
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Events;
|
||||
|
||||
use Doctrine\Tests\DbalTestCase;
|
||||
use Doctrine\DBAL\Event\Listeners\OracleSessionInit;
|
||||
use Doctrine\DBAL\Event\ConnectionEventArgs;
|
||||
use Doctrine\DBAL\Events;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class OracleSessionInitTest extends DbalTestCase
|
||||
{
|
||||
public function testPostConnect()
|
||||
{
|
||||
$connectionMock = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
|
||||
$connectionMock->expects($this->once())
|
||||
->method('executeUpdate')
|
||||
->with($this->isType('string'));
|
||||
|
||||
$eventArgs = new ConnectionEventArgs($connectionMock);
|
||||
|
||||
|
||||
$listener = new OracleSessionInit();
|
||||
$listener->postConnect($eventArgs);
|
||||
}
|
||||
|
||||
public function testGetSubscribedEvents()
|
||||
{
|
||||
$listener = new OracleSessionInit();
|
||||
$this->assertEquals(array(Events::postConnect), $listener->getSubscribedEvents());
|
||||
}
|
||||
}
|
35
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php
vendored
Normal file
35
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Events;
|
||||
|
||||
use Doctrine\Tests\DbalTestCase;
|
||||
use Doctrine\DBAL\Event\Listeners\SQLSessionInit;
|
||||
use Doctrine\DBAL\Event\ConnectionEventArgs;
|
||||
use Doctrine\DBAL\Events;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DBAL-169
|
||||
*/
|
||||
class SQLSessionInitTest extends DbalTestCase
|
||||
{
|
||||
public function testPostConnect()
|
||||
{
|
||||
$connectionMock = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
|
||||
$connectionMock->expects($this->once())
|
||||
->method('exec')
|
||||
->with($this->equalTo("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'"));
|
||||
|
||||
$eventArgs = new ConnectionEventArgs($connectionMock);
|
||||
|
||||
$listener = new SQLSessionInit("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'");
|
||||
$listener->postConnect($eventArgs);
|
||||
}
|
||||
|
||||
public function testGetSubscribedEvents()
|
||||
{
|
||||
$listener = new SQLSessionInit("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'");
|
||||
$this->assertEquals(array(Events::postConnect), $listener->getSubscribedEvents());
|
||||
}
|
||||
}
|
83
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php
vendored
Normal file
83
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use PDO;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DBAL-6
|
||||
*/
|
||||
class BlobTest extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
try {
|
||||
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
|
||||
$table = new \Doctrine\DBAL\Schema\Table("blob_table");
|
||||
$table->addColumn('id', 'integer');
|
||||
$table->addColumn('clobfield', 'text');
|
||||
$table->addColumn('blobfield', 'blob');
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
$sm = $this->_conn->getSchemaManager();
|
||||
$sm->createTable($table);
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
$this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('blob_table'));
|
||||
}
|
||||
|
||||
public function testInsert()
|
||||
{
|
||||
$ret = $this->_conn->insert('blob_table',
|
||||
array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test'),
|
||||
array(\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_LOB)
|
||||
);
|
||||
$this->assertEquals(1, $ret);
|
||||
}
|
||||
|
||||
public function testSelect()
|
||||
{
|
||||
$ret = $this->_conn->insert('blob_table',
|
||||
array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test'),
|
||||
array(\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_LOB)
|
||||
);
|
||||
|
||||
$this->assertBlobContains('test');
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$ret = $this->_conn->insert('blob_table',
|
||||
array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test'),
|
||||
array(\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_LOB)
|
||||
);
|
||||
|
||||
$this->_conn->update('blob_table',
|
||||
array('blobfield' => 'test2'),
|
||||
array('id' => 1),
|
||||
array(\PDO::PARAM_LOB, \PDO::PARAM_INT)
|
||||
);
|
||||
|
||||
$this->assertBlobContains('test2');
|
||||
}
|
||||
|
||||
private function assertBlobContains($text)
|
||||
{
|
||||
$rows = $this->_conn->fetchAll('SELECT * FROM blob_table');
|
||||
|
||||
$this->assertEquals(1, count($rows));
|
||||
$row = array_change_key_case($rows[0], CASE_LOWER);
|
||||
|
||||
$blobValue = Type::getType('blob')->convertToPHPValue($row['blobfield'], $this->_conn->getDatabasePlatform());
|
||||
|
||||
$this->assertInternalType('resource', $blobValue);
|
||||
$this->assertEquals($text, stream_get_contents($blobValue));
|
||||
}
|
||||
}
|
219
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
vendored
Normal file
219
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
vendored
Normal file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional;
|
||||
|
||||
use Doctrine\DBAL\ConnectionException;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->resetSharedConn();
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
$this->resetSharedConn();
|
||||
}
|
||||
|
||||
public function testGetWrappedConnection()
|
||||
{
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Driver\Connection', $this->_conn->getWrappedConnection());
|
||||
}
|
||||
|
||||
public function testCommitWithRollbackOnlyThrowsException()
|
||||
{
|
||||
$this->_conn->beginTransaction();
|
||||
$this->_conn->setRollbackOnly();
|
||||
$this->setExpectedException('Doctrine\DBAL\ConnectionException');
|
||||
$this->_conn->commit();
|
||||
}
|
||||
|
||||
public function testTransactionNestingBehavior()
|
||||
{
|
||||
try {
|
||||
$this->_conn->beginTransaction();
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
|
||||
try {
|
||||
$this->_conn->beginTransaction();
|
||||
$this->assertEquals(2, $this->_conn->getTransactionNestingLevel());
|
||||
throw new \Exception;
|
||||
$this->_conn->commit(); // never reached
|
||||
} catch (\Exception $e) {
|
||||
$this->_conn->rollback();
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
//no rethrow
|
||||
}
|
||||
$this->assertTrue($this->_conn->isRollbackOnly());
|
||||
|
||||
$this->_conn->commit(); // should throw exception
|
||||
$this->fail('Transaction commit after failed nested transaction should fail.');
|
||||
} catch (ConnectionException $e) {
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
$this->_conn->rollback();
|
||||
$this->assertEquals(0, $this->_conn->getTransactionNestingLevel());
|
||||
}
|
||||
}
|
||||
|
||||
public function testTransactionNestingBehaviorWithSavepoints()
|
||||
{
|
||||
if (!$this->_conn->getDatabasePlatform()->supportsSavepoints()) {
|
||||
$this->markTestSkipped('This test requires the platform to support savepoints.');
|
||||
}
|
||||
|
||||
$this->_conn->setNestTransactionsWithSavepoints(true);
|
||||
try {
|
||||
$this->_conn->beginTransaction();
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
|
||||
try {
|
||||
$this->_conn->beginTransaction();
|
||||
$this->assertEquals(2, $this->_conn->getTransactionNestingLevel());
|
||||
$this->_conn->beginTransaction();
|
||||
$this->assertEquals(3, $this->_conn->getTransactionNestingLevel());
|
||||
$this->_conn->commit();
|
||||
$this->assertEquals(2, $this->_conn->getTransactionNestingLevel());
|
||||
throw new \Exception;
|
||||
$this->_conn->commit(); // never reached
|
||||
} catch (\Exception $e) {
|
||||
$this->_conn->rollback();
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
//no rethrow
|
||||
}
|
||||
$this->assertFalse($this->_conn->isRollbackOnly());
|
||||
try {
|
||||
$this->_conn->setNestTransactionsWithSavepoints(false);
|
||||
$this->fail('Should not be able to disable savepoints in usage for nested transactions inside an open transaction.');
|
||||
} catch (ConnectionException $e) {
|
||||
$this->assertTrue($this->_conn->getNestTransactionsWithSavepoints());
|
||||
}
|
||||
$this->_conn->commit(); // should not throw exception
|
||||
} catch (ConnectionException $e) {
|
||||
$this->fail('Transaction commit after failed nested transaction should not fail when using savepoints.');
|
||||
$this->_conn->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
public function testTransactionNestingBehaviorCantBeChangedInActiveTransaction()
|
||||
{
|
||||
if (!$this->_conn->getDatabasePlatform()->supportsSavepoints()) {
|
||||
$this->markTestSkipped('This test requires the platform to support savepoints.');
|
||||
}
|
||||
|
||||
$this->_conn->beginTransaction();
|
||||
try {
|
||||
$this->_conn->setNestTransactionsWithSavepoints(true);
|
||||
$this->fail('An exception should have been thrown by chaning the nesting transaction behavior within an transaction.');
|
||||
} catch(ConnectionException $e) {
|
||||
$this->_conn->rollBack();
|
||||
}
|
||||
}
|
||||
|
||||
public function testSetNestedTransactionsThroughSavepointsNotSupportedThrowsException()
|
||||
{
|
||||
if ($this->_conn->getDatabasePlatform()->supportsSavepoints()) {
|
||||
$this->markTestSkipped('This test requires the platform not to support savepoints.');
|
||||
}
|
||||
|
||||
$this->setExpectedException('Doctrine\DBAL\ConnectionException', "Savepoints are not supported by this driver.");
|
||||
|
||||
$this->_conn->setNestTransactionsWithSavepoints(true);
|
||||
}
|
||||
|
||||
public function testCreateSavepointsNotSupportedThrowsException()
|
||||
{
|
||||
if ($this->_conn->getDatabasePlatform()->supportsSavepoints()) {
|
||||
$this->markTestSkipped('This test requires the platform not to support savepoints.');
|
||||
}
|
||||
|
||||
$this->setExpectedException('Doctrine\DBAL\ConnectionException', "Savepoints are not supported by this driver.");
|
||||
|
||||
$this->_conn->createSavepoint('foo');
|
||||
}
|
||||
|
||||
public function testReleaseSavepointsNotSupportedThrowsException()
|
||||
{
|
||||
if ($this->_conn->getDatabasePlatform()->supportsSavepoints()) {
|
||||
$this->markTestSkipped('This test requires the platform not to support savepoints.');
|
||||
}
|
||||
|
||||
$this->setExpectedException('Doctrine\DBAL\ConnectionException', "Savepoints are not supported by this driver.");
|
||||
|
||||
$this->_conn->releaseSavepoint('foo');
|
||||
}
|
||||
|
||||
public function testRollbackSavepointsNotSupportedThrowsException()
|
||||
{
|
||||
if ($this->_conn->getDatabasePlatform()->supportsSavepoints()) {
|
||||
$this->markTestSkipped('This test requires the platform not to support savepoints.');
|
||||
}
|
||||
|
||||
$this->setExpectedException('Doctrine\DBAL\ConnectionException', "Savepoints are not supported by this driver.");
|
||||
|
||||
$this->_conn->rollbackSavepoint('foo');
|
||||
}
|
||||
|
||||
public function testTransactionBehaviorWithRollback()
|
||||
{
|
||||
try {
|
||||
$this->_conn->beginTransaction();
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
|
||||
throw new \Exception;
|
||||
|
||||
$this->_conn->commit(); // never reached
|
||||
} catch (\Exception $e) {
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
$this->_conn->rollback();
|
||||
$this->assertEquals(0, $this->_conn->getTransactionNestingLevel());
|
||||
}
|
||||
}
|
||||
|
||||
public function testTransactionBehaviour()
|
||||
{
|
||||
try {
|
||||
$this->_conn->beginTransaction();
|
||||
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
|
||||
$this->_conn->commit();
|
||||
} catch (\Exception $e) {
|
||||
$this->_conn->rollback();
|
||||
$this->assertEquals(0, $this->_conn->getTransactionNestingLevel());
|
||||
}
|
||||
|
||||
$this->assertEquals(0, $this->_conn->getTransactionNestingLevel());
|
||||
}
|
||||
|
||||
public function testTransactionalWithException()
|
||||
{
|
||||
try {
|
||||
$this->_conn->transactional(function($conn) {
|
||||
$conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL());
|
||||
throw new \RuntimeException("Ooops!");
|
||||
});
|
||||
} catch (\RuntimeException $expected) {
|
||||
$this->assertEquals(0, $this->_conn->getTransactionNestingLevel());
|
||||
}
|
||||
}
|
||||
|
||||
public function testTransactional()
|
||||
{
|
||||
$this->_conn->transactional(function($conn) {
|
||||
/* @var $conn Connection */
|
||||
$conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the quote function accepts DBAL and PDO types.
|
||||
*/
|
||||
public function testQuote()
|
||||
{
|
||||
$this->assertEquals($this->_conn->quote("foo", Type::STRING), $this->_conn->quote("foo", \PDO::PARAM_STR));
|
||||
}
|
||||
}
|
477
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
vendored
Normal file
477
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
vendored
Normal file
@@ -0,0 +1,477 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use PDO;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
static private $generated = false;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (self::$generated === false) {
|
||||
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
|
||||
$table = new \Doctrine\DBAL\Schema\Table("fetch_table");
|
||||
$table->addColumn('test_int', 'integer');
|
||||
$table->addColumn('test_string', 'string');
|
||||
$table->addColumn('test_datetime', 'datetime', array('notnull' => false));
|
||||
$table->setPrimaryKey(array('test_int'));
|
||||
|
||||
$sm = $this->_conn->getSchemaManager();
|
||||
$sm->createTable($table);
|
||||
|
||||
$this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo', 'test_datetime' => '2010-01-01 10:10:10'));
|
||||
self::$generated = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function testPrepareWithBindValue()
|
||||
{
|
||||
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
|
||||
|
||||
$stmt->bindValue(1, 1);
|
||||
$stmt->bindValue(2, 'foo');
|
||||
$stmt->execute();
|
||||
|
||||
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$row = array_change_key_case($row, \CASE_LOWER);
|
||||
$this->assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row);
|
||||
}
|
||||
|
||||
public function testPrepareWithBindParam()
|
||||
{
|
||||
$paramInt = 1;
|
||||
$paramStr = 'foo';
|
||||
|
||||
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
|
||||
|
||||
$stmt->bindParam(1, $paramInt);
|
||||
$stmt->bindParam(2, $paramStr);
|
||||
$stmt->execute();
|
||||
|
||||
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$row = array_change_key_case($row, \CASE_LOWER);
|
||||
$this->assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row);
|
||||
}
|
||||
|
||||
public function testPrepareWithFetchAll()
|
||||
{
|
||||
$paramInt = 1;
|
||||
$paramStr = 'foo';
|
||||
|
||||
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
|
||||
|
||||
$stmt->bindParam(1, $paramInt);
|
||||
$stmt->bindParam(2, $paramStr);
|
||||
$stmt->execute();
|
||||
|
||||
$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$rows[0] = array_change_key_case($rows[0], \CASE_LOWER);
|
||||
$this->assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $rows[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-228
|
||||
*/
|
||||
public function testPrepareWithFetchAllBoth()
|
||||
{
|
||||
$paramInt = 1;
|
||||
$paramStr = 'foo';
|
||||
|
||||
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
|
||||
|
||||
$stmt->bindParam(1, $paramInt);
|
||||
$stmt->bindParam(2, $paramStr);
|
||||
$stmt->execute();
|
||||
|
||||
$rows = $stmt->fetchAll(\PDO::FETCH_BOTH);
|
||||
$rows[0] = array_change_key_case($rows[0], \CASE_LOWER);
|
||||
$this->assertEquals(array('test_int' => 1, 'test_string' => 'foo', 0 => 1, 1 => 'foo'), $rows[0]);
|
||||
}
|
||||
|
||||
public function testPrepareWithFetchColumn()
|
||||
{
|
||||
$paramInt = 1;
|
||||
$paramStr = 'foo';
|
||||
|
||||
$sql = "SELECT test_int FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
|
||||
|
||||
$stmt->bindParam(1, $paramInt);
|
||||
$stmt->bindParam(2, $paramStr);
|
||||
$stmt->execute();
|
||||
|
||||
$column = $stmt->fetchColumn();
|
||||
$this->assertEquals(1, $column);
|
||||
}
|
||||
|
||||
public function testPrepareWithIterator()
|
||||
{
|
||||
$paramInt = 1;
|
||||
$paramStr = 'foo';
|
||||
|
||||
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
|
||||
|
||||
$stmt->bindParam(1, $paramInt);
|
||||
$stmt->bindParam(2, $paramStr);
|
||||
$stmt->execute();
|
||||
|
||||
$rows = array();
|
||||
$stmt->setFetchMode(\PDO::FETCH_ASSOC);
|
||||
foreach ($stmt as $row) {
|
||||
$rows[] = array_change_key_case($row, \CASE_LOWER);
|
||||
}
|
||||
|
||||
$this->assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $rows[0]);
|
||||
}
|
||||
|
||||
public function testPrepareWithQuoted()
|
||||
{
|
||||
$table = 'fetch_table';
|
||||
$paramInt = 1;
|
||||
$paramStr = 'foo';
|
||||
|
||||
$sql = "SELECT test_int, test_string FROM " . $this->_conn->quoteIdentifier($table) . " ".
|
||||
"WHERE test_int = " . $this->_conn->quote($paramInt) . " AND test_string = " . $this->_conn->quote($paramStr);
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
|
||||
}
|
||||
|
||||
public function testPrepareWithExecuteParams()
|
||||
{
|
||||
$paramInt = 1;
|
||||
$paramStr = 'foo';
|
||||
|
||||
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
|
||||
$stmt->execute(array($paramInt, $paramStr));
|
||||
|
||||
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$this->assertTrue($row !== false);
|
||||
$row = array_change_key_case($row, \CASE_LOWER);
|
||||
$this->assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row);
|
||||
}
|
||||
|
||||
public function testFetchAll()
|
||||
{
|
||||
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
||||
$data = $this->_conn->fetchAll($sql, array(1, 'foo'));
|
||||
|
||||
$this->assertEquals(1, count($data));
|
||||
|
||||
$row = $data[0];
|
||||
$this->assertEquals(2, count($row));
|
||||
|
||||
$row = array_change_key_case($row, \CASE_LOWER);
|
||||
$this->assertEquals(1, $row['test_int']);
|
||||
$this->assertEquals('foo', $row['test_string']);
|
||||
}
|
||||
|
||||
public function testFetchBoth()
|
||||
{
|
||||
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
||||
$row = $this->_conn->executeQuery($sql, array(1, 'foo'))->fetch();
|
||||
|
||||
$this->assertTrue($row !== false);
|
||||
|
||||
$row = array_change_key_case($row, \CASE_LOWER);
|
||||
|
||||
$this->assertEquals(1, $row['test_int']);
|
||||
$this->assertEquals('foo', $row['test_string']);
|
||||
$this->assertEquals(1, $row[0]);
|
||||
$this->assertEquals('foo', $row[1]);
|
||||
}
|
||||
|
||||
public function testFetchRow()
|
||||
{
|
||||
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
||||
$row = $this->_conn->fetchAssoc($sql, array(1, 'foo'));
|
||||
|
||||
$this->assertTrue($row !== false);
|
||||
|
||||
$row = array_change_key_case($row, \CASE_LOWER);
|
||||
|
||||
$this->assertEquals(1, $row['test_int']);
|
||||
$this->assertEquals('foo', $row['test_string']);
|
||||
}
|
||||
|
||||
public function testFetchArray()
|
||||
{
|
||||
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
||||
$row = $this->_conn->fetchArray($sql, array(1, 'foo'));
|
||||
|
||||
$this->assertEquals(1, $row[0]);
|
||||
$this->assertEquals('foo', $row[1]);
|
||||
}
|
||||
|
||||
public function testFetchColumn()
|
||||
{
|
||||
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
||||
$testInt = $this->_conn->fetchColumn($sql, array(1, 'foo'), 0);
|
||||
|
||||
$this->assertEquals(1, $testInt);
|
||||
|
||||
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
||||
$testString = $this->_conn->fetchColumn($sql, array(1, 'foo'), 1);
|
||||
|
||||
$this->assertEquals('foo', $testString);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-697
|
||||
*/
|
||||
public function testExecuteQueryBindDateTimeType()
|
||||
{
|
||||
$sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?';
|
||||
$stmt = $this->_conn->executeQuery($sql,
|
||||
array(1 => new \DateTime('2010-01-01 10:10:10')),
|
||||
array(1 => Type::DATETIME)
|
||||
);
|
||||
|
||||
$this->assertEquals(1, $stmt->fetchColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-697
|
||||
*/
|
||||
public function testExecuteUpdateBindDateTimeType()
|
||||
{
|
||||
$datetime = new \DateTime('2010-02-02 20:20:20');
|
||||
|
||||
$sql = 'INSERT INTO fetch_table (test_int, test_string, test_datetime) VALUES (?, ?, ?)';
|
||||
$affectedRows = $this->_conn->executeUpdate($sql,
|
||||
array(1 => 50, 2 => 'foo', 3 => $datetime),
|
||||
array(1 => PDO::PARAM_INT, 2 => PDO::PARAM_STR, 3 => Type::DATETIME)
|
||||
);
|
||||
|
||||
$this->assertEquals(1, $affectedRows);
|
||||
$this->assertEquals(1, $this->_conn->executeQuery(
|
||||
'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?',
|
||||
array(1 => $datetime),
|
||||
array(1 => Type::DATETIME)
|
||||
)->fetchColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-697
|
||||
*/
|
||||
public function testPrepareQueryBindValueDateTimeType()
|
||||
{
|
||||
$sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?';
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
$stmt->bindValue(1, new \DateTime('2010-01-01 10:10:10'), Type::DATETIME);
|
||||
$stmt->execute();
|
||||
|
||||
$this->assertEquals(1, $stmt->fetchColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-78
|
||||
*/
|
||||
public function testNativeArrayListSupport()
|
||||
{
|
||||
for ($i = 100; $i < 110; $i++) {
|
||||
$this->_conn->insert('fetch_table', array('test_int' => $i, 'test_string' => 'foo' . $i, 'test_datetime' => '2010-01-01 10:10:10'));
|
||||
}
|
||||
|
||||
$stmt = $this->_conn->executeQuery('SELECT test_int FROM fetch_table WHERE test_int IN (?)',
|
||||
array(array(100, 101, 102, 103, 104)), array(Connection::PARAM_INT_ARRAY));
|
||||
|
||||
$data = $stmt->fetchAll(PDO::FETCH_NUM);
|
||||
$this->assertEquals(5, count($data));
|
||||
$this->assertEquals(array(array(100), array(101), array(102), array(103), array(104)), $data);
|
||||
|
||||
$stmt = $this->_conn->executeQuery('SELECT test_int FROM fetch_table WHERE test_string IN (?)',
|
||||
array(array('foo100', 'foo101', 'foo102', 'foo103', 'foo104')), array(Connection::PARAM_STR_ARRAY));
|
||||
|
||||
$data = $stmt->fetchAll(PDO::FETCH_NUM);
|
||||
$this->assertEquals(5, count($data));
|
||||
$this->assertEquals(array(array(100), array(101), array(102), array(103), array(104)), $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1014
|
||||
*/
|
||||
public function testDateArithmetics()
|
||||
{
|
||||
$p = $this->_conn->getDatabasePlatform();
|
||||
$sql = 'SELECT ';
|
||||
$sql .= $p->getDateDiffExpression('test_datetime', $p->getCurrentTimestampSQL()) .' AS diff, ';
|
||||
$sql .= $p->getDateAddDaysExpression('test_datetime', 10) .' AS add_days, ';
|
||||
$sql .= $p->getDateSubDaysExpression('test_datetime', 10) .' AS sub_days, ';
|
||||
$sql .= $p->getDateAddMonthExpression('test_datetime', 2) .' AS add_month, ';
|
||||
$sql .= $p->getDateSubMonthExpression('test_datetime', 2) .' AS sub_month ';
|
||||
$sql .= 'FROM fetch_table';
|
||||
|
||||
$row = $this->_conn->fetchAssoc($sql);
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
|
||||
$diff = floor( (strtotime('2010-01-01')-time()) / 3600 / 24);
|
||||
$this->assertEquals($diff, (int)$row['diff'], "Date difference should be approx. ".$diff." days.", 1);
|
||||
$this->assertEquals('2010-01-11', date('Y-m-d', strtotime($row['add_days'])), "Adding date should end up on 2010-01-11");
|
||||
$this->assertEquals('2009-12-22', date('Y-m-d', strtotime($row['sub_days'])), "Subtracting date should end up on 2009-12-22");
|
||||
$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'])), "Adding month should end up on 2009-11-01");
|
||||
}
|
||||
|
||||
public function testQuoteSQLInjection()
|
||||
{
|
||||
$sql = "SELECT * FROM fetch_table WHERE test_string = " . $this->_conn->quote("bar' OR '1'='1");
|
||||
$rows = $this->_conn->fetchAll($sql);
|
||||
|
||||
$this->assertEquals(0, count($rows), "no result should be returned, otherwise SQL injection is possible");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1213
|
||||
*/
|
||||
public function testBitComparisonExpressionSupport()
|
||||
{
|
||||
$this->_conn->executeQuery('DELETE FROM fetch_table')->execute();
|
||||
$platform = $this->_conn->getDatabasePlatform();
|
||||
$bitmap = array();
|
||||
|
||||
for ($i = 2; $i < 9; $i = $i + 2) {
|
||||
$bitmap[$i] = array(
|
||||
'bit_or' => ($i | 2),
|
||||
'bit_and' => ($i & 2)
|
||||
);
|
||||
$this->_conn->insert('fetch_table', array(
|
||||
'test_int' => $i,
|
||||
'test_string' => json_encode($bitmap[$i]),
|
||||
'test_datetime' => '2010-01-01 10:10:10'
|
||||
));
|
||||
}
|
||||
|
||||
$sql[] = 'SELECT ';
|
||||
$sql[] = 'test_int, ';
|
||||
$sql[] = 'test_string, ';
|
||||
$sql[] = $platform->getBitOrComparisonExpression('test_int', 2) . ' AS bit_or, ';
|
||||
$sql[] = $platform->getBitAndComparisonExpression('test_int', 2) . ' AS bit_and ';
|
||||
$sql[] = 'FROM fetch_table';
|
||||
|
||||
$stmt = $this->_conn->executeQuery(implode(PHP_EOL, $sql));
|
||||
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
|
||||
$this->assertEquals(4, count($data));
|
||||
$this->assertEquals(count($bitmap), count($data));
|
||||
foreach ($data as $row) {
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
|
||||
$this->assertArrayHasKey('test_int', $row);
|
||||
|
||||
$id = $row['test_int'];
|
||||
|
||||
$this->assertArrayHasKey($id, $bitmap);
|
||||
$this->assertArrayHasKey($id, $bitmap);
|
||||
|
||||
$this->assertArrayHasKey('bit_or', $row);
|
||||
$this->assertArrayHasKey('bit_and', $row);
|
||||
|
||||
$this->assertEquals($row['bit_or'], $bitmap[$id]['bit_or']);
|
||||
$this->assertEquals($row['bit_and'], $bitmap[$id]['bit_and']);
|
||||
}
|
||||
}
|
||||
|
||||
public function testSetDefaultFetchMode()
|
||||
{
|
||||
$stmt = $this->_conn->query("SELECT * FROM fetch_table");
|
||||
$stmt->setFetchMode(\PDO::FETCH_NUM);
|
||||
|
||||
$row = array_keys($stmt->fetch());
|
||||
$this->assertEquals(0, count( array_filter($row, function($v) { return ! is_numeric($v); })), "should be no non-numerical elements in the result.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-196
|
||||
*/
|
||||
public function testFetchAllSupportFetchClass()
|
||||
{
|
||||
$this->skipOci8AndMysqli();
|
||||
|
||||
$this->_conn->executeQuery('DELETE FROM fetch_table')->execute();
|
||||
$this->_conn->insert('fetch_table', array(
|
||||
'test_int' => 1,
|
||||
'test_string' => 'foo',
|
||||
'test_datetime' => '2010-01-01 10:10:10'
|
||||
));
|
||||
|
||||
$sql = "SELECT test_int, test_string, test_datetime FROM fetch_table";
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
$results = $stmt->fetchAll(
|
||||
\PDO::FETCH_CLASS,
|
||||
__NAMESPACE__.'\\MyFetchClass'
|
||||
);
|
||||
|
||||
$this->assertEquals(1, count($results));
|
||||
$this->assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]);
|
||||
|
||||
$this->assertEquals(1, $results[0]->test_int);
|
||||
$this->assertEquals('foo', $results[0]->test_string);
|
||||
$this->assertStringStartsWith('2010-01-01 10:10:10', $results[0]->test_datetime);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-241
|
||||
*/
|
||||
public function testFetchAllStyleColumn()
|
||||
{
|
||||
$sql = "DELETE FROM fetch_table";
|
||||
$this->_conn->executeUpdate($sql);
|
||||
|
||||
$this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo'));
|
||||
$this->_conn->insert('fetch_table', array('test_int' => 10, 'test_string' => 'foo'));
|
||||
|
||||
$sql = "SELECT test_int FROM fetch_table";
|
||||
$rows = $this->_conn->query($sql)->fetchAll(\PDO::FETCH_COLUMN);
|
||||
|
||||
$this->assertEquals(array(1, 10), $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-257
|
||||
*/
|
||||
public function testEmptyFetchColumnReturnsFalse()
|
||||
{
|
||||
$this->_conn->executeQuery('DELETE FROM fetch_table')->execute();
|
||||
$this->assertFalse($this->_conn->fetchColumn('SELECT test_int FROM fetch_table'));
|
||||
$this->assertFalse($this->_conn->query('SELECT test_int FROM fetch_table')->fetchColumn());
|
||||
}
|
||||
|
||||
private function skipOci8AndMysqli()
|
||||
{
|
||||
if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] == "oci8") {
|
||||
$this->markTestSkipped("Not supported by OCI8");
|
||||
}
|
||||
if ('mysqli' == $this->_conn->getDriver()->getName()) {
|
||||
$this->markTestSkipped('Mysqli driver dont support this feature.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MyFetchClass
|
||||
{
|
||||
public $test_int, $test_string, $test_datetime;
|
||||
}
|
52
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php
vendored
Normal file
52
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional;
|
||||
|
||||
class LoggingTest extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
public function testLogExecuteQuery()
|
||||
{
|
||||
$sql = $this->_conn->getDatabasePlatform()->getDummySelectSQL();
|
||||
|
||||
$logMock = $this->getMock('Doctrine\DBAL\Logging\SQLLogger');
|
||||
$logMock->expects($this->at(0))
|
||||
->method('startQuery')
|
||||
->with($this->equalTo($sql), $this->equalTo(array()), $this->equalTo(array()));
|
||||
$logMock->expects($this->at(1))
|
||||
->method('stopQuery');
|
||||
$this->_conn->getConfiguration()->setSQLLogger($logMock);
|
||||
$this->_conn->executeQuery($sql, array());
|
||||
}
|
||||
|
||||
public function testLogExecuteUpdate()
|
||||
{
|
||||
$this->markTestSkipped('Test breaks MySQL but works on all other platforms (Unbuffered Queries stuff).');
|
||||
|
||||
$sql = $this->_conn->getDatabasePlatform()->getDummySelectSQL();
|
||||
|
||||
$logMock = $this->getMock('Doctrine\DBAL\Logging\SQLLogger');
|
||||
$logMock->expects($this->at(0))
|
||||
->method('startQuery')
|
||||
->with($this->equalTo($sql), $this->equalTo(array()), $this->equalTo(array()));
|
||||
$logMock->expects($this->at(1))
|
||||
->method('stopQuery');
|
||||
$this->_conn->getConfiguration()->setSQLLogger($logMock);
|
||||
$this->_conn->executeUpdate($sql, array());
|
||||
}
|
||||
|
||||
public function testLogPrepareExecute()
|
||||
{
|
||||
$sql = $this->_conn->getDatabasePlatform()->getDummySelectSQL();
|
||||
|
||||
$logMock = $this->getMock('Doctrine\DBAL\Logging\SQLLogger');
|
||||
$logMock->expects($this->once())
|
||||
->method('startQuery')
|
||||
->with($this->equalTo($sql), $this->equalTo(array()));
|
||||
$logMock->expects($this->at(1))
|
||||
->method('stopQuery');
|
||||
$this->_conn->getConfiguration()->setSQLLogger($logMock);
|
||||
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
}
|
||||
}
|
82
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
vendored
Normal file
82
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional;
|
||||
|
||||
use Doctrine\Tests\DbalFunctionalTestCase;
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
|
||||
/**
|
||||
* @group DBAL-20
|
||||
*/
|
||||
class MasterSlaveConnectionTest extends DbalFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if ($this->_conn->getDatabasePlatform()->getName() == "sqlite") {
|
||||
$this->markTestSkipped('Test does not work on sqlite.');
|
||||
}
|
||||
|
||||
try {
|
||||
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
|
||||
$table = new \Doctrine\DBAL\Schema\Table("master_slave_table");
|
||||
$table->addColumn('test_int', 'integer');
|
||||
$table->setPrimaryKey(array('test_int'));
|
||||
|
||||
$sm = $this->_conn->getSchemaManager();
|
||||
$sm->createTable($table);
|
||||
|
||||
$this->_conn->insert('master_slave_table', array('test_int' => 1));
|
||||
} catch(\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
public function createMasterSlaveConnection()
|
||||
{
|
||||
$params = $this->_conn->getParams();
|
||||
$params['master'] = $params;
|
||||
$params['slaves'] = array($params, $params);
|
||||
$params['wrapperClass'] = 'Doctrine\DBAL\Connections\MasterSlaveConnection';
|
||||
|
||||
return DriverManager::getConnection($params);
|
||||
}
|
||||
|
||||
public function testMasterOnConnect()
|
||||
{
|
||||
$conn = $this->createMasterSlaveConnection();
|
||||
|
||||
$this->assertFalse($conn->isConnectedToMaster());
|
||||
$conn->connect('slave');
|
||||
$this->assertFalse($conn->isConnectedToMaster());
|
||||
$conn->connect('master');
|
||||
$this->assertTrue($conn->isConnectedToMaster());
|
||||
}
|
||||
|
||||
public function testNoMasterOnExecuteQuery()
|
||||
{
|
||||
$conn = $this->createMasterSlaveConnection();
|
||||
|
||||
$sql = "SELECT count(*) as num FROM master_slave_table";
|
||||
$data = $conn->fetchAll($sql);
|
||||
$data[0] = array_change_key_case($data[0], CASE_LOWER);
|
||||
|
||||
$this->assertEquals(1, $data[0]['num']);
|
||||
$this->assertFalse($conn->isConnectedToMaster());
|
||||
}
|
||||
|
||||
public function testMasterOnWriteOperation()
|
||||
{
|
||||
$conn = $this->createMasterSlaveConnection();
|
||||
$conn->insert('master_slave_table', array('test_int' => 30));
|
||||
|
||||
$this->assertTrue($conn->isConnectedToMaster());
|
||||
|
||||
$sql = "SELECT count(*) as num FROM master_slave_table";
|
||||
$data = $conn->fetchAll($sql);
|
||||
$data[0] = array_change_key_case($data[0], CASE_LOWER);
|
||||
|
||||
$this->assertEquals(2, $data[0]['num']);
|
||||
$this->assertTrue($conn->isConnectedToMaster());
|
||||
}
|
||||
}
|
114
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php
vendored
Normal file
114
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use PDO;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
private static $tableCreated = false;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!self::$tableCreated) {
|
||||
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
|
||||
$table = new \Doctrine\DBAL\Schema\Table("modify_limit_table");
|
||||
$table->addColumn('test_int', 'integer');
|
||||
$table->setPrimaryKey(array('test_int'));
|
||||
|
||||
$table2 = new \Doctrine\DBAL\Schema\Table("modify_limit_table2");
|
||||
$table2->addColumn('id', 'integer', array('autoincrement' => true));
|
||||
$table2->addColumn('test_int', 'integer');
|
||||
$table2->setPrimaryKey(array('id'));
|
||||
|
||||
$sm = $this->_conn->getSchemaManager();
|
||||
$sm->createTable($table);
|
||||
$sm->createTable($table2);
|
||||
self::$tableCreated = true;
|
||||
}
|
||||
$this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('modify_limit_table'));
|
||||
$this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('modify_limit_table2'));
|
||||
}
|
||||
|
||||
public function testModifyLimitQuerySimpleQuery()
|
||||
{
|
||||
$this->_conn->insert('modify_limit_table', array('test_int' => 1));
|
||||
$this->_conn->insert('modify_limit_table', array('test_int' => 2));
|
||||
$this->_conn->insert('modify_limit_table', array('test_int' => 3));
|
||||
$this->_conn->insert('modify_limit_table', array('test_int' => 4));
|
||||
|
||||
$sql = "SELECT * FROM modify_limit_table";
|
||||
|
||||
$this->assertLimitResult(array(1, 2, 3, 4), $sql, 10, 0);
|
||||
$this->assertLimitResult(array(1, 2), $sql, 2, 0);
|
||||
$this->assertLimitResult(array(3, 4), $sql, 2, 2);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryJoinQuery()
|
||||
{
|
||||
$this->_conn->insert('modify_limit_table', array('test_int' => 1));
|
||||
$this->_conn->insert('modify_limit_table', array('test_int' => 2));
|
||||
|
||||
$this->_conn->insert('modify_limit_table2', array('test_int' => 1));
|
||||
$this->_conn->insert('modify_limit_table2', array('test_int' => 1));
|
||||
$this->_conn->insert('modify_limit_table2', array('test_int' => 1));
|
||||
$this->_conn->insert('modify_limit_table2', array('test_int' => 2));
|
||||
$this->_conn->insert('modify_limit_table2', array('test_int' => 2));
|
||||
|
||||
$sql = "SELECT modify_limit_table.test_int FROM modify_limit_table INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int";
|
||||
|
||||
$this->assertLimitResult(array(1, 1, 1, 2, 2), $sql, 10, 0);
|
||||
$this->assertLimitResult(array(1, 1, 1), $sql, 3, 0);
|
||||
$this->assertLimitResult(array(2, 2), $sql, 2, 3);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryOrderBy()
|
||||
{
|
||||
$this->_conn->insert('modify_limit_table', array('test_int' => 1));
|
||||
$this->_conn->insert('modify_limit_table', array('test_int' => 2));
|
||||
$this->_conn->insert('modify_limit_table', array('test_int' => 3));
|
||||
$this->_conn->insert('modify_limit_table', array('test_int' => 4));
|
||||
|
||||
$sql = "SELECT * FROM modify_limit_table ORDER BY test_int DESC";
|
||||
|
||||
$this->assertLimitResult(array(4, 3, 2, 1), $sql, 10, 0);
|
||||
$this->assertLimitResult(array(4, 3), $sql, 2, 0);
|
||||
$this->assertLimitResult(array(2, 1), $sql, 2, 2);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryGroupBy()
|
||||
{
|
||||
$this->_conn->insert('modify_limit_table', array('test_int' => 1));
|
||||
$this->_conn->insert('modify_limit_table', array('test_int' => 2));
|
||||
|
||||
$this->_conn->insert('modify_limit_table2', array('test_int' => 1));
|
||||
$this->_conn->insert('modify_limit_table2', array('test_int' => 1));
|
||||
$this->_conn->insert('modify_limit_table2', array('test_int' => 1));
|
||||
$this->_conn->insert('modify_limit_table2', array('test_int' => 2));
|
||||
$this->_conn->insert('modify_limit_table2', array('test_int' => 2));
|
||||
|
||||
$sql = "SELECT modify_limit_table.test_int FROM modify_limit_table " .
|
||||
"INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int ".
|
||||
"GROUP BY modify_limit_table.test_int";
|
||||
$this->assertLimitResult(array(1, 2), $sql, 10, 0);
|
||||
$this->assertLimitResult(array(1), $sql, 1, 0);
|
||||
$this->assertLimitResult(array(2), $sql, 1, 1);
|
||||
}
|
||||
|
||||
public function assertLimitResult($expectedResults, $sql, $limit, $offset)
|
||||
{
|
||||
$p = $this->_conn->getDatabasePlatform();
|
||||
$data = array();
|
||||
foreach ($this->_conn->fetchAll($p->modifyLimitQuery($sql, $limit, $offset)) AS $row) {
|
||||
$row = array_change_key_case($row, CASE_LOWER);
|
||||
$data[] = $row['test_int'];
|
||||
}
|
||||
$this->assertEquals($expectedResults, $data);
|
||||
}
|
||||
}
|
166
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php
vendored
Normal file
166
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional\Ticket;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use\PDO;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
|
||||
/**
|
||||
* @group DDC-1372
|
||||
*/
|
||||
class NamedParametersTest extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
|
||||
public function ticketProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'SELECT * FROM ddc1372_foobar f WHERE f.foo = :foo AND f.bar IN (:bar)',
|
||||
array('foo'=>1,'bar'=> array(1, 2, 3)),
|
||||
array('foo'=>PDO::PARAM_INT,'bar'=> Connection::PARAM_INT_ARRAY,),
|
||||
array(
|
||||
array('id'=>1,'foo'=>1,'bar'=>1),
|
||||
array('id'=>2,'foo'=>1,'bar'=>2),
|
||||
array('id'=>3,'foo'=>1,'bar'=>3),
|
||||
)
|
||||
),
|
||||
|
||||
array(
|
||||
'SELECT * FROM ddc1372_foobar f WHERE f.foo = :foo AND f.bar IN (:bar)',
|
||||
array('foo'=>1,'bar'=> array(1, 2, 3)),
|
||||
array('bar'=> Connection::PARAM_INT_ARRAY,'foo'=>PDO::PARAM_INT),
|
||||
array(
|
||||
array('id'=>1,'foo'=>1,'bar'=>1),
|
||||
array('id'=>2,'foo'=>1,'bar'=>2),
|
||||
array('id'=>3,'foo'=>1,'bar'=>3),
|
||||
)
|
||||
),
|
||||
|
||||
array(
|
||||
'SELECT * FROM ddc1372_foobar f WHERE f.bar IN (:bar) AND f.foo = :foo',
|
||||
array('foo'=>1,'bar'=> array(1, 2, 3)),
|
||||
array('bar'=> Connection::PARAM_INT_ARRAY,'foo'=>PDO::PARAM_INT),
|
||||
array(
|
||||
array('id'=>1,'foo'=>1,'bar'=>1),
|
||||
array('id'=>2,'foo'=>1,'bar'=>2),
|
||||
array('id'=>3,'foo'=>1,'bar'=>3),
|
||||
)
|
||||
),
|
||||
|
||||
array(
|
||||
'SELECT * FROM ddc1372_foobar f WHERE f.bar IN (:bar) AND f.foo = :foo',
|
||||
array('foo'=>1,'bar'=> array('1', '2', '3')),
|
||||
array('bar'=> Connection::PARAM_STR_ARRAY,'foo'=>PDO::PARAM_INT),
|
||||
array(
|
||||
array('id'=>1,'foo'=>1,'bar'=>1),
|
||||
array('id'=>2,'foo'=>1,'bar'=>2),
|
||||
array('id'=>3,'foo'=>1,'bar'=>3),
|
||||
)
|
||||
),
|
||||
|
||||
array(
|
||||
'SELECT * FROM ddc1372_foobar f WHERE f.bar IN (:bar) AND f.foo IN (:foo)',
|
||||
array('foo'=>array('1'),'bar'=> array(1, 2, 3,4)),
|
||||
array('bar'=> Connection::PARAM_STR_ARRAY,'foo'=>Connection::PARAM_INT_ARRAY),
|
||||
array(
|
||||
array('id'=>1,'foo'=>1,'bar'=>1),
|
||||
array('id'=>2,'foo'=>1,'bar'=>2),
|
||||
array('id'=>3,'foo'=>1,'bar'=>3),
|
||||
array('id'=>4,'foo'=>1,'bar'=>4),
|
||||
)
|
||||
),
|
||||
|
||||
array(
|
||||
'SELECT * FROM ddc1372_foobar f WHERE f.bar IN (:bar) AND f.foo IN (:foo)',
|
||||
array('foo'=>1,'bar'=> 2),
|
||||
array('bar'=>PDO::PARAM_INT,'foo'=>PDO::PARAM_INT),
|
||||
array(
|
||||
array('id'=>2,'foo'=>1,'bar'=>2),
|
||||
)
|
||||
),
|
||||
|
||||
array(
|
||||
'SELECT * FROM ddc1372_foobar f WHERE f.bar = :arg AND f.foo <> :arg',
|
||||
array('arg'=>'1'),
|
||||
array('arg'=>PDO::PARAM_STR),
|
||||
array(
|
||||
array('id'=>5,'foo'=>2,'bar'=>1),
|
||||
)
|
||||
),
|
||||
|
||||
array(
|
||||
'SELECT * FROM ddc1372_foobar f WHERE f.bar NOT IN (:arg) AND f.foo IN (:arg)',
|
||||
array('arg'=>array(1, 2)),
|
||||
array('arg'=>Connection::PARAM_INT_ARRAY),
|
||||
array(
|
||||
array('id'=>3,'foo'=>1,'bar'=>3),
|
||||
array('id'=>4,'foo'=>1,'bar'=>4),
|
||||
)
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!$this->_conn->getSchemaManager()->tablesExist("ddc1372_foobar")) {
|
||||
try {
|
||||
$table = new \Doctrine\DBAL\Schema\Table("ddc1372_foobar");
|
||||
$table->addColumn('id', 'integer');
|
||||
$table->addColumn('foo','string');
|
||||
$table->addColumn('bar','string');
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
|
||||
$sm = $this->_conn->getSchemaManager();
|
||||
$sm->createTable($table);
|
||||
|
||||
$this->_conn->insert('ddc1372_foobar', array(
|
||||
'id' => 1, 'foo' => 1, 'bar' => 1
|
||||
));
|
||||
$this->_conn->insert('ddc1372_foobar', array(
|
||||
'id' => 2, 'foo' => 1, 'bar' => 2
|
||||
));
|
||||
$this->_conn->insert('ddc1372_foobar', array(
|
||||
'id' => 3, 'foo' => 1, 'bar' => 3
|
||||
));
|
||||
$this->_conn->insert('ddc1372_foobar', array(
|
||||
'id' => 4, 'foo' => 1, 'bar' => 4
|
||||
));
|
||||
$this->_conn->insert('ddc1372_foobar', array(
|
||||
'id' => 5, 'foo' => 2, 'bar' => 1
|
||||
));
|
||||
$this->_conn->insert('ddc1372_foobar', array(
|
||||
'id' => 6, 'foo' => 2, 'bar' => 2
|
||||
));
|
||||
} catch(\Exception $e) {
|
||||
$this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider ticketProvider
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @param array $expected
|
||||
*/
|
||||
public function testTicket($query,$params,$types,$expected)
|
||||
{
|
||||
$stmt = $this->_conn->executeQuery($query, $params, $types);
|
||||
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($result as $k => $v) {
|
||||
$result[$k] = array_change_key_case($v, CASE_LOWER);
|
||||
}
|
||||
|
||||
$this->assertEquals($result, $expected);
|
||||
}
|
||||
|
||||
}
|
97
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php
vendored
Normal file
97
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
use PDO;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DBAL-56
|
||||
*/
|
||||
class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
static private $hasTable = false;
|
||||
|
||||
private $portableConnection;
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if ($this->portableConnection) {
|
||||
$this->portableConnection->close();
|
||||
}
|
||||
}
|
||||
|
||||
private function getPortableConnection($portabilityMode = \Doctrine\DBAL\Portability\Connection::PORTABILITY_ALL, $case = \PDO::CASE_LOWER)
|
||||
{
|
||||
if (!$this->portableConnection) {
|
||||
$params = $this->_conn->getParams();
|
||||
$params['wrapperClass'] = 'Doctrine\DBAL\Portability\Connection';
|
||||
$params['portability'] = $portabilityMode;
|
||||
$params['fetch_case'] = $case;
|
||||
$this->portableConnection = DriverManager::getConnection($params, $this->_conn->getConfiguration(), $this->_conn->getEventManager());
|
||||
|
||||
try {
|
||||
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
|
||||
$table = new \Doctrine\DBAL\Schema\Table("portability_table");
|
||||
$table->addColumn('Test_Int', 'integer');
|
||||
$table->addColumn('Test_String', 'string', array('fixed' => true, 'length' => 32));
|
||||
$table->addColumn('Test_Null', 'string', array('notnull' => false));
|
||||
$table->setPrimaryKey(array('Test_Int'));
|
||||
|
||||
$sm = $this->portableConnection->getSchemaManager();
|
||||
$sm->createTable($table);
|
||||
|
||||
$this->portableConnection->insert('portability_table', array('Test_Int' => 1, 'Test_String' => 'foo', 'Test_Null' => ''));
|
||||
$this->portableConnection->insert('portability_table', array('Test_Int' => 2, 'Test_String' => 'foo ', 'Test_Null' => null));
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $this->portableConnection;
|
||||
}
|
||||
|
||||
public function testFullFetchMode()
|
||||
{
|
||||
$rows = $this->getPortableConnection()->fetchAll('SELECT * FROM portability_table');
|
||||
$this->assertFetchResultRows($rows);
|
||||
|
||||
$stmt = $this->getPortableConnection()->query('SELECT * FROM portability_table');
|
||||
$stmt->setFetchMode(\PDO::FETCH_ASSOC);
|
||||
foreach ($stmt as $row) {
|
||||
$this->assertFetchResultRow($row);
|
||||
}
|
||||
|
||||
$stmt = $this->getPortableConnection()->query('SELECT * FROM portability_table');
|
||||
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$this->assertFetchResultRow($row);
|
||||
}
|
||||
|
||||
$stmt = $this->getPortableConnection()->prepare('SELECT * FROM portability_table');
|
||||
$stmt->execute();
|
||||
|
||||
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$this->assertFetchResultRow($row);
|
||||
}
|
||||
}
|
||||
|
||||
public function assertFetchResultRows($rows)
|
||||
{
|
||||
$this->assertEquals(2, count($rows));
|
||||
foreach ($rows AS $row) {
|
||||
$this->assertFetchResultRow($row);
|
||||
}
|
||||
}
|
||||
|
||||
public function assertFetchResultRow($row)
|
||||
{
|
||||
$this->assertTrue(in_array($row['test_int'], array(1, 2)), "Primary key test_int should either be 1 or 2.");
|
||||
$this->assertArrayHasKey('test_string', $row, "Case should be lowered.");
|
||||
$this->assertEquals(3, strlen($row['test_string']), "test_string should be rtrimed to length of three for CHAR(32) column.");
|
||||
$this->assertNull($row['test_null']);
|
||||
}
|
||||
}
|
199
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php
vendored
Normal file
199
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php
vendored
Normal file
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Cache\QueryCacheProfile;
|
||||
use PDO;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DDC-217
|
||||
*/
|
||||
class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
private $expectedResult = array(array('test_int' => 100, 'test_string' => 'foo'), array('test_int' => 200, 'test_string' => 'bar'), array('test_int' => 300, 'test_string' => 'baz'));
|
||||
private $sqlLogger;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
try {
|
||||
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
|
||||
$table = new \Doctrine\DBAL\Schema\Table("caching");
|
||||
$table->addColumn('test_int', 'integer');
|
||||
$table->addColumn('test_string', 'string', array('notnull' => false));
|
||||
$table->setPrimaryKey(array('test_int'));
|
||||
|
||||
$sm = $this->_conn->getSchemaManager();
|
||||
$sm->createTable($table);
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
$this->_conn->executeUpdate('DELETE FROM caching');
|
||||
foreach ($this->expectedResult AS $row) {
|
||||
$this->_conn->insert('caching', $row);
|
||||
}
|
||||
|
||||
$config = $this->_conn->getConfiguration();
|
||||
$config->setSQLLogger($this->sqlLogger = new \Doctrine\DBAL\Logging\DebugStack);
|
||||
|
||||
$cache = new \Doctrine\Common\Cache\ArrayCache;
|
||||
$config->setResultCacheImpl($cache);
|
||||
}
|
||||
|
||||
public function testCacheFetchAssoc()
|
||||
{
|
||||
$this->assertCacheNonCacheSelectSameFetchModeAreEqual($this->expectedResult, \PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
public function testFetchNum()
|
||||
{
|
||||
$expectedResult = array();
|
||||
foreach ($this->expectedResult AS $v) {
|
||||
$expectedResult[] = array_values($v);
|
||||
}
|
||||
$this->assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, \PDO::FETCH_NUM);
|
||||
}
|
||||
|
||||
public function testFetchBoth()
|
||||
{
|
||||
$expectedResult = array();
|
||||
foreach ($this->expectedResult AS $v) {
|
||||
$expectedResult[] = array_merge($v, array_values($v));
|
||||
}
|
||||
$this->assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, \PDO::FETCH_BOTH);
|
||||
}
|
||||
|
||||
public function testMixingFetch()
|
||||
{
|
||||
$numExpectedResult = array();
|
||||
foreach ($this->expectedResult AS $v) {
|
||||
$numExpectedResult[] = array_values($v);
|
||||
}
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
|
||||
|
||||
$data = $this->hydrateStmt($stmt, \PDO::FETCH_ASSOC);
|
||||
|
||||
$this->assertEquals($this->expectedResult, $data);
|
||||
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
|
||||
|
||||
$data = $this->hydrateStmt($stmt, \PDO::FETCH_NUM);
|
||||
|
||||
$this->assertEquals($numExpectedResult, $data);
|
||||
}
|
||||
|
||||
public function testIteratorFetch()
|
||||
{
|
||||
$this->assertStandardAndIteratorFetchAreEqual(\PDO::FETCH_BOTH);
|
||||
$this->assertStandardAndIteratorFetchAreEqual(\PDO::FETCH_ASSOC);
|
||||
$this->assertStandardAndIteratorFetchAreEqual(\PDO::FETCH_NUM);
|
||||
}
|
||||
|
||||
public function assertStandardAndIteratorFetchAreEqual($fetchStyle)
|
||||
{
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
|
||||
$data = $this->hydrateStmt($stmt, $fetchStyle);
|
||||
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
|
||||
$data_iterator = $this->hydrateStmtIterator($stmt, $fetchStyle);
|
||||
|
||||
$this->assertEquals($data, $data_iterator);
|
||||
}
|
||||
|
||||
public function testDontCloseNoCache()
|
||||
{
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
|
||||
|
||||
$data = array();
|
||||
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
|
||||
|
||||
$data = array();
|
||||
while ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
$this->assertEquals(2, count($this->sqlLogger->queries));
|
||||
}
|
||||
|
||||
public function testDontFinishNoCache()
|
||||
{
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
|
||||
|
||||
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
|
||||
|
||||
$data = $this->hydrateStmt($stmt, \PDO::FETCH_NUM);
|
||||
|
||||
$this->assertEquals(2, count($this->sqlLogger->queries));
|
||||
}
|
||||
|
||||
public function assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, $fetchStyle)
|
||||
{
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
|
||||
|
||||
$this->assertEquals(2, $stmt->columnCount());
|
||||
$data = $this->hydrateStmt($stmt, $fetchStyle);
|
||||
$this->assertEquals($expectedResult, $data);
|
||||
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey"));
|
||||
|
||||
$this->assertEquals(2, $stmt->columnCount());
|
||||
$data = $this->hydrateStmt($stmt, $fetchStyle);
|
||||
$this->assertEquals($expectedResult, $data);
|
||||
$this->assertEquals(1, count($this->sqlLogger->queries), "just one dbal hit");
|
||||
}
|
||||
|
||||
public function testEmptyResultCache()
|
||||
{
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching WHERE test_int > 500", array(), array(), new QueryCacheProfile(10, "emptycachekey"));
|
||||
$data = $this->hydrateStmt($stmt);
|
||||
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching WHERE test_int > 500", array(), array(), new QueryCacheProfile(10, "emptycachekey"));
|
||||
$data = $this->hydrateStmt($stmt);
|
||||
|
||||
$this->assertEquals(1, count($this->sqlLogger->queries), "just one dbal hit");
|
||||
}
|
||||
|
||||
public function testChangeCacheImpl()
|
||||
{
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching WHERE test_int > 500", array(), array(), new QueryCacheProfile(10, "emptycachekey"));
|
||||
$data = $this->hydrateStmt($stmt);
|
||||
|
||||
$secondCache = new \Doctrine\Common\Cache\ArrayCache;
|
||||
$stmt = $this->_conn->executeQuery("SELECT * FROM caching WHERE test_int > 500", array(), array(), new QueryCacheProfile(10, "emptycachekey", $secondCache));
|
||||
$data = $this->hydrateStmt($stmt);
|
||||
|
||||
$this->assertEquals(2, count($this->sqlLogger->queries), "two hits");
|
||||
$this->assertEquals(1, count($secondCache->fetch("emptycachekey")));
|
||||
}
|
||||
|
||||
private function hydrateStmt($stmt, $fetchStyle = \PDO::FETCH_ASSOC)
|
||||
{
|
||||
$data = array();
|
||||
while ($row = $stmt->fetch($fetchStyle)) {
|
||||
$data[] = array_change_key_case($row, CASE_LOWER);
|
||||
}
|
||||
$stmt->closeCursor();
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function hydrateStmtIterator($stmt, $fetchStyle = \PDO::FETCH_ASSOC)
|
||||
{
|
||||
$data = array();
|
||||
$stmt->setFetchMode($fetchStyle);
|
||||
foreach ($stmt as $row) {
|
||||
$data[] = array_change_key_case($row, CASE_LOWER);
|
||||
}
|
||||
$stmt->closeCursor();
|
||||
return $data;
|
||||
}
|
||||
}
|
12
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php
vendored
Normal file
12
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional\Schema;
|
||||
|
||||
use Doctrine\DBAL\Schema;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class Db2SchemaManagerTest extends SchemaManagerFunctionalTestCase
|
||||
{
|
||||
|
||||
}
|
50
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
vendored
Normal file
50
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional\Schema;
|
||||
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
|
||||
{
|
||||
public function testSwitchPrimaryKeyColumns()
|
||||
{
|
||||
$tableOld = new Table("switch_primary_key_columns");
|
||||
$tableOld->addColumn('foo_id', 'integer');
|
||||
$tableOld->addColumn('bar_id', 'integer');
|
||||
$tableNew = clone $tableOld;
|
||||
|
||||
$this->_sm->createTable($tableOld);
|
||||
$tableFetched = $this->_sm->listTableDetails("switch_primary_key_columns");
|
||||
$tableNew = clone $tableFetched;
|
||||
$tableNew->setPrimaryKey(array('bar_id', 'foo_id'));
|
||||
|
||||
$comparator = new \Doctrine\DBAL\Schema\Comparator;
|
||||
$this->_sm->alterTable($comparator->diffTable($tableFetched, $tableNew));
|
||||
}
|
||||
|
||||
public function testDiffTableBug()
|
||||
{
|
||||
$schema = new Schema();
|
||||
$table = $schema->createTable('diffbug_routing_translations');
|
||||
$table->addColumn('id', 'integer');
|
||||
$table->addColumn('route', 'string');
|
||||
$table->addColumn('locale', 'string');
|
||||
$table->addColumn('attribute', 'string');
|
||||
$table->addColumn('localized_value', 'string');
|
||||
$table->addColumn('original_value', 'string');
|
||||
$table->setPrimaryKey(array('id'));
|
||||
$table->addUniqueIndex(array('route', 'locale', 'attribute'));
|
||||
$table->addIndex(array('localized_value')); // this is much more selective than the unique index
|
||||
|
||||
$this->_sm->createTable($table);
|
||||
$tableFetched = $this->_sm->listTableDetails("diffbug_routing_translations");
|
||||
|
||||
$comparator = new \Doctrine\DBAL\Schema\Comparator;
|
||||
$diff = $comparator->diffTable($tableFetched, $table);
|
||||
|
||||
$this->assertFalse($diff, "no changes expected.");
|
||||
}
|
||||
}
|
39
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php
vendored
Normal file
39
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional\Schema;
|
||||
|
||||
use Doctrine\DBAL\Schema;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if(!isset($GLOBALS['db_username'])) {
|
||||
$this->markTestSkipped('Foo');
|
||||
}
|
||||
|
||||
$username = $GLOBALS['db_username'];
|
||||
|
||||
$query = "GRANT ALL PRIVILEGES TO ".$username;
|
||||
|
||||
$conn = \Doctrine\Tests\TestUtil::getTempConnection();
|
||||
$conn->executeUpdate($query);
|
||||
}
|
||||
|
||||
public function testRenameTable()
|
||||
{
|
||||
$this->_sm->tryMethod('DropTable', 'list_tables_test');
|
||||
$this->_sm->tryMethod('DropTable', 'list_tables_test_new_name');
|
||||
|
||||
$this->createTestTable('list_tables_test');
|
||||
$this->_sm->renameTable('list_tables_test', 'list_tables_test_new_name');
|
||||
|
||||
$tables = $this->_sm->listTables();
|
||||
|
||||
$this->assertHasTable($tables, 'list_tables_test_new_name');
|
||||
}
|
||||
}
|
228
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
vendored
Normal file
228
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
vendored
Normal file
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional\Schema;
|
||||
|
||||
use Doctrine\DBAL\Schema;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
|
||||
{
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
if (!$this->_conn) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_conn->getConfiguration()->setFilterSchemaAssetsExpression(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-177
|
||||
*/
|
||||
public function testGetSearchPath()
|
||||
{
|
||||
$params = $this->_conn->getParams();
|
||||
|
||||
$paths = $this->_sm->getSchemaSearchPaths();
|
||||
$this->assertEquals(array($params['user'], 'public'), $paths);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-244
|
||||
*/
|
||||
public function testGetSchemaNames()
|
||||
{
|
||||
$names = $this->_sm->getSchemaNames();
|
||||
|
||||
$this->assertInternalType('array', $names);
|
||||
$this->assertTrue(count($names) > 0);
|
||||
$this->assertTrue(in_array('public', $names), "The public schema should be found.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-21
|
||||
*/
|
||||
public function testSupportDomainTypeFallback()
|
||||
{
|
||||
$createDomainTypeSQL = "CREATE DOMAIN MyMoney AS DECIMAL(18,2)";
|
||||
$this->_conn->exec($createDomainTypeSQL);
|
||||
|
||||
$createTableSQL = "CREATE TABLE domain_type_test (id INT PRIMARY KEY, value MyMoney)";
|
||||
$this->_conn->exec($createTableSQL);
|
||||
|
||||
$table = $this->_conn->getSchemaManager()->listTableDetails('domain_type_test');
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Types\DecimalType', $table->getColumn('value')->getType());
|
||||
|
||||
Type::addType('MyMoney', 'Doctrine\Tests\DBAL\Functional\Schema\MoneyType');
|
||||
$this->_conn->getDatabasePlatform()->registerDoctrineTypeMapping('MyMoney', 'MyMoney');
|
||||
|
||||
$table = $this->_conn->getSchemaManager()->listTableDetails('domain_type_test');
|
||||
$this->assertInstanceOf('Doctrine\Tests\DBAL\Functional\Schema\MoneyType', $table->getColumn('value')->getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-37
|
||||
*/
|
||||
public function testDetectsAutoIncrement()
|
||||
{
|
||||
$autoincTable = new \Doctrine\DBAL\Schema\Table('autoinc_table');
|
||||
$column = $autoincTable->addColumn('id', 'integer');
|
||||
$column->setAutoincrement(true);
|
||||
$this->_sm->createTable($autoincTable);
|
||||
$autoincTable = $this->_sm->listTableDetails('autoinc_table');
|
||||
|
||||
$this->assertTrue($autoincTable->getColumn('id')->getAutoincrement());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-37
|
||||
*/
|
||||
public function testAlterTableAutoIncrementAdd()
|
||||
{
|
||||
$tableFrom = new \Doctrine\DBAL\Schema\Table('autoinc_table_add');
|
||||
$column = $tableFrom->addColumn('id', 'integer');
|
||||
$this->_sm->createTable($tableFrom);
|
||||
$tableFrom = $this->_sm->listTableDetails('autoinc_table_add');
|
||||
$this->assertFalse($tableFrom->getColumn('id')->getAutoincrement());
|
||||
|
||||
$tableTo = new \Doctrine\DBAL\Schema\Table('autoinc_table_add');
|
||||
$column = $tableTo->addColumn('id', 'integer');
|
||||
$column->setAutoincrement(true);
|
||||
|
||||
$c = new \Doctrine\DBAL\Schema\Comparator();
|
||||
$diff = $c->diffTable($tableFrom, $tableTo);
|
||||
$sql = $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff);
|
||||
$this->assertEquals(array(
|
||||
"CREATE SEQUENCE autoinc_table_add_id_seq",
|
||||
"SELECT setval('autoinc_table_add_id_seq', (SELECT MAX(id) FROM autoinc_table_add))",
|
||||
"ALTER TABLE autoinc_table_add ALTER id SET DEFAULT nextval('autoinc_table_add_id_seq')",
|
||||
), $sql);
|
||||
|
||||
$this->_sm->alterTable($diff);
|
||||
$tableFinal = $this->_sm->listTableDetails('autoinc_table_add');
|
||||
$this->assertTrue($tableFinal->getColumn('id')->getAutoincrement());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-37
|
||||
*/
|
||||
public function testAlterTableAutoIncrementDrop()
|
||||
{
|
||||
$tableFrom = new \Doctrine\DBAL\Schema\Table('autoinc_table_drop');
|
||||
$column = $tableFrom->addColumn('id', 'integer');
|
||||
$column->setAutoincrement(true);
|
||||
$this->_sm->createTable($tableFrom);
|
||||
$tableFrom = $this->_sm->listTableDetails('autoinc_table_drop');
|
||||
$this->assertTrue($tableFrom->getColumn('id')->getAutoincrement());
|
||||
|
||||
$tableTo = new \Doctrine\DBAL\Schema\Table('autoinc_table_drop');
|
||||
$column = $tableTo->addColumn('id', 'integer');
|
||||
|
||||
$c = new \Doctrine\DBAL\Schema\Comparator();
|
||||
$diff = $c->diffTable($tableFrom, $tableTo);
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $diff, "There should be a difference and not false being returned from the table comparison");
|
||||
$this->assertEquals(array("ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT"), $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff));
|
||||
|
||||
$this->_sm->alterTable($diff);
|
||||
$tableFinal = $this->_sm->listTableDetails('autoinc_table_drop');
|
||||
$this->assertFalse($tableFinal->getColumn('id')->getAutoincrement());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-75
|
||||
*/
|
||||
public function testTableWithSchema()
|
||||
{
|
||||
$this->_conn->exec('CREATE SCHEMA nested');
|
||||
|
||||
$nestedRelatedTable = new \Doctrine\DBAL\Schema\Table('nested.schemarelated');
|
||||
$column = $nestedRelatedTable->addColumn('id', 'integer');
|
||||
$column->setAutoincrement(true);
|
||||
$nestedRelatedTable->setPrimaryKey(array('id'));
|
||||
|
||||
$nestedSchemaTable = new \Doctrine\DBAL\Schema\Table('nested.schematable');
|
||||
$column = $nestedSchemaTable->addColumn('id', 'integer');
|
||||
$column->setAutoincrement(true);
|
||||
$nestedSchemaTable->setPrimaryKey(array('id'));
|
||||
$nestedSchemaTable->addUnnamedForeignKeyConstraint($nestedRelatedTable, array('id'), array('id'));
|
||||
|
||||
$this->_sm->createTable($nestedRelatedTable);
|
||||
$this->_sm->createTable($nestedSchemaTable);
|
||||
|
||||
$tables = $this->_sm->listTableNames();
|
||||
$this->assertContains('nested.schematable', $tables, "The table should be detected with its non-public schema.");
|
||||
|
||||
$nestedSchemaTable = $this->_sm->listTableDetails('nested.schematable');
|
||||
$this->assertTrue($nestedSchemaTable->hasColumn('id'));
|
||||
$this->assertEquals(array('id'), $nestedSchemaTable->getPrimaryKey()->getColumns());
|
||||
|
||||
$relatedFks = $nestedSchemaTable->getForeignKeys();
|
||||
$this->assertEquals(1, count($relatedFks));
|
||||
$relatedFk = array_pop($relatedFks);
|
||||
$this->assertEquals("nested.schemarelated", $relatedFk->getForeignTableName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-91
|
||||
* @group DBAL-88
|
||||
*/
|
||||
public function testReturnQuotedAssets()
|
||||
{
|
||||
$sql = 'create table dbal91_something ( id integer CONSTRAINT id_something PRIMARY KEY NOT NULL ,"table" integer );';
|
||||
$this->_conn->exec($sql);
|
||||
|
||||
$sql = 'ALTER TABLE dbal91_something ADD CONSTRAINT something_input FOREIGN KEY( "table" ) REFERENCES dbal91_something ON UPDATE CASCADE;';
|
||||
$this->_conn->exec($sql);
|
||||
|
||||
$table = $this->_sm->listTableDetails('dbal91_something');
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
"CREATE TABLE dbal91_something (id INT NOT NULL, \"table\" INT DEFAULT NULL, PRIMARY KEY(id))",
|
||||
"CREATE INDEX IDX_A9401304ECA7352B ON dbal91_something (\"table\")",
|
||||
),
|
||||
$this->_conn->getDatabasePlatform()->getCreateTableSQL($table)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-204
|
||||
*/
|
||||
public function testFilterSchemaExpression()
|
||||
{
|
||||
$testTable = new \Doctrine\DBAL\Schema\Table('dbal204_test_prefix');
|
||||
$column = $testTable->addColumn('id', 'integer');
|
||||
$this->_sm->createTable($testTable);
|
||||
$testTable = new \Doctrine\DBAL\Schema\Table('dbal204_without_prefix');
|
||||
$column = $testTable->addColumn('id', 'integer');
|
||||
$this->_sm->createTable($testTable);
|
||||
|
||||
$this->_conn->getConfiguration()->setFilterSchemaAssetsExpression('^dbal204_');
|
||||
$names = $this->_sm->listTableNames();
|
||||
$this->assertEquals(2, count($names));
|
||||
|
||||
$this->_conn->getConfiguration()->setFilterSchemaAssetsExpression('^dbal204_test');
|
||||
$names = $this->_sm->listTableNames();
|
||||
$this->assertEquals(1, count($names));
|
||||
}
|
||||
}
|
||||
|
||||
class MoneyType extends Type
|
||||
{
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return "MyMoney";
|
||||
}
|
||||
|
||||
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
|
||||
{
|
||||
return 'MyMoney';
|
||||
}
|
||||
|
||||
}
|
37
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php
vendored
Normal file
37
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional\Schema;
|
||||
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\TableDiff;
|
||||
use Doctrine\DBAL\Schema\ColumnDiff;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
|
||||
{
|
||||
protected function getPlatformName()
|
||||
{
|
||||
return "mssql";
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-255
|
||||
*/
|
||||
public function testDropColumnConstraints()
|
||||
{
|
||||
$table = new Table('sqlsrv_drop_column');
|
||||
$table->addColumn('id', 'integer');
|
||||
$table->addColumn('todrop', 'decimal', array('default' => 10.2));
|
||||
|
||||
$this->_sm->createTable($table);
|
||||
|
||||
$diff = new TableDiff('sqlsrv_drop_column', array(), array(), array(
|
||||
new Column('todrop', Type::getType('decimal'))
|
||||
));
|
||||
$this->_sm->alterTable($diff);
|
||||
|
||||
$columns = $this->_sm->listTableColumns('sqlsrv_drop_column');
|
||||
$this->assertEquals(1, count($columns));
|
||||
}
|
||||
}
|
642
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
vendored
Normal file
642
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
vendored
Normal file
@@ -0,0 +1,642 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional\Schema;
|
||||
|
||||
use Doctrine\DBAL\Types\Type,
|
||||
Doctrine\DBAL\Schema\AbstractSchemaManager;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\DBAL\Events;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager
|
||||
*/
|
||||
protected $_sm;
|
||||
|
||||
protected function getPlatformName()
|
||||
{
|
||||
$class = get_class($this);
|
||||
$e = explode('\\', $class);
|
||||
$testClass = end($e);
|
||||
$dbms = strtolower(str_replace('SchemaManagerTest', null, $testClass));
|
||||
return $dbms;
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$dbms = $this->getPlatformName();
|
||||
|
||||
if ($this->_conn->getDatabasePlatform()->getName() !== $dbms) {
|
||||
$this->markTestSkipped(get_class($this) . ' requires the use of ' . $dbms);
|
||||
}
|
||||
|
||||
$this->_sm = $this->_conn->getSchemaManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-195
|
||||
*/
|
||||
public function testDropAndCreateSequence()
|
||||
{
|
||||
if(!$this->_conn->getDatabasePlatform()->supportsSequences()) {
|
||||
$this->markTestSkipped($this->_conn->getDriver()->getName().' does not support sequences.');
|
||||
}
|
||||
|
||||
$sequence = new \Doctrine\DBAL\Schema\Sequence('dropcreate_sequences_test_seq', 20, 10);
|
||||
$this->_sm->dropAndCreateSequence($sequence);
|
||||
}
|
||||
|
||||
public function testListSequences()
|
||||
{
|
||||
if(!$this->_conn->getDatabasePlatform()->supportsSequences()) {
|
||||
$this->markTestSkipped($this->_conn->getDriver()->getName().' does not support sequences.');
|
||||
}
|
||||
|
||||
$sequence = new \Doctrine\DBAL\Schema\Sequence('list_sequences_test_seq', 20, 10);
|
||||
$this->_sm->createSequence($sequence);
|
||||
|
||||
$sequences = $this->_sm->listSequences();
|
||||
|
||||
$this->assertInternalType('array', $sequences, 'listSequences() should return an array.');
|
||||
|
||||
$foundSequence = null;
|
||||
foreach($sequences AS $sequence) {
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $sequence, 'Array elements of listSequences() should be Sequence instances.');
|
||||
if(strtolower($sequence->getName()) == 'list_sequences_test_seq') {
|
||||
$foundSequence = $sequence;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertNotNull($foundSequence, "Sequence with name 'list_sequences_test_seq' was not found.");
|
||||
$this->assertEquals(20, $foundSequence->getAllocationSize(), "Allocation Size is expected to be 20.");
|
||||
$this->assertEquals(10, $foundSequence->getInitialValue(), "Initial Value is expected to be 10.");
|
||||
}
|
||||
|
||||
public function testListDatabases()
|
||||
{
|
||||
if (!$this->_sm->getDatabasePlatform()->supportsCreateDropDatabase()) {
|
||||
$this->markTestSkipped('Cannot drop Database client side with this Driver.');
|
||||
}
|
||||
|
||||
$this->_sm->dropAndCreateDatabase('test_create_database');
|
||||
$databases = $this->_sm->listDatabases();
|
||||
|
||||
$databases = \array_map('strtolower', $databases);
|
||||
|
||||
$this->assertEquals(true, \in_array('test_create_database', $databases));
|
||||
}
|
||||
|
||||
public function testListTables()
|
||||
{
|
||||
$this->createTestTable('list_tables_test');
|
||||
$tables = $this->_sm->listTables();
|
||||
|
||||
$this->assertInternalType('array', $tables);
|
||||
$this->assertTrue(count($tables) > 0, "List Tables has to find at least one table named 'list_tables_test'.");
|
||||
|
||||
$foundTable = false;
|
||||
foreach ($tables AS $table) {
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\Table', $table);
|
||||
if (strtolower($table->getName()) == 'list_tables_test') {
|
||||
$foundTable = true;
|
||||
|
||||
$this->assertTrue($table->hasColumn('id'));
|
||||
$this->assertTrue($table->hasColumn('test'));
|
||||
$this->assertTrue($table->hasColumn('foreign_key_test'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertTrue( $foundTable , "The 'list_tables_test' table has to be found.");
|
||||
}
|
||||
|
||||
public function createListTableColumns()
|
||||
{
|
||||
$table = new \Doctrine\DBAL\Schema\Table('list_table_columns');
|
||||
$table->addColumn('id', 'integer', array('notnull' => true));
|
||||
$table->addColumn('test', 'string', array('length' => 255, 'notnull' => false, 'default' => 'expected default'));
|
||||
$table->addColumn('foo', 'text', array('notnull' => true));
|
||||
$table->addColumn('bar', 'decimal', array('precision' => 10, 'scale' => 4, 'notnull' => false));
|
||||
$table->addColumn('baz1', 'datetime');
|
||||
$table->addColumn('baz2', 'time');
|
||||
$table->addColumn('baz3', 'date');
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
public function testListTableColumns()
|
||||
{
|
||||
$table = $this->createListTableColumns();
|
||||
|
||||
$this->_sm->dropAndCreateTable($table);
|
||||
|
||||
$columns = $this->_sm->listTableColumns('list_table_columns');
|
||||
|
||||
$this->assertArrayHasKey('id', $columns);
|
||||
$this->assertEquals('id', strtolower($columns['id']->getname()));
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Types\IntegerType', $columns['id']->gettype());
|
||||
$this->assertEquals(false, $columns['id']->getunsigned());
|
||||
$this->assertEquals(true, $columns['id']->getnotnull());
|
||||
$this->assertEquals(null, $columns['id']->getdefault());
|
||||
$this->assertInternalType('array', $columns['id']->getPlatformOptions());
|
||||
|
||||
$this->assertArrayHasKey('test', $columns);
|
||||
$this->assertEquals('test', strtolower($columns['test']->getname()));
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Types\StringType', $columns['test']->gettype());
|
||||
$this->assertEquals(255, $columns['test']->getlength());
|
||||
$this->assertEquals(false, $columns['test']->getfixed());
|
||||
$this->assertEquals(false, $columns['test']->getnotnull());
|
||||
$this->assertEquals('expected default', $columns['test']->getdefault());
|
||||
$this->assertInternalType('array', $columns['test']->getPlatformOptions());
|
||||
|
||||
$this->assertEquals('foo', strtolower($columns['foo']->getname()));
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Types\TextType', $columns['foo']->gettype());
|
||||
$this->assertEquals(false, $columns['foo']->getunsigned());
|
||||
$this->assertEquals(false, $columns['foo']->getfixed());
|
||||
$this->assertEquals(true, $columns['foo']->getnotnull());
|
||||
$this->assertEquals(null, $columns['foo']->getdefault());
|
||||
$this->assertInternalType('array', $columns['foo']->getPlatformOptions());
|
||||
|
||||
$this->assertEquals('bar', strtolower($columns['bar']->getname()));
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Types\DecimalType', $columns['bar']->gettype());
|
||||
$this->assertEquals(null, $columns['bar']->getlength());
|
||||
$this->assertEquals(10, $columns['bar']->getprecision());
|
||||
$this->assertEquals(4, $columns['bar']->getscale());
|
||||
$this->assertEquals(false, $columns['bar']->getunsigned());
|
||||
$this->assertEquals(false, $columns['bar']->getfixed());
|
||||
$this->assertEquals(false, $columns['bar']->getnotnull());
|
||||
$this->assertEquals(null, $columns['bar']->getdefault());
|
||||
$this->assertInternalType('array', $columns['bar']->getPlatformOptions());
|
||||
|
||||
$this->assertEquals('baz1', strtolower($columns['baz1']->getname()));
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Types\DateTimeType', $columns['baz1']->gettype());
|
||||
$this->assertEquals(true, $columns['baz1']->getnotnull());
|
||||
$this->assertEquals(null, $columns['baz1']->getdefault());
|
||||
$this->assertInternalType('array', $columns['baz1']->getPlatformOptions());
|
||||
|
||||
$this->assertEquals('baz2', strtolower($columns['baz2']->getname()));
|
||||
$this->assertContains($columns['baz2']->gettype()->getName(), array('time', 'date', 'datetime'));
|
||||
$this->assertEquals(true, $columns['baz2']->getnotnull());
|
||||
$this->assertEquals(null, $columns['baz2']->getdefault());
|
||||
$this->assertInternalType('array', $columns['baz2']->getPlatformOptions());
|
||||
|
||||
$this->assertEquals('baz3', strtolower($columns['baz3']->getname()));
|
||||
$this->assertContains($columns['baz2']->gettype()->getName(), array('time', 'date', 'datetime'));
|
||||
$this->assertEquals(true, $columns['baz3']->getnotnull());
|
||||
$this->assertEquals(null, $columns['baz3']->getdefault());
|
||||
$this->assertInternalType('array', $columns['baz3']->getPlatformOptions());
|
||||
}
|
||||
|
||||
public function testListTableColumnsDispatchEvent()
|
||||
{
|
||||
$table = $this->createListTableColumns();
|
||||
|
||||
$this->_sm->dropAndCreateTable($table);
|
||||
|
||||
$listenerMock = $this->getMock('ListTableColumnsDispatchEventListener', array('onSchemaColumnDefinition'));
|
||||
$listenerMock
|
||||
->expects($this->exactly(7))
|
||||
->method('onSchemaColumnDefinition');
|
||||
|
||||
$oldEventManager = $this->_sm->getDatabasePlatform()->getEventManager();
|
||||
|
||||
$eventManager = new EventManager();
|
||||
$eventManager->addEventListener(array(Events::onSchemaColumnDefinition), $listenerMock);
|
||||
|
||||
$this->_sm->getDatabasePlatform()->setEventManager($eventManager);
|
||||
|
||||
$this->_sm->listTableColumns('list_table_columns');
|
||||
|
||||
$this->_sm->getDatabasePlatform()->setEventManager($oldEventManager);
|
||||
}
|
||||
|
||||
public function testListTableIndexesDispatchEvent()
|
||||
{
|
||||
$table = $this->getTestTable('list_table_indexes_test');
|
||||
$table->addUniqueIndex(array('test'), 'test_index_name');
|
||||
$table->addIndex(array('id', 'test'), 'test_composite_idx');
|
||||
|
||||
$this->_sm->dropAndCreateTable($table);
|
||||
|
||||
$listenerMock = $this->getMock('ListTableIndexesDispatchEventListener', array('onSchemaIndexDefinition'));
|
||||
$listenerMock
|
||||
->expects($this->exactly(3))
|
||||
->method('onSchemaIndexDefinition');
|
||||
|
||||
$oldEventManager = $this->_sm->getDatabasePlatform()->getEventManager();
|
||||
|
||||
$eventManager = new EventManager();
|
||||
$eventManager->addEventListener(array(Events::onSchemaIndexDefinition), $listenerMock);
|
||||
|
||||
$this->_sm->getDatabasePlatform()->setEventManager($eventManager);
|
||||
|
||||
$this->_sm->listTableIndexes('list_table_indexes_test');
|
||||
|
||||
$this->_sm->getDatabasePlatform()->setEventManager($oldEventManager);
|
||||
}
|
||||
|
||||
public function testDiffListTableColumns()
|
||||
{
|
||||
if ($this->_sm->getDatabasePlatform()->getName() == 'oracle') {
|
||||
$this->markTestSkipped('Does not work with Oracle, since it cannot detect DateTime, Date and Time differenecs (at the moment).');
|
||||
}
|
||||
|
||||
$offlineTable = $this->createListTableColumns();
|
||||
$onlineTable = $this->_sm->listTableDetails('list_table_columns');
|
||||
|
||||
$comparator = new \Doctrine\DBAL\Schema\Comparator();
|
||||
$diff = $comparator->diffTable($offlineTable, $onlineTable);
|
||||
|
||||
$this->assertFalse($diff, "No differences should be detected with the offline vs online schema.");
|
||||
}
|
||||
|
||||
public function testListTableIndexes()
|
||||
{
|
||||
$table = $this->getTestCompositeTable('list_table_indexes_test');
|
||||
$table->addUniqueIndex(array('test'), 'test_index_name');
|
||||
$table->addIndex(array('id', 'test'), 'test_composite_idx');
|
||||
|
||||
$this->_sm->dropAndCreateTable($table);
|
||||
|
||||
$tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_test');
|
||||
|
||||
$this->assertEquals(3, count($tableIndexes));
|
||||
|
||||
$this->assertArrayHasKey('primary', $tableIndexes, 'listTableIndexes() has to return a "primary" array key.');
|
||||
$this->assertEquals(array('id', 'other_id'), array_map('strtolower', $tableIndexes['primary']->getColumns()));
|
||||
$this->assertTrue($tableIndexes['primary']->isUnique());
|
||||
$this->assertTrue($tableIndexes['primary']->isPrimary());
|
||||
|
||||
$this->assertEquals('test_index_name', $tableIndexes['test_index_name']->getName());
|
||||
$this->assertEquals(array('test'), array_map('strtolower', $tableIndexes['test_index_name']->getColumns()));
|
||||
$this->assertTrue($tableIndexes['test_index_name']->isUnique());
|
||||
$this->assertFalse($tableIndexes['test_index_name']->isPrimary());
|
||||
|
||||
$this->assertEquals('test_composite_idx', $tableIndexes['test_composite_idx']->getName());
|
||||
$this->assertEquals(array('id', 'test'), array_map('strtolower', $tableIndexes['test_composite_idx']->getColumns()));
|
||||
$this->assertFalse($tableIndexes['test_composite_idx']->isUnique());
|
||||
$this->assertFalse($tableIndexes['test_composite_idx']->isPrimary());
|
||||
}
|
||||
|
||||
public function testDropAndCreateIndex()
|
||||
{
|
||||
$table = $this->getTestTable('test_create_index');
|
||||
$table->addUniqueIndex(array('test'), 'test');
|
||||
$this->_sm->dropAndCreateTable($table);
|
||||
|
||||
$this->_sm->dropAndCreateIndex($table->getIndex('test'), $table);
|
||||
$tableIndexes = $this->_sm->listTableIndexes('test_create_index');
|
||||
$this->assertInternalType('array', $tableIndexes);
|
||||
|
||||
$this->assertEquals('test', strtolower($tableIndexes['test']->getName()));
|
||||
$this->assertEquals(array('test'), array_map('strtolower', $tableIndexes['test']->getColumns()));
|
||||
$this->assertTrue($tableIndexes['test']->isUnique());
|
||||
$this->assertFalse($tableIndexes['test']->isPrimary());
|
||||
}
|
||||
|
||||
public function testCreateTableWithForeignKeys()
|
||||
{
|
||||
if(!$this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
|
||||
$this->markTestSkipped('Platform does not support foreign keys.');
|
||||
}
|
||||
|
||||
$tableB = $this->getTestTable('test_foreign');
|
||||
|
||||
$this->_sm->dropAndCreateTable($tableB);
|
||||
|
||||
$tableA = $this->getTestTable('test_create_fk');
|
||||
$tableA->addForeignKeyConstraint('test_foreign', array('foreign_key_test'), array('id'));
|
||||
|
||||
$this->_sm->dropAndCreateTable($tableA);
|
||||
|
||||
$fkTable = $this->_sm->listTableDetails('test_create_fk');
|
||||
$fkConstraints = $fkTable->getForeignKeys();
|
||||
$this->assertEquals(1, count($fkConstraints), "Table 'test_create_fk1' has to have one foreign key.");
|
||||
|
||||
$fkConstraint = current($fkConstraints);
|
||||
$this->assertInstanceOf('\Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkConstraint);
|
||||
$this->assertEquals('test_foreign', strtolower($fkConstraint->getForeignTableName()));
|
||||
$this->assertEquals(array('foreign_key_test'), array_map('strtolower', $fkConstraint->getColumns()));
|
||||
$this->assertEquals(array('id'), array_map('strtolower', $fkConstraint->getForeignColumns()));
|
||||
|
||||
$this->assertTrue($fkTable->columnsAreIndexed($fkConstraint->getColumns()), "The columns of a foreign key constraint should always be indexed.");
|
||||
}
|
||||
|
||||
public function testListForeignKeys()
|
||||
{
|
||||
if(!$this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) {
|
||||
$this->markTestSkipped('Does not support foreign key constraints.');
|
||||
}
|
||||
|
||||
$this->createTestTable('test_create_fk1');
|
||||
$this->createTestTable('test_create_fk2');
|
||||
|
||||
$foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(
|
||||
array('foreign_key_test'), 'test_create_fk2', array('id'), 'foreign_key_test_fk', array('onDelete' => 'CASCADE')
|
||||
);
|
||||
|
||||
$this->_sm->createForeignKey($foreignKey, 'test_create_fk1');
|
||||
|
||||
$fkeys = $this->_sm->listTableForeignKeys('test_create_fk1');
|
||||
|
||||
$this->assertEquals(1, count($fkeys), "Table 'test_create_fk1' has to have one foreign key.");
|
||||
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]);
|
||||
$this->assertEquals(array('foreign_key_test'), array_map('strtolower', $fkeys[0]->getLocalColumns()));
|
||||
$this->assertEquals(array('id'), array_map('strtolower', $fkeys[0]->getForeignColumns()));
|
||||
$this->assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName()));
|
||||
|
||||
if($fkeys[0]->hasOption('onDelete')) {
|
||||
$this->assertEquals('CASCADE', $fkeys[0]->getOption('onDelete'));
|
||||
}
|
||||
}
|
||||
|
||||
protected function getCreateExampleViewSql()
|
||||
{
|
||||
$this->markTestSkipped('No Create Example View SQL was defined for this SchemaManager');
|
||||
}
|
||||
|
||||
public function testCreateSchema()
|
||||
{
|
||||
$this->createTestTable('test_table');
|
||||
|
||||
$schema = $this->_sm->createSchema();
|
||||
$this->assertTrue($schema->hasTable('test_table'));
|
||||
}
|
||||
|
||||
public function testAlterTableScenario()
|
||||
{
|
||||
if(!$this->_sm->getDatabasePlatform()->supportsAlterTable()) {
|
||||
$this->markTestSkipped('Alter Table is not supported by this platform.');
|
||||
}
|
||||
|
||||
$this->createTestTable('alter_table');
|
||||
$this->createTestTable('alter_table_foreign');
|
||||
|
||||
$table = $this->_sm->listTableDetails('alter_table');
|
||||
$this->assertTrue($table->hasColumn('id'));
|
||||
$this->assertTrue($table->hasColumn('test'));
|
||||
$this->assertTrue($table->hasColumn('foreign_key_test'));
|
||||
$this->assertEquals(0, count($table->getForeignKeys()));
|
||||
$this->assertEquals(1, count($table->getIndexes()));
|
||||
|
||||
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table");
|
||||
$tableDiff->addedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', Type::getType('integer'));
|
||||
$tableDiff->removedColumns['test'] = $table->getColumn('test');
|
||||
|
||||
$this->_sm->alterTable($tableDiff);
|
||||
|
||||
$table = $this->_sm->listTableDetails('alter_table');
|
||||
$this->assertFalse($table->hasColumn('test'));
|
||||
$this->assertTrue($table->hasColumn('foo'));
|
||||
|
||||
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table");
|
||||
$tableDiff->addedIndexes[] = new \Doctrine\DBAL\Schema\Index('foo_idx', array('foo'));
|
||||
|
||||
$this->_sm->alterTable($tableDiff);
|
||||
|
||||
$table = $this->_sm->listTableDetails('alter_table');
|
||||
$this->assertEquals(2, count($table->getIndexes()));
|
||||
$this->assertTrue($table->hasIndex('foo_idx'));
|
||||
$this->assertEquals(array('foo'), array_map('strtolower', $table->getIndex('foo_idx')->getColumns()));
|
||||
$this->assertFalse($table->getIndex('foo_idx')->isPrimary());
|
||||
$this->assertFalse($table->getIndex('foo_idx')->isUnique());
|
||||
|
||||
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table");
|
||||
$tableDiff->changedIndexes[] = new \Doctrine\DBAL\Schema\Index('foo_idx', array('foo', 'foreign_key_test'));
|
||||
|
||||
$this->_sm->alterTable($tableDiff);
|
||||
|
||||
$table = $this->_sm->listTableDetails('alter_table');
|
||||
$this->assertEquals(2, count($table->getIndexes()));
|
||||
$this->assertTrue($table->hasIndex('foo_idx'));
|
||||
$this->assertEquals(array('foo', 'foreign_key_test'), array_map('strtolower', $table->getIndex('foo_idx')->getColumns()));
|
||||
|
||||
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table");
|
||||
$tableDiff->removedIndexes[] = new \Doctrine\DBAL\Schema\Index('foo_idx', array('foo', 'foreign_key_test'));
|
||||
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('foreign_key_test'), 'alter_table_foreign', array('id'));
|
||||
$tableDiff->addedForeignKeys[] = $fk;
|
||||
|
||||
$this->_sm->alterTable($tableDiff);
|
||||
$table = $this->_sm->listTableDetails('alter_table');
|
||||
|
||||
// dont check for index size here, some platforms automatically add indexes for foreign keys.
|
||||
$this->assertFalse($table->hasIndex('foo_idx'));
|
||||
|
||||
$this->assertEquals(1, count($table->getForeignKeys()));
|
||||
$fks = $table->getForeignKeys();
|
||||
$foreignKey = current($fks);
|
||||
$this->assertEquals('alter_table_foreign', strtolower($foreignKey->getForeignTableName()));
|
||||
$this->assertEquals(array('foreign_key_test'), array_map('strtolower', $foreignKey->getColumns()));
|
||||
$this->assertEquals(array('id'), array_map('strtolower', $foreignKey->getForeignColumns()));
|
||||
}
|
||||
|
||||
public function testCreateAndListViews()
|
||||
{
|
||||
$this->createTestTable('view_test_table');
|
||||
|
||||
$name = "doctrine_test_view";
|
||||
$sql = "SELECT * FROM view_test_table";
|
||||
|
||||
$view = new \Doctrine\DBAL\Schema\View($name, $sql);
|
||||
|
||||
$this->_sm->dropAndCreateView($view);
|
||||
|
||||
$views = $this->_sm->listViews();
|
||||
}
|
||||
|
||||
public function testAutoincrementDetection()
|
||||
{
|
||||
if (!$this->_sm->getDatabasePlatform()->supportsIdentityColumns()) {
|
||||
$this->markTestSkipped('This test is only supported on platforms that have autoincrement');
|
||||
}
|
||||
|
||||
$table = new \Doctrine\DBAL\Schema\Table('test_autoincrement');
|
||||
$table->setSchemaConfig($this->_sm->createSchemaConfig());
|
||||
$table->addColumn('id', 'integer', array('autoincrement' => true));
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
$this->_sm->createTable($table);
|
||||
|
||||
$inferredTable = $this->_sm->listTableDetails('test_autoincrement');
|
||||
$this->assertTrue($inferredTable->hasColumn('id'));
|
||||
$this->assertTrue($inferredTable->getColumn('id')->getAutoincrement());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-887
|
||||
*/
|
||||
public function testUpdateSchemaWithForeignKeyRenaming()
|
||||
{
|
||||
if (!$this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
|
||||
$this->markTestSkipped('This test is only supported on platforms that have foreign keys.');
|
||||
}
|
||||
|
||||
$table = new \Doctrine\DBAL\Schema\Table('test_fk_base');
|
||||
$table->addColumn('id', 'integer');
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
$tableFK = new \Doctrine\DBAL\Schema\Table('test_fk_rename');
|
||||
$tableFK->setSchemaConfig($this->_sm->createSchemaConfig());
|
||||
$tableFK->addColumn('id', 'integer');
|
||||
$tableFK->addColumn('fk_id', 'integer');
|
||||
$tableFK->setPrimaryKey(array('id'));
|
||||
$tableFK->addIndex(array('fk_id'), 'fk_idx');
|
||||
$tableFK->addForeignKeyConstraint('test_fk_base', array('fk_id'), array('id'));
|
||||
|
||||
$this->_sm->createTable($table);
|
||||
$this->_sm->createTable($tableFK);
|
||||
|
||||
$tableFKNew = new \Doctrine\DBAL\Schema\Table('test_fk_rename');
|
||||
$tableFKNew->setSchemaConfig($this->_sm->createSchemaConfig());
|
||||
$tableFKNew->addColumn('id', 'integer');
|
||||
$tableFKNew->addColumn('rename_fk_id', 'integer');
|
||||
$tableFKNew->setPrimaryKey(array('id'));
|
||||
$tableFKNew->addIndex(array('rename_fk_id'), 'fk_idx');
|
||||
$tableFKNew->addForeignKeyConstraint('test_fk_base', array('rename_fk_id'), array('id'));
|
||||
|
||||
$c = new \Doctrine\DBAL\Schema\Comparator();
|
||||
$tableDiff = $c->diffTable($tableFK, $tableFKNew);
|
||||
|
||||
$this->_sm->alterTable($tableDiff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-42
|
||||
*/
|
||||
public function testGetColumnComment()
|
||||
{
|
||||
if (!$this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && !$this->_conn->getDatabasePlatform()->supportsCommentOnStatement()) {
|
||||
$this->markTestSkipped('Database does not support column comments.');
|
||||
}
|
||||
|
||||
$table = new \Doctrine\DBAL\Schema\Table('column_comment_test');
|
||||
$table->addColumn('id', 'integer', array('comment' => 'This is a comment'));
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
$this->_sm->createTable($table);
|
||||
|
||||
$columns = $this->_sm->listTableColumns("column_comment_test");
|
||||
$this->assertEquals(1, count($columns));
|
||||
$this->assertEquals('This is a comment', $columns['id']->getComment());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-42
|
||||
*/
|
||||
public function testAutomaticallyAppendCommentOnMarkedColumns()
|
||||
{
|
||||
if (!$this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && !$this->_conn->getDatabasePlatform()->supportsCommentOnStatement()) {
|
||||
$this->markTestSkipped('Database does not support column comments.');
|
||||
}
|
||||
|
||||
$table = new \Doctrine\DBAL\Schema\Table('column_comment_test2');
|
||||
$table->addColumn('id', 'integer', array('comment' => 'This is a comment'));
|
||||
$table->addColumn('obj', 'object', array('comment' => 'This is a comment'));
|
||||
$table->addColumn('arr', 'array', array('comment' => 'This is a comment'));
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
$this->_sm->createTable($table);
|
||||
|
||||
$columns = $this->_sm->listTableColumns("column_comment_test2");
|
||||
$this->assertEquals(3, count($columns));
|
||||
$this->assertEquals('This is a comment', $columns['id']->getComment());
|
||||
$this->assertEquals('This is a comment', $columns['obj']->getComment(), "The Doctrine2 Typehint should be stripped from comment.");
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Types\ObjectType', $columns['obj']->getType(), "The Doctrine2 should be detected from comment hint.");
|
||||
$this->assertEquals('This is a comment', $columns['arr']->getComment(), "The Doctrine2 Typehint should be stripped from comment.");
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Types\ArrayType', $columns['arr']->getType(), "The Doctrine2 should be detected from comment hint.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-197
|
||||
*/
|
||||
public function testListTableWithBlob()
|
||||
{
|
||||
$table = new \Doctrine\DBAL\Schema\Table('test_blob_table');
|
||||
$table->addColumn('id', 'integer', array('comment' => 'This is a comment'));
|
||||
$table->addColumn('binarydata', 'blob', array());
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
$this->_sm->createTable($table);
|
||||
$blobTable = $this->_sm->listTableDetails('test_blob_table');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $data
|
||||
*/
|
||||
protected function createTestTable($name = 'test_table', $data = array())
|
||||
{
|
||||
$options = array();
|
||||
if (isset($data['options'])) {
|
||||
$options = $data['options'];
|
||||
}
|
||||
|
||||
$table = $this->getTestTable($name, $options);
|
||||
|
||||
$this->_sm->dropAndCreateTable($table);
|
||||
}
|
||||
|
||||
protected function getTestTable($name, $options=array())
|
||||
{
|
||||
$table = new \Doctrine\DBAL\Schema\Table($name, array(), array(), array(), false, $options);
|
||||
$table->setSchemaConfig($this->_sm->createSchemaConfig());
|
||||
$table->addColumn('id', 'integer', array('notnull' => true));
|
||||
$table->setPrimaryKey(array('id'));
|
||||
$table->addColumn('test', 'string', array('length' => 255));
|
||||
$table->addColumn('foreign_key_test', 'integer');
|
||||
return $table;
|
||||
}
|
||||
|
||||
protected function getTestCompositeTable($name)
|
||||
{
|
||||
$table = new \Doctrine\DBAL\Schema\Table($name, array(), array(), array(), false, array());
|
||||
$table->setSchemaConfig($this->_sm->createSchemaConfig());
|
||||
$table->addColumn('id', 'integer', array('notnull' => true));
|
||||
$table->addColumn('other_id', 'integer', array('notnull' => true));
|
||||
$table->setPrimaryKey(array('id', 'other_id'));
|
||||
$table->addColumn('test', 'string', array('length' => 255));
|
||||
return $table;
|
||||
}
|
||||
|
||||
protected function assertHasTable($tables, $tableName)
|
||||
{
|
||||
$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_test_new_name') {
|
||||
$foundTable = true;
|
||||
}
|
||||
}
|
||||
$this->assertTrue($foundTable, "Could not find new table");
|
||||
}
|
||||
|
||||
public function testListForeignKeysComposite()
|
||||
{
|
||||
if(!$this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) {
|
||||
$this->markTestSkipped('Does not support foreign key constraints.');
|
||||
}
|
||||
|
||||
$this->_sm->createTable($this->getTestTable('test_create_fk3'));
|
||||
$this->_sm->createTable($this->getTestCompositeTable('test_create_fk4'));
|
||||
|
||||
$foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(
|
||||
array('id', 'foreign_key_test'), 'test_create_fk4', array('id', 'other_id'), 'foreign_key_test_fk'
|
||||
);
|
||||
|
||||
$this->_sm->createForeignKey($foreignKey, 'test_create_fk3');
|
||||
|
||||
$fkeys = $this->_sm->listTableForeignKeys('test_create_fk3');
|
||||
|
||||
$this->assertEquals(1, count($fkeys), "Table 'test_create_fk3' has to have one foreign key.");
|
||||
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]);
|
||||
$this->assertEquals(array('id', 'foreign_key_test'), array_map('strtolower', $fkeys[0]->getLocalColumns()));
|
||||
$this->assertEquals(array('id', 'other_id'), array_map('strtolower', $fkeys[0]->getForeignColumns()));
|
||||
}
|
||||
}
|
46
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php
vendored
Normal file
46
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional\Schema;
|
||||
|
||||
use Doctrine\DBAL\Schema;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
|
||||
{
|
||||
/**
|
||||
* SQLITE does not support databases.
|
||||
*
|
||||
* @expectedException \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function testListDatabases()
|
||||
{
|
||||
$this->_sm->listDatabases();
|
||||
}
|
||||
|
||||
public function testCreateAndDropDatabase()
|
||||
{
|
||||
$path = dirname(__FILE__).'/test_create_and_drop_sqlite_database.sqlite';
|
||||
|
||||
$this->_sm->createDatabase($path);
|
||||
$this->assertEquals(true, file_exists($path));
|
||||
$this->_sm->dropDatabase($path);
|
||||
$this->assertEquals(false, file_exists($path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function testRenameTable()
|
||||
{
|
||||
$this->_sm->renameTable('oldname', 'newname');
|
||||
}
|
||||
|
||||
public function testAutoincrementDetection()
|
||||
{
|
||||
$this->markTestSkipped(
|
||||
'There is currently no reliable way to determine whether an SQLite column is marked as '
|
||||
. 'auto-increment. So, while it does support a single identity column, we cannot with '
|
||||
. 'certainty determine which it is.');
|
||||
}
|
||||
}
|
102
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php
vendored
Normal file
102
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional;
|
||||
|
||||
use \Doctrine\DBAL\Schema\Table;
|
||||
use \Doctrine\DBAL\Schema\Column;
|
||||
use \Doctrine\DBAL\Types\Type;
|
||||
|
||||
class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
try {
|
||||
$this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTableSQL("nontemporary"));
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if ($this->_conn) {
|
||||
try {
|
||||
$tempTable = $this->_conn->getDatabasePlatform()->getTemporaryTableName("temporary");
|
||||
$this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTemporaryTableSQL($tempTable));
|
||||
} catch(\Exception $e) { }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1337
|
||||
* @return void
|
||||
*/
|
||||
public function testDropTemporaryTableNotAutoCommitTransaction()
|
||||
{
|
||||
$platform = $this->_conn->getDatabasePlatform();
|
||||
$columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true));
|
||||
$tempTable = $platform->getTemporaryTableName("temporary");
|
||||
|
||||
$createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
|
||||
. $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
|
||||
$this->_conn->executeUpdate($createTempTableSQL);
|
||||
|
||||
$table = new Table("nontemporary");
|
||||
$table->addColumn("id", "integer");
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
foreach ($platform->getCreateTableSQL($table) AS $sql) {
|
||||
$this->_conn->executeQuery($sql);
|
||||
}
|
||||
|
||||
$this->_conn->beginTransaction();
|
||||
$this->_conn->insert("nontemporary", array("id" => 1));
|
||||
$this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable));
|
||||
$this->_conn->insert("nontemporary", array("id" => 2));
|
||||
|
||||
$this->_conn->rollback();
|
||||
|
||||
$rows = $this->_conn->fetchAll('SELECT * FROM nontemporary');
|
||||
$this->assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1337
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateTemporaryTableNotAutoCommitTransaction()
|
||||
{
|
||||
$platform = $this->_conn->getDatabasePlatform();
|
||||
$columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true));
|
||||
$tempTable = $platform->getTemporaryTableName("temporary");
|
||||
|
||||
$createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
|
||||
. $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
|
||||
|
||||
$table = new Table("nontemporary");
|
||||
$table->addColumn("id", "integer");
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
foreach ($platform->getCreateTableSQL($table) AS $sql) {
|
||||
$this->_conn->executeQuery($sql);
|
||||
}
|
||||
|
||||
$this->_conn->beginTransaction();
|
||||
$this->_conn->insert("nontemporary", array("id" => 1));
|
||||
|
||||
$this->_conn->exec($createTempTableSQL);
|
||||
$this->_conn->insert("nontemporary", array("id" => 2));
|
||||
|
||||
$this->_conn->rollback();
|
||||
|
||||
try {
|
||||
$this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable));
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
$rows = $this->_conn->fetchAll('SELECT * FROM nontemporary');
|
||||
$this->assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit.");
|
||||
}
|
||||
}
|
27
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php
vendored
Normal file
27
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional\Ticket;
|
||||
|
||||
/**
|
||||
* @group DBAL-168
|
||||
*/
|
||||
class DBAL168Test extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
public function testDomainsTable()
|
||||
{
|
||||
if ($this->_conn->getDatabasePlatform()->getName() != "postgresql") {
|
||||
$this->markTestSkipped('PostgreSQL only test');
|
||||
}
|
||||
|
||||
$table = new \Doctrine\DBAL\Schema\Table("domains");
|
||||
$table->addColumn('id', 'integer');
|
||||
$table->addColumn('parent_id', 'integer');
|
||||
$table->setPrimaryKey(array('id'));
|
||||
$table->addForeignKeyConstraint('domains', array('parent_id'), array('id'));
|
||||
|
||||
$this->_conn->getSchemaManager()->createTable($table);
|
||||
$table = $this->_conn->getSchemaManager()->listTableDetails('domains');
|
||||
|
||||
$this->assertEquals('domains', $table->getName());
|
||||
}
|
||||
}
|
48
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php
vendored
Normal file
48
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional\Ticket;
|
||||
|
||||
/**
|
||||
* @group DBAL-202
|
||||
*/
|
||||
class DBAL202Test extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if ($this->_conn->getDatabasePlatform()->getName() != 'oracle') {
|
||||
$this->markTestSkipped('OCI8 only test');
|
||||
}
|
||||
|
||||
if ($this->_conn->getSchemaManager()->tablesExist('DBAL202')) {
|
||||
$this->_conn->executeQuery('DELETE FROM DBAL202');
|
||||
} else {
|
||||
$table = new \Doctrine\DBAL\Schema\Table('DBAL202');
|
||||
$table->addColumn('id', 'integer');
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
$this->_conn->getSchemaManager()->createTable($table);
|
||||
}
|
||||
}
|
||||
|
||||
public function testStatementRollback()
|
||||
{
|
||||
$stmt = $this->_conn->prepare('INSERT INTO DBAL202 VALUES (8)');
|
||||
$this->_conn->beginTransaction();
|
||||
$stmt->execute();
|
||||
$this->_conn->rollback();
|
||||
|
||||
$this->assertEquals(0, $this->_conn->query('SELECT COUNT(1) FROM DBAL202')->fetchColumn());
|
||||
}
|
||||
|
||||
public function testStatementCommit()
|
||||
{
|
||||
$stmt = $this->_conn->prepare('INSERT INTO DBAL202 VALUES (8)');
|
||||
$this->_conn->beginTransaction();
|
||||
$stmt->execute();
|
||||
$this->_conn->commit();
|
||||
|
||||
$this->assertEquals(1, $this->_conn->query('SELECT COUNT(1) FROM DBAL202')->fetchColumn());
|
||||
}
|
||||
}
|
101
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php
vendored
Normal file
101
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
static private $typeCounter = 0;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
|
||||
$sm = $this->_conn->getSchemaManager();
|
||||
|
||||
$table = new \Doctrine\DBAL\Schema\Table("type_conversion");
|
||||
$table->addColumn('id', 'integer', array('notnull' => false));
|
||||
$table->addColumn('test_string', 'string', array('notnull' => false));
|
||||
$table->addColumn('test_boolean', 'boolean', array('notnull' => false));
|
||||
$table->addColumn('test_bigint', 'bigint', array('notnull' => false));
|
||||
$table->addColumn('test_smallint', 'bigint', array('notnull' => false));
|
||||
$table->addColumn('test_datetime', 'datetime', array('notnull' => false));
|
||||
$table->addColumn('test_datetimetz', 'datetimetz', array('notnull' => false));
|
||||
$table->addColumn('test_date', 'date', array('notnull' => false));
|
||||
$table->addColumn('test_time', 'time', array('notnull' => false));
|
||||
$table->addColumn('test_text', 'text', array('notnull' => false));
|
||||
$table->addColumn('test_array', 'array', array('notnull' => false));
|
||||
$table->addColumn('test_object', 'object', array('notnull' => false));
|
||||
$table->addColumn('test_float', 'float', array('notnull' => false));
|
||||
$table->addColumn('test_decimal', 'decimal', array('notnull' => false, 'scale' => 2, 'precision' => 10));
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
try {
|
||||
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) AS $sql) {
|
||||
$this->_conn->executeQuery($sql);
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static public function dataIdempotentDataConversion()
|
||||
{
|
||||
$obj = new \stdClass();
|
||||
$obj->foo = "bar";
|
||||
$obj->bar = "baz";
|
||||
|
||||
return array(
|
||||
array('string', 'ABCDEFGaaaBBB', 'string'),
|
||||
array('boolean', true, 'bool'),
|
||||
array('boolean', false, 'bool'),
|
||||
array('bigint', 12345678, 'string'),
|
||||
array('smallint', 123, 'int'),
|
||||
array('datetime', new \DateTime('2010-04-05 10:10:10'), 'DateTime'),
|
||||
array('datetimetz', new \DateTime('2010-04-05 10:10:10'), 'DateTime'),
|
||||
array('date', new \DateTime('2010-04-05'), 'DateTime'),
|
||||
array('time', new \DateTime('10:10:10'), 'DateTime'),
|
||||
array('text', str_repeat('foo ', 1000), 'string'),
|
||||
array('array', array('foo' => 'bar'), 'array'),
|
||||
array('object', $obj, 'object'),
|
||||
array('float', 1.5, 'float'),
|
||||
array('decimal', 1.55, 'string'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataIdempotentDataConversion
|
||||
* @param string $type
|
||||
* @param mixed $originalValue
|
||||
* @param string $expectedPhpType
|
||||
*/
|
||||
public function testIdempotentDataConversion($type, $originalValue, $expectedPhpType)
|
||||
{
|
||||
$columnName = "test_" . $type;
|
||||
$typeInstance = Type::getType($type);
|
||||
$insertionValue = $typeInstance->convertToDatabaseValue($originalValue, $this->_conn->getDatabasePlatform());
|
||||
|
||||
$this->_conn->insert('type_conversion', array('id' => ++self::$typeCounter, $columnName => $insertionValue));
|
||||
|
||||
$sql = "SELECT " . $columnName . " FROM type_conversion WHERE id = " . self::$typeCounter;
|
||||
$actualDbValue = $typeInstance->convertToPHPValue($this->_conn->fetchColumn($sql), $this->_conn->getDatabasePlatform());
|
||||
|
||||
if ($originalValue instanceof \DateTime) {
|
||||
$this->assertInstanceOf($expectedPhpType, $actualDbValue, "The expected type from the conversion to and back from the database should be " . $expectedPhpType);
|
||||
} else {
|
||||
$this->assertInternalType($expectedPhpType, $actualDbValue, "The expected type from the conversion to and back from the database should be " . $expectedPhpType);
|
||||
}
|
||||
|
||||
if ($type !== "datetimetz") {
|
||||
$this->assertEquals($originalValue, $actualDbValue, "Conversion between values should produce the same out as in value, but doesnt!");
|
||||
|
||||
if ($originalValue instanceof \DateTime) {
|
||||
$this->assertEquals($originalValue->getTimezone()->getName(), $actualDbValue->getTimezone()->getName(), "Timezones should be the same.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
137
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php
vendored
Normal file
137
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Functional;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use PDO;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class WriteTest extends \Doctrine\Tests\DbalFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
try {
|
||||
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
|
||||
$table = new \Doctrine\DBAL\Schema\Table("write_table");
|
||||
$table->addColumn('test_int', 'integer');
|
||||
$table->addColumn('test_string', 'string', array('notnull' => false));
|
||||
$table->setPrimaryKey(array('test_int'));
|
||||
|
||||
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) AS $sql) {
|
||||
$this->_conn->executeQuery($sql);
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
$this->_conn->executeUpdate('DELETE FROM write_table');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-80
|
||||
*/
|
||||
public function testExecuteUpdateFirstTypeIsNull()
|
||||
{
|
||||
$sql = "INSERT INTO write_table (test_string, test_int) VALUES (?, ?)";
|
||||
$this->_conn->executeUpdate($sql, array("text", 1111), array(null, PDO::PARAM_INT));
|
||||
|
||||
$sql = "SELECT * FROM write_table WHERE test_string = ? AND test_int = ?";
|
||||
$this->assertTrue((bool)$this->_conn->fetchColumn($sql, array("text", 1111)));
|
||||
}
|
||||
|
||||
public function testExecuteUpdate()
|
||||
{
|
||||
$sql = "INSERT INTO write_table (test_int) VALUES ( " . $this->_conn->quote(1) . ")";
|
||||
$affected = $this->_conn->executeUpdate($sql);
|
||||
|
||||
$this->assertEquals(1, $affected, "executeUpdate() should return the number of affected rows!");
|
||||
}
|
||||
|
||||
public function testExecuteUpdateWithTypes()
|
||||
{
|
||||
$sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)";
|
||||
$affected = $this->_conn->executeUpdate($sql, array(1, 'foo'), array(\PDO::PARAM_INT, \PDO::PARAM_STR));
|
||||
|
||||
$this->assertEquals(1, $affected, "executeUpdate() should return the number of affected rows!");
|
||||
}
|
||||
|
||||
public function testPrepareRowCountReturnsAffectedRows()
|
||||
{
|
||||
$sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)";
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
|
||||
$stmt->bindValue(1, 1);
|
||||
$stmt->bindValue(2, "foo");
|
||||
$stmt->execute();
|
||||
|
||||
$this->assertEquals(1, $stmt->rowCount());
|
||||
}
|
||||
|
||||
public function testPrepareWithPdoTypes()
|
||||
{
|
||||
$sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)";
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
|
||||
$stmt->bindValue(1, 1, \PDO::PARAM_INT);
|
||||
$stmt->bindValue(2, "foo", \PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
|
||||
$this->assertEquals(1, $stmt->rowCount());
|
||||
}
|
||||
|
||||
public function testPrepareWithDbalTypes()
|
||||
{
|
||||
$sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)";
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
|
||||
$stmt->bindValue(1, 1, Type::getType('integer'));
|
||||
$stmt->bindValue(2, "foo", Type::getType('string'));
|
||||
$stmt->execute();
|
||||
|
||||
$this->assertEquals(1, $stmt->rowCount());
|
||||
}
|
||||
|
||||
public function testPrepareWithDbalTypeNames()
|
||||
{
|
||||
$sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)";
|
||||
$stmt = $this->_conn->prepare($sql);
|
||||
|
||||
$stmt->bindValue(1, 1, 'integer');
|
||||
$stmt->bindValue(2, "foo", 'string');
|
||||
$stmt->execute();
|
||||
|
||||
$this->assertEquals(1, $stmt->rowCount());
|
||||
}
|
||||
|
||||
public function insertRows()
|
||||
{
|
||||
$this->assertEquals(1, $this->_conn->insert('write_table', array('test_int' => 1, 'test_string' => 'foo')));
|
||||
$this->assertEquals(1, $this->_conn->insert('write_table', array('test_int' => 2, 'test_string' => 'bar')));
|
||||
}
|
||||
|
||||
public function testInsert()
|
||||
{
|
||||
$this->insertRows();
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$this->insertRows();
|
||||
|
||||
$this->assertEquals(1, $this->_conn->delete('write_table', array('test_int' => 2)));
|
||||
$this->assertEquals(1, count($this->_conn->fetchAll('SELECT * FROM write_table')));
|
||||
|
||||
$this->assertEquals(1, $this->_conn->delete('write_table', array('test_int' => 1)));
|
||||
$this->assertEquals(0, count($this->_conn->fetchAll('SELECT * FROM write_table')));
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$this->insertRows();
|
||||
|
||||
$this->assertEquals(1, $this->_conn->update('write_table', array('test_string' => 'bar'), array('test_string' => 'foo')));
|
||||
$this->assertEquals(2, $this->_conn->update('write_table', array('test_string' => 'baz'), array('test_string' => 'bar')));
|
||||
$this->assertEquals(0, $this->_conn->update('write_table', array('test_string' => 'baz'), array('test_string' => 'bar')));
|
||||
}
|
||||
}
|
49
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php
vendored
Normal file
49
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
use Doctrine\DBAL\Platforms;
|
||||
|
||||
class MockPlatform extends \Doctrine\DBAL\Platforms\AbstractPlatform
|
||||
{
|
||||
/**
|
||||
* Gets the SQL Snippet used to declare a BLOB column type.
|
||||
*/
|
||||
public function getBlobTypeDeclarationSQL(array $field)
|
||||
{
|
||||
throw DBALException::notSupported(__METHOD__);
|
||||
}
|
||||
|
||||
public function getBooleanTypeDeclarationSQL(array $columnDef) {}
|
||||
public function getIntegerTypeDeclarationSQL(array $columnDef) {}
|
||||
public function getBigIntTypeDeclarationSQL(array $columnDef) {}
|
||||
public function getSmallIntTypeDeclarationSQL(array $columnDef) {}
|
||||
public function _getCommonIntegerTypeDeclarationSQL(array $columnDef) {}
|
||||
|
||||
public function getVarcharTypeDeclarationSQL(array $field)
|
||||
{
|
||||
return "DUMMYVARCHAR()";
|
||||
}
|
||||
|
||||
/** @override */
|
||||
public function getClobTypeDeclarationSQL(array $field)
|
||||
{
|
||||
return 'DUMMYCLOB';
|
||||
}
|
||||
|
||||
public function getVarcharDefaultLength()
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'mock';
|
||||
}
|
||||
protected function initializeDoctrineTypeMappings() {
|
||||
}
|
||||
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
388
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
vendored
Normal file
388
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
vendored
Normal file
@@ -0,0 +1,388 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Platforms;
|
||||
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\DBAL\Events;
|
||||
|
||||
abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
/**
|
||||
* @var Doctrine\DBAL\Platforms\AbstractPlatform
|
||||
*/
|
||||
protected $_platform;
|
||||
|
||||
abstract public function createPlatform();
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_platform = $this->createPlatform();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1360
|
||||
*/
|
||||
public function testQuoteIdentifier()
|
||||
{
|
||||
if ($this->_platform->getName() == "mssql") {
|
||||
$this->markTestSkipped('Not working this way on mssql.');
|
||||
}
|
||||
|
||||
$c = $this->_platform->getIdentifierQuoteCharacter();
|
||||
$this->assertEquals($c."test".$c, $this->_platform->quoteIdentifier("test"));
|
||||
$this->assertEquals($c."test".$c.".".$c."test".$c, $this->_platform->quoteIdentifier("test.test"));
|
||||
$this->assertEquals(str_repeat($c, 4), $this->_platform->quoteIdentifier($c));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1360
|
||||
*/
|
||||
public function testQuoteSingleIdentifier()
|
||||
{
|
||||
if ($this->_platform->getName() == "mssql") {
|
||||
$this->markTestSkipped('Not working this way on mssql.');
|
||||
}
|
||||
|
||||
$c = $this->_platform->getIdentifierQuoteCharacter();
|
||||
$this->assertEquals($c."test".$c, $this->_platform->quoteSingleIdentifier("test"));
|
||||
$this->assertEquals($c."test.test".$c, $this->_platform->quoteSingleIdentifier("test.test"));
|
||||
$this->assertEquals(str_repeat($c, 4), $this->_platform->quoteSingleIdentifier($c));
|
||||
}
|
||||
|
||||
public function testGetInvalidtForeignKeyReferentialActionSQL()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$this->_platform->getForeignKeyReferentialActionSQL('unknown');
|
||||
}
|
||||
|
||||
public function testGetUnknownDoctrineMappingType()
|
||||
{
|
||||
$this->setExpectedException('Doctrine\DBAL\DBALException');
|
||||
$this->_platform->getDoctrineTypeMapping('foobar');
|
||||
}
|
||||
|
||||
public function testRegisterDoctrineMappingType()
|
||||
{
|
||||
$this->_platform->registerDoctrineTypeMapping('foo', 'integer');
|
||||
$this->assertEquals('integer', $this->_platform->getDoctrineTypeMapping('foo'));
|
||||
}
|
||||
|
||||
public function testRegisterUnknownDoctrineMappingType()
|
||||
{
|
||||
$this->setExpectedException('Doctrine\DBAL\DBALException');
|
||||
$this->_platform->registerDoctrineTypeMapping('foo', 'bar');
|
||||
}
|
||||
|
||||
public function testCreateWithNoColumns()
|
||||
{
|
||||
$table = new \Doctrine\DBAL\Schema\Table('test');
|
||||
|
||||
$this->setExpectedException('Doctrine\DBAL\DBALException');
|
||||
$sql = $this->_platform->getCreateTableSQL($table);
|
||||
}
|
||||
|
||||
public function testGeneratesTableCreationSql()
|
||||
{
|
||||
$table = new \Doctrine\DBAL\Schema\Table('test');
|
||||
$table->addColumn('id', 'integer', array('notnull' => true, 'autoincrement' => true));
|
||||
$table->addColumn('test', 'string', array('notnull' => false, 'length' => 255));
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
$sql = $this->_platform->getCreateTableSQL($table);
|
||||
$this->assertEquals($this->getGenerateTableSql(), $sql[0]);
|
||||
}
|
||||
|
||||
abstract public function getGenerateTableSql();
|
||||
|
||||
public function testGenerateTableWithMultiColumnUniqueIndex()
|
||||
{
|
||||
$table = new \Doctrine\DBAL\Schema\Table('test');
|
||||
$table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255));
|
||||
$table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255));
|
||||
$table->addUniqueIndex(array("foo", "bar"));
|
||||
|
||||
$sql = $this->_platform->getCreateTableSQL($table);
|
||||
$this->assertEquals($this->getGenerateTableWithMultiColumnUniqueIndexSql(), $sql);
|
||||
}
|
||||
|
||||
abstract public function getGenerateTableWithMultiColumnUniqueIndexSql();
|
||||
|
||||
public function testGeneratesIndexCreationSql()
|
||||
{
|
||||
$indexDef = new \Doctrine\DBAL\Schema\Index('my_idx', array('user_name', 'last_login'));
|
||||
|
||||
$this->assertEquals(
|
||||
$this->getGenerateIndexSql(),
|
||||
$this->_platform->getCreateIndexSQL($indexDef, 'mytable')
|
||||
);
|
||||
}
|
||||
|
||||
abstract public function getGenerateIndexSql();
|
||||
|
||||
public function testGeneratesUniqueIndexCreationSql()
|
||||
{
|
||||
$indexDef = new \Doctrine\DBAL\Schema\Index('index_name', array('test', 'test2'), true);
|
||||
|
||||
$sql = $this->_platform->getCreateIndexSQL($indexDef, 'test');
|
||||
$this->assertEquals($this->getGenerateUniqueIndexSql(), $sql);
|
||||
}
|
||||
|
||||
abstract public function getGenerateUniqueIndexSql();
|
||||
|
||||
public function testGeneratesForeignKeyCreationSql()
|
||||
{
|
||||
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name_id'), 'other_table', array('id'), '');
|
||||
|
||||
$sql = $this->_platform->getCreateForeignKeySQL($fk, 'test');
|
||||
$this->assertEquals($sql, $this->getGenerateForeignKeySql());
|
||||
}
|
||||
|
||||
abstract public function getGenerateForeignKeySql();
|
||||
|
||||
public function testGeneratesConstraintCreationSql()
|
||||
{
|
||||
$idx = new \Doctrine\DBAL\Schema\Index('constraint_name', array('test'), true, false);
|
||||
$sql = $this->_platform->getCreateConstraintSQL($idx, 'test');
|
||||
$this->assertEquals($this->getGenerateConstraintUniqueIndexSql(), $sql);
|
||||
|
||||
$pk = new \Doctrine\DBAL\Schema\Index('constraint_name', array('test'), true, true);
|
||||
$sql = $this->_platform->getCreateConstraintSQL($pk, 'test');
|
||||
$this->assertEquals($this->getGenerateConstraintPrimaryIndexSql(), $sql);
|
||||
|
||||
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk');
|
||||
$sql = $this->_platform->getCreateConstraintSQL($fk, 'test');
|
||||
$this->assertEquals($this->getGenerateConstraintForeignKeySql(), $sql);
|
||||
}
|
||||
|
||||
protected function getBitAndComparisonExpressionSql($value1, $value2)
|
||||
{
|
||||
return '(' . $value1 . ' & ' . $value2 . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1213
|
||||
*/
|
||||
public function testGeneratesBitAndComparisonExpressionSql()
|
||||
{
|
||||
$sql = $this->_platform->getBitAndComparisonExpression(2, 4);
|
||||
$this->assertEquals($this->getBitAndComparisonExpressionSql(2, 4), $sql);
|
||||
}
|
||||
|
||||
protected function getBitOrComparisonExpressionSql($value1, $value2)
|
||||
{
|
||||
return '(' . $value1 . ' | ' . $value2 . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1213
|
||||
*/
|
||||
public function testGeneratesBitOrComparisonExpressionSql()
|
||||
{
|
||||
$sql = $this->_platform->getBitOrComparisonExpression(2, 4);
|
||||
$this->assertEquals($this->getBitOrComparisonExpressionSql(2, 4), $sql);
|
||||
}
|
||||
|
||||
public function getGenerateConstraintUniqueIndexSql()
|
||||
{
|
||||
return 'ALTER TABLE test ADD CONSTRAINT constraint_name UNIQUE (test)';
|
||||
}
|
||||
|
||||
public function getGenerateConstraintPrimaryIndexSql()
|
||||
{
|
||||
return 'ALTER TABLE test ADD CONSTRAINT constraint_name PRIMARY KEY (test)';
|
||||
}
|
||||
|
||||
public function getGenerateConstraintForeignKeySql()
|
||||
{
|
||||
return 'ALTER TABLE test ADD CONSTRAINT constraint_fk FOREIGN KEY (fk_name) REFERENCES foreign (id)';
|
||||
}
|
||||
|
||||
abstract public function getGenerateAlterTableSql();
|
||||
|
||||
public function testGeneratesTableAlterationSql()
|
||||
{
|
||||
$expectedSql = $this->getGenerateAlterTableSql();
|
||||
|
||||
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable');
|
||||
$tableDiff->newName = 'userlist';
|
||||
$tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('notnull' => false));
|
||||
$tableDiff->removedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', \Doctrine\DBAL\Types\Type::getType('integer'));
|
||||
$tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff(
|
||||
'bar', new \Doctrine\DBAL\Schema\Column(
|
||||
'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('default' => 'def')
|
||||
),
|
||||
array('type', 'notnull', 'default')
|
||||
);
|
||||
$tableDiff->changedColumns['bloo'] = new \Doctrine\DBAL\Schema\ColumnDiff(
|
||||
'bloo', new \Doctrine\DBAL\Schema\Column(
|
||||
'bloo', \Doctrine\DBAL\Types\Type::getType('boolean'), array('default' => false)
|
||||
),
|
||||
array('type', 'notnull', 'default')
|
||||
);
|
||||
|
||||
$sql = $this->_platform->getAlterTableSQL($tableDiff);
|
||||
|
||||
$this->assertEquals($expectedSql, $sql);
|
||||
}
|
||||
|
||||
public function testGetCustomColumnDeclarationSql()
|
||||
{
|
||||
$field = array('columnDefinition' => 'MEDIUMINT(6) UNSIGNED');
|
||||
$this->assertEquals('foo MEDIUMINT(6) UNSIGNED', $this->_platform->getColumnDeclarationSQL('foo', $field));
|
||||
}
|
||||
|
||||
public function testGetCreateTableSqlDispatchEvent()
|
||||
{
|
||||
$listenerMock = $this->getMock('GetCreateTableSqlDispatchEvenListener', array('onSchemaCreateTable', 'onSchemaCreateTableColumn'));
|
||||
$listenerMock
|
||||
->expects($this->once())
|
||||
->method('onSchemaCreateTable');
|
||||
$listenerMock
|
||||
->expects($this->exactly(2))
|
||||
->method('onSchemaCreateTableColumn');
|
||||
|
||||
$eventManager = new EventManager();
|
||||
$eventManager->addEventListener(array(Events::onSchemaCreateTable, Events::onSchemaCreateTableColumn), $listenerMock);
|
||||
|
||||
$this->_platform->setEventManager($eventManager);
|
||||
|
||||
$table = new \Doctrine\DBAL\Schema\Table('test');
|
||||
$table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255));
|
||||
$table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255));
|
||||
|
||||
$this->_platform->getCreateTableSQL($table);
|
||||
}
|
||||
|
||||
public function testGetDropTableSqlDispatchEvent()
|
||||
{
|
||||
$listenerMock = $this->getMock('GetDropTableSqlDispatchEventListener', array('onSchemaDropTable'));
|
||||
$listenerMock
|
||||
->expects($this->once())
|
||||
->method('onSchemaDropTable');
|
||||
|
||||
$eventManager = new EventManager();
|
||||
$eventManager->addEventListener(array(Events::onSchemaDropTable), $listenerMock);
|
||||
|
||||
$this->_platform->setEventManager($eventManager);
|
||||
|
||||
$this->_platform->getDropTableSQL('TABLE');
|
||||
}
|
||||
|
||||
public function testGetAlterTableSqlDispatchEvent()
|
||||
{
|
||||
$events = array(
|
||||
'onSchemaAlterTable',
|
||||
'onSchemaAlterTableAddColumn',
|
||||
'onSchemaAlterTableRemoveColumn',
|
||||
'onSchemaAlterTableChangeColumn',
|
||||
'onSchemaAlterTableRenameColumn'
|
||||
);
|
||||
|
||||
$listenerMock = $this->getMock('GetAlterTableSqlDispatchEvenListener', $events);
|
||||
$listenerMock
|
||||
->expects($this->once())
|
||||
->method('onSchemaAlterTable');
|
||||
$listenerMock
|
||||
->expects($this->once())
|
||||
->method('onSchemaAlterTableAddColumn');
|
||||
$listenerMock
|
||||
->expects($this->once())
|
||||
->method('onSchemaAlterTableRemoveColumn');
|
||||
$listenerMock
|
||||
->expects($this->once())
|
||||
->method('onSchemaAlterTableChangeColumn');
|
||||
$listenerMock
|
||||
->expects($this->once())
|
||||
->method('onSchemaAlterTableRenameColumn');
|
||||
|
||||
$eventManager = new EventManager();
|
||||
$events = array(
|
||||
Events::onSchemaAlterTable,
|
||||
Events::onSchemaAlterTableAddColumn,
|
||||
Events::onSchemaAlterTableRemoveColumn,
|
||||
Events::onSchemaAlterTableChangeColumn,
|
||||
Events::onSchemaAlterTableRenameColumn
|
||||
);
|
||||
$eventManager->addEventListener($events, $listenerMock);
|
||||
|
||||
$this->_platform->setEventManager($eventManager);
|
||||
|
||||
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable');
|
||||
$tableDiff->addedColumns['added'] = new \Doctrine\DBAL\Schema\Column('added', \Doctrine\DBAL\Types\Type::getType('integer'), array());
|
||||
$tableDiff->removedColumns['removed'] = new \Doctrine\DBAL\Schema\Column('removed', \Doctrine\DBAL\Types\Type::getType('integer'), array());
|
||||
$tableDiff->changedColumns['changed'] = new \Doctrine\DBAL\Schema\ColumnDiff(
|
||||
'changed', new \Doctrine\DBAL\Schema\Column(
|
||||
'changed2', \Doctrine\DBAL\Types\Type::getType('string'), array()
|
||||
),
|
||||
array()
|
||||
);
|
||||
$tableDiff->renamedColumns['renamed'] = new \Doctrine\DBAL\Schema\Column('renamed2', \Doctrine\DBAL\Types\Type::getType('integer'), array());
|
||||
|
||||
$this->_platform->getAlterTableSQL($tableDiff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-42
|
||||
*/
|
||||
public function testCreateTableColumnComments()
|
||||
{
|
||||
$table = new \Doctrine\DBAL\Schema\Table('test');
|
||||
$table->addColumn('id', 'integer', array('comment' => 'This is a comment'));
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
$this->assertEquals($this->getCreateTableColumnCommentsSQL(), $this->_platform->getCreateTableSQL($table));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-42
|
||||
*/
|
||||
public function testAlterTableColumnComments()
|
||||
{
|
||||
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable');
|
||||
$tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('comment' => 'A comment'));
|
||||
$tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff(
|
||||
'bar', new \Doctrine\DBAL\Schema\Column(
|
||||
'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('comment' => 'B comment')
|
||||
),
|
||||
array('comment')
|
||||
);
|
||||
|
||||
$this->assertEquals($this->getAlterTableColumnCommentsSQL(), $this->_platform->getAlterTableSQL($tableDiff));
|
||||
}
|
||||
|
||||
public function testCreateTableColumnTypeComments()
|
||||
{
|
||||
$table = new \Doctrine\DBAL\Schema\Table('test');
|
||||
$table->addColumn('id', 'integer');
|
||||
$table->addColumn('data', 'array');
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
$this->assertEquals($this->getCreateTableColumnTypeCommentsSQL(), $this->_platform->getCreateTableSQL($table));
|
||||
}
|
||||
|
||||
public function getCreateTableColumnCommentsSQL()
|
||||
{
|
||||
$this->markTestSkipped('Platform does not support Column comments.');
|
||||
}
|
||||
|
||||
public function getAlterTableColumnCommentsSQL()
|
||||
{
|
||||
$this->markTestSkipped('Platform does not support Column comments.');
|
||||
}
|
||||
|
||||
public function getCreateTableColumnTypeCommentsSQL()
|
||||
{
|
||||
$this->markTestSkipped('Platform does not support Column comments.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-45
|
||||
*/
|
||||
public function testKeywordList()
|
||||
{
|
||||
$keywordList = $this->_platform->getReservedKeywordsList();
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Platforms\Keywords\KeywordList', $keywordList);
|
||||
|
||||
$this->assertTrue($keywordList->isKeyword('table'));
|
||||
}
|
||||
}
|
229
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
vendored
Normal file
229
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Platforms;
|
||||
|
||||
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\TableDiff;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Index;
|
||||
|
||||
class MySqlPlatformTest extends AbstractPlatformTestCase
|
||||
{
|
||||
public function createPlatform()
|
||||
{
|
||||
return new MysqlPlatform;
|
||||
}
|
||||
|
||||
public function testGenerateMixedCaseTableCreate()
|
||||
{
|
||||
$table = new Table("Foo");
|
||||
$table->addColumn("Bar", "integer");
|
||||
|
||||
$sql = $this->_platform->getCreateTableSQL($table);
|
||||
$this->assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) ENGINE = InnoDB', array_shift($sql));
|
||||
}
|
||||
|
||||
public function getGenerateTableSql()
|
||||
{
|
||||
return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) ENGINE = InnoDB';
|
||||
}
|
||||
|
||||
public function getGenerateTableWithMultiColumnUniqueIndexSql()
|
||||
{
|
||||
return array(
|
||||
'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA (foo, bar)) ENGINE = InnoDB'
|
||||
);
|
||||
}
|
||||
|
||||
public function getGenerateAlterTableSql()
|
||||
{
|
||||
return array(
|
||||
"ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL, DROP foo, CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL, CHANGE bloo bloo TINYINT(1) DEFAULT '0' NOT NULL"
|
||||
);
|
||||
}
|
||||
|
||||
public function testGeneratesSqlSnippets()
|
||||
{
|
||||
$this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
|
||||
$this->assertEquals('`', $this->_platform->getIdentifierQuoteCharacter(), 'Quote character is not correct');
|
||||
$this->assertEquals('CONCAT(column1, column2, column3)', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation function is not correct');
|
||||
}
|
||||
|
||||
public function testGeneratesTransactionsCommands()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED),
|
||||
''
|
||||
);
|
||||
$this->assertEquals(
|
||||
'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testGeneratesDDLSnippets()
|
||||
{
|
||||
$this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSQL());
|
||||
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
|
||||
$this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar'));
|
||||
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
|
||||
}
|
||||
|
||||
public function testGeneratesTypeDeclarationForIntegers()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'INT',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(array())
|
||||
);
|
||||
$this->assertEquals(
|
||||
'INT AUTO_INCREMENT',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
|
||||
));
|
||||
$this->assertEquals(
|
||||
'INT AUTO_INCREMENT',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(
|
||||
array('autoincrement' => true, 'primary' => true)
|
||||
));
|
||||
}
|
||||
|
||||
public function testGeneratesTypeDeclarationForStrings()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'CHAR(10)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(
|
||||
array('length' => 10, 'fixed' => true)
|
||||
));
|
||||
$this->assertEquals(
|
||||
'VARCHAR(50)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
|
||||
'Variable string declaration is not correct'
|
||||
);
|
||||
$this->assertEquals(
|
||||
'VARCHAR(255)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(array()),
|
||||
'Long string declaration is not correct'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPrefersIdentityColumns()
|
||||
{
|
||||
$this->assertTrue($this->_platform->prefersIdentityColumns());
|
||||
}
|
||||
|
||||
public function testSupportsIdentityColumns()
|
||||
{
|
||||
$this->assertTrue($this->_platform->supportsIdentityColumns());
|
||||
}
|
||||
|
||||
public function testDoesSupportSavePoints()
|
||||
{
|
||||
$this->assertTrue($this->_platform->supportsSavepoints());
|
||||
}
|
||||
|
||||
public function getGenerateIndexSql()
|
||||
{
|
||||
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
|
||||
}
|
||||
|
||||
public function getGenerateUniqueIndexSql()
|
||||
{
|
||||
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
|
||||
}
|
||||
|
||||
public function getGenerateForeignKeySql()
|
||||
{
|
||||
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-126
|
||||
*/
|
||||
public function testUniquePrimaryKey()
|
||||
{
|
||||
$keyTable = new Table("foo");
|
||||
$keyTable->addColumn("bar", "integer");
|
||||
$keyTable->addColumn("baz", "string");
|
||||
$keyTable->setPrimaryKey(array("bar"));
|
||||
$keyTable->addUniqueIndex(array("baz"));
|
||||
|
||||
$oldTable = new Table("foo");
|
||||
$oldTable->addColumn("bar", "integer");
|
||||
$oldTable->addColumn("baz", "string");
|
||||
|
||||
$c = new \Doctrine\DBAL\Schema\Comparator;
|
||||
$diff = $c->diffTable($oldTable, $keyTable);
|
||||
|
||||
$sql = $this->_platform->getAlterTableSQL($diff);
|
||||
|
||||
$this->assertEquals(array(
|
||||
"ALTER TABLE foo ADD PRIMARY KEY (bar)",
|
||||
"CREATE UNIQUE INDEX UNIQ_8C73652178240498 ON foo (baz)",
|
||||
), $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQuery()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
|
||||
$this->assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryWithEmptyOffset()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
|
||||
$this->assertEquals('SELECT * FROM user LIMIT 10', $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-118
|
||||
*/
|
||||
public function testGetDateTimeTypeDeclarationSql()
|
||||
{
|
||||
$this->assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => false)));
|
||||
$this->assertEquals("TIMESTAMP", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => true)));
|
||||
$this->assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array()));
|
||||
}
|
||||
|
||||
public function getCreateTableColumnCommentsSQL()
|
||||
{
|
||||
return array("CREATE TABLE test (id INT NOT NULL COMMENT 'This is a comment', PRIMARY KEY(id)) ENGINE = InnoDB");
|
||||
}
|
||||
|
||||
public function getAlterTableColumnCommentsSQL()
|
||||
{
|
||||
return array("ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'");
|
||||
}
|
||||
|
||||
public function getCreateTableColumnTypeCommentsSQL()
|
||||
{
|
||||
return array("CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) ENGINE = InnoDB");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-237
|
||||
*/
|
||||
public function testChangeIndexWithForeignKeys()
|
||||
{
|
||||
$index = new Index("idx", array("col"), false);
|
||||
$unique = new Index("uniq", array("col"), true);
|
||||
|
||||
$diff = new TableDiff("test", array(), array(), array(), array($unique), array(), array($index));
|
||||
$sql = $this->_platform->getAlterTableSQL($diff);
|
||||
$this->assertEquals(array("ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)"), $sql);
|
||||
|
||||
$diff = new TableDiff("test", array(), array(), array(), array($index), array(), array($unique));
|
||||
$sql = $this->_platform->getAlterTableSQL($diff);
|
||||
$this->assertEquals(array("ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)"), $sql);
|
||||
}
|
||||
}
|
227
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
vendored
Normal file
227
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
vendored
Normal file
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Platforms;
|
||||
|
||||
use Doctrine\DBAL\Platforms\OraclePlatform;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class OraclePlatformTest extends AbstractPlatformTestCase
|
||||
{
|
||||
public function createPlatform()
|
||||
{
|
||||
return new OraclePlatform;
|
||||
}
|
||||
|
||||
public function getGenerateTableSql()
|
||||
{
|
||||
return 'CREATE TABLE test (id NUMBER(10) NOT NULL, test VARCHAR2(255) DEFAULT NULL, PRIMARY KEY(id))';
|
||||
}
|
||||
|
||||
public function getGenerateTableWithMultiColumnUniqueIndexSql()
|
||||
{
|
||||
return array(
|
||||
'CREATE TABLE test (foo VARCHAR2(255) DEFAULT NULL, bar VARCHAR2(255) DEFAULT NULL)',
|
||||
'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)',
|
||||
);
|
||||
}
|
||||
|
||||
public function getGenerateAlterTableSql()
|
||||
{
|
||||
return array(
|
||||
'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL)',
|
||||
"ALTER TABLE mytable MODIFY (baz VARCHAR2(255) DEFAULT 'def' NOT NULL, bloo NUMBER(1) DEFAULT '0' NOT NULL)",
|
||||
"ALTER TABLE mytable DROP (foo)",
|
||||
"ALTER TABLE mytable RENAME TO userlist",
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function testRLike()
|
||||
{
|
||||
$this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
|
||||
}
|
||||
|
||||
public function testGeneratesSqlSnippets()
|
||||
{
|
||||
$this->assertEquals('"', $this->_platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct');
|
||||
$this->assertEquals('column1 || column2 || column3', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct');
|
||||
}
|
||||
|
||||
public function testGeneratesTransactionsCommands()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'SET TRANSACTION ISOLATION LEVEL READ COMMITTED',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function testShowDatabasesThrowsException()
|
||||
{
|
||||
$this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSQL());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function testCreateDatabaseThrowsException()
|
||||
{
|
||||
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
|
||||
}
|
||||
|
||||
public function testDropDatabaseThrowsException()
|
||||
{
|
||||
$this->assertEquals('DROP USER foobar CASCADE', $this->_platform->getDropDatabaseSQL('foobar'));
|
||||
}
|
||||
|
||||
public function testDropTable()
|
||||
{
|
||||
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
|
||||
}
|
||||
|
||||
public function testGeneratesTypeDeclarationForIntegers()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'NUMBER(10)',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(array())
|
||||
);
|
||||
$this->assertEquals(
|
||||
'NUMBER(10)',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
|
||||
));
|
||||
$this->assertEquals(
|
||||
'NUMBER(10)',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(
|
||||
array('autoincrement' => true, 'primary' => true)
|
||||
));
|
||||
}
|
||||
|
||||
public function testGeneratesTypeDeclarationsForStrings()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'CHAR(10)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(
|
||||
array('length' => 10, 'fixed' => true)
|
||||
));
|
||||
$this->assertEquals(
|
||||
'VARCHAR2(50)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
|
||||
'Variable string declaration is not correct'
|
||||
);
|
||||
$this->assertEquals(
|
||||
'VARCHAR2(255)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(array()),
|
||||
'Long string declaration is not correct'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPrefersIdentityColumns()
|
||||
{
|
||||
$this->assertFalse($this->_platform->prefersIdentityColumns());
|
||||
}
|
||||
|
||||
public function testSupportsIdentityColumns()
|
||||
{
|
||||
$this->assertFalse($this->_platform->supportsIdentityColumns());
|
||||
}
|
||||
|
||||
public function testSupportsSavePoints()
|
||||
{
|
||||
$this->assertTrue($this->_platform->supportsSavepoints());
|
||||
}
|
||||
|
||||
public function getGenerateIndexSql()
|
||||
{
|
||||
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
|
||||
}
|
||||
|
||||
public function getGenerateUniqueIndexSql()
|
||||
{
|
||||
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
|
||||
}
|
||||
|
||||
public function getGenerateForeignKeySql()
|
||||
{
|
||||
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
|
||||
}
|
||||
|
||||
public function testModifyLimitQuery()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
|
||||
$this->assertEquals('SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10', $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryWithEmptyOffset()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
|
||||
$this->assertEquals('SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10', $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryWithAscOrderBy()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username ASC', 10);
|
||||
$this->assertEquals('SELECT a.* FROM (SELECT * FROM user ORDER BY username ASC) a WHERE ROWNUM <= 10', $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryWithDescOrderBy()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10);
|
||||
$this->assertEquals('SELECT a.* FROM (SELECT * FROM user ORDER BY username DESC) a WHERE ROWNUM <= 10', $sql);
|
||||
}
|
||||
|
||||
public function getCreateTableColumnCommentsSQL()
|
||||
{
|
||||
return array(
|
||||
"CREATE TABLE test (id NUMBER(10) NOT NULL, PRIMARY KEY(id))",
|
||||
"COMMENT ON COLUMN test.id IS 'This is a comment'",
|
||||
);
|
||||
}
|
||||
|
||||
public function getCreateTableColumnTypeCommentsSQL()
|
||||
{
|
||||
return array(
|
||||
"CREATE TABLE test (id NUMBER(10) NOT NULL, data CLOB NOT NULL, PRIMARY KEY(id))",
|
||||
"COMMENT ON COLUMN test.data IS '(DC2Type:array)'"
|
||||
);
|
||||
}
|
||||
|
||||
public function getAlterTableColumnCommentsSQL()
|
||||
{
|
||||
return array(
|
||||
"ALTER TABLE mytable ADD (quota NUMBER(10) NOT NULL)",
|
||||
"ALTER TABLE mytable MODIFY (baz VARCHAR2(255) NOT NULL)",
|
||||
"COMMENT ON COLUMN mytable.quota IS 'A comment'",
|
||||
"COMMENT ON COLUMN mytable.baz IS 'B comment'",
|
||||
);
|
||||
}
|
||||
|
||||
public function getBitAndComparisonExpressionSql($value1, $value2)
|
||||
{
|
||||
return 'BITAND('.$value1 . ', ' . $value2 . ')';
|
||||
}
|
||||
|
||||
public function getBitOrComparisonExpressionSql($value1, $value2)
|
||||
{
|
||||
return '(' . $value1 . '-' .
|
||||
$this->getBitAndComparisonExpressionSql($value1, $value2)
|
||||
. '+' . $value2 . ')';
|
||||
}
|
||||
}
|
230
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
vendored
Normal file
230
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
vendored
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Platforms;
|
||||
|
||||
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class PostgreSqlPlatformTest extends AbstractPlatformTestCase
|
||||
{
|
||||
public function createPlatform()
|
||||
{
|
||||
return new PostgreSqlPlatform;
|
||||
}
|
||||
|
||||
public function getGenerateTableSql()
|
||||
{
|
||||
return 'CREATE TABLE test (id SERIAL NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))';
|
||||
}
|
||||
|
||||
public function getGenerateTableWithMultiColumnUniqueIndexSql()
|
||||
{
|
||||
return array(
|
||||
'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)',
|
||||
'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)'
|
||||
);
|
||||
}
|
||||
|
||||
public function getGenerateAlterTableSql()
|
||||
{
|
||||
return array(
|
||||
'ALTER TABLE mytable ADD quota INT DEFAULT NULL',
|
||||
'ALTER TABLE mytable DROP foo',
|
||||
'ALTER TABLE mytable ALTER bar TYPE VARCHAR(255)',
|
||||
"ALTER TABLE mytable ALTER bar SET DEFAULT 'def'",
|
||||
'ALTER TABLE mytable ALTER bar SET NOT NULL',
|
||||
'ALTER TABLE mytable ALTER bloo TYPE BOOLEAN',
|
||||
"ALTER TABLE mytable ALTER bloo SET DEFAULT 'false'",
|
||||
'ALTER TABLE mytable ALTER bloo SET NOT NULL',
|
||||
'ALTER TABLE mytable RENAME TO userlist',
|
||||
);
|
||||
}
|
||||
|
||||
public function getGenerateIndexSql()
|
||||
{
|
||||
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
|
||||
}
|
||||
|
||||
public function getGenerateForeignKeySql()
|
||||
{
|
||||
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE';
|
||||
}
|
||||
|
||||
public function testGeneratesForeignKeySqlForNonStandardOptions()
|
||||
{
|
||||
$foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(
|
||||
array('foreign_id'), 'my_table', array('id'), 'my_fk', array('onDelete' => 'CASCADE')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE",
|
||||
$this->_platform->getForeignKeyDeclarationSQL($foreignKey)
|
||||
);
|
||||
}
|
||||
|
||||
public function testGeneratesSqlSnippets()
|
||||
{
|
||||
$this->assertEquals('SIMILAR TO', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
|
||||
$this->assertEquals('"', $this->_platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct');
|
||||
$this->assertEquals('column1 || column2 || column3', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct');
|
||||
$this->assertEquals('SUBSTR(column, 5)', $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');
|
||||
}
|
||||
|
||||
public function testGeneratesTransactionCommands()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL REPEATABLE READ',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
|
||||
);
|
||||
}
|
||||
|
||||
public function testGeneratesDDLSnippets()
|
||||
{
|
||||
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
|
||||
$this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar'));
|
||||
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
|
||||
}
|
||||
|
||||
public function testGenerateTableWithAutoincrement()
|
||||
{
|
||||
$table = new \Doctrine\DBAL\Schema\Table('autoinc_table');
|
||||
$column = $table->addColumn('id', 'integer');
|
||||
$column->setAutoincrement(true);
|
||||
|
||||
$this->assertEquals(array('CREATE TABLE autoinc_table (id SERIAL NOT NULL)'), $this->_platform->getCreateTableSQL($table));
|
||||
}
|
||||
|
||||
public function testGeneratesTypeDeclarationForIntegers()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'INT',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(array())
|
||||
);
|
||||
$this->assertEquals(
|
||||
'SERIAL',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
|
||||
));
|
||||
$this->assertEquals(
|
||||
'SERIAL',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(
|
||||
array('autoincrement' => true, 'primary' => true)
|
||||
));
|
||||
}
|
||||
|
||||
public function testGeneratesTypeDeclarationForStrings()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'CHAR(10)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(
|
||||
array('length' => 10, 'fixed' => true))
|
||||
);
|
||||
$this->assertEquals(
|
||||
'VARCHAR(50)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
|
||||
'Variable string declaration is not correct'
|
||||
);
|
||||
$this->assertEquals(
|
||||
'VARCHAR(255)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(array()),
|
||||
'Long string declaration is not correct'
|
||||
);
|
||||
}
|
||||
|
||||
public function getGenerateUniqueIndexSql()
|
||||
{
|
||||
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
|
||||
}
|
||||
|
||||
public function testGeneratesSequenceSqlCommands()
|
||||
{
|
||||
$sequence = new \Doctrine\DBAL\Schema\Sequence('myseq', 20, 1);
|
||||
$this->assertEquals(
|
||||
'CREATE SEQUENCE myseq INCREMENT BY 20 MINVALUE 1 START 1',
|
||||
$this->_platform->getCreateSequenceSQL($sequence)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'DROP SEQUENCE myseq',
|
||||
$this->_platform->getDropSequenceSQL('myseq')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"SELECT NEXTVAL('myseq')",
|
||||
$this->_platform->getSequenceNextValSQL('myseq')
|
||||
);
|
||||
}
|
||||
|
||||
public function testDoesNotPreferIdentityColumns()
|
||||
{
|
||||
$this->assertFalse($this->_platform->prefersIdentityColumns());
|
||||
}
|
||||
|
||||
public function testPrefersSequences()
|
||||
{
|
||||
$this->assertTrue($this->_platform->prefersSequences());
|
||||
}
|
||||
|
||||
public function testSupportsIdentityColumns()
|
||||
{
|
||||
$this->assertTrue($this->_platform->supportsIdentityColumns());
|
||||
}
|
||||
|
||||
public function testSupportsSavePoints()
|
||||
{
|
||||
$this->assertTrue($this->_platform->supportsSavepoints());
|
||||
}
|
||||
|
||||
public function testSupportsSequences()
|
||||
{
|
||||
$this->assertTrue($this->_platform->supportsSequences());
|
||||
}
|
||||
|
||||
public function testModifyLimitQuery()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
|
||||
$this->assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryWithEmptyOffset()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
|
||||
$this->assertEquals('SELECT * FROM user LIMIT 10', $sql);
|
||||
}
|
||||
|
||||
public function getCreateTableColumnCommentsSQL()
|
||||
{
|
||||
return array(
|
||||
"CREATE TABLE test (id INT NOT NULL, PRIMARY KEY(id))",
|
||||
"COMMENT ON COLUMN test.id IS 'This is a comment'",
|
||||
);
|
||||
}
|
||||
|
||||
public function getAlterTableColumnCommentsSQL()
|
||||
{
|
||||
return array(
|
||||
"ALTER TABLE mytable ADD quota INT NOT NULL",
|
||||
"COMMENT ON COLUMN mytable.quota IS 'A comment'",
|
||||
"COMMENT ON COLUMN mytable.baz IS 'B comment'",
|
||||
);
|
||||
}
|
||||
|
||||
public function getCreateTableColumnTypeCommentsSQL()
|
||||
{
|
||||
return array(
|
||||
"CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))",
|
||||
"COMMENT ON COLUMN test.data IS '(DC2Type:array)'"
|
||||
);
|
||||
}
|
||||
}
|
47
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php
vendored
Normal file
47
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Platforms;
|
||||
|
||||
use Doctrine\DBAL\Platforms\Keywords\ReservedKeywordsValidator;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
class ReservedKeywordsValidatorTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
/**
|
||||
* @var ReservedKeywordsValidator
|
||||
*/
|
||||
private $validator;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->validator = new ReservedKeywordsValidator(array(
|
||||
new \Doctrine\DBAL\Platforms\Keywords\MySQLKeywords()
|
||||
));
|
||||
}
|
||||
|
||||
public function testReservedTableName()
|
||||
{
|
||||
$table = new Table("TABLE");
|
||||
$this->validator->acceptTable($table);
|
||||
|
||||
$this->assertEquals(
|
||||
array('Table TABLE keyword violations: MySQL'),
|
||||
$this->validator->getViolations()
|
||||
);
|
||||
}
|
||||
|
||||
public function testReservedColumnName()
|
||||
{
|
||||
$table = new Table("TABLE");
|
||||
$column = $table->addColumn('table', 'string');
|
||||
|
||||
$this->validator->acceptColumn($table, $column);
|
||||
|
||||
$this->assertEquals(
|
||||
array('Table TABLE column table keyword violations: MySQL'),
|
||||
$this->validator->getViolations()
|
||||
);
|
||||
}
|
||||
}
|
191
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php
vendored
Normal file
191
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Platforms;
|
||||
|
||||
use Doctrine\DBAL\Platforms\SQLServer2008Platform;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
class SQLServerPlatformTest extends AbstractPlatformTestCase
|
||||
{
|
||||
public function createPlatform()
|
||||
{
|
||||
return new SQLServer2008Platform;
|
||||
}
|
||||
|
||||
public function getGenerateTableSql()
|
||||
{
|
||||
return 'CREATE TABLE test (id INT IDENTITY NOT NULL, test NVARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))';
|
||||
}
|
||||
|
||||
public function getGenerateTableWithMultiColumnUniqueIndexSql()
|
||||
{
|
||||
return array(
|
||||
'CREATE TABLE test (foo NVARCHAR(255) DEFAULT NULL, bar NVARCHAR(255) DEFAULT NULL)',
|
||||
'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar) WHERE foo IS NOT NULL AND bar IS NOT NULL'
|
||||
);
|
||||
}
|
||||
|
||||
public function getGenerateAlterTableSql()
|
||||
{
|
||||
return array(
|
||||
'ALTER TABLE mytable RENAME TO userlist',
|
||||
'ALTER TABLE mytable ADD quota INT DEFAULT NULL',
|
||||
'ALTER TABLE mytable DROP COLUMN foo',
|
||||
'ALTER TABLE mytable ALTER COLUMN baz NVARCHAR(255) DEFAULT \'def\' NOT NULL',
|
||||
'ALTER TABLE mytable ALTER COLUMN bloo BIT DEFAULT \'0\' NOT NULL',
|
||||
);
|
||||
}
|
||||
|
||||
public function testGeneratesSqlSnippets()
|
||||
{
|
||||
$this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
|
||||
$this->assertEquals('"', $this->_platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct');
|
||||
$this->assertEquals('(column1 + column2 + column3)', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct');
|
||||
}
|
||||
|
||||
public function testGeneratesTransactionsCommands()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'SET TRANSACTION ISOLATION LEVEL READ COMMITTED',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'SET TRANSACTION ISOLATION LEVEL REPEATABLE READ',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
|
||||
);
|
||||
}
|
||||
|
||||
public function testGeneratesDDLSnippets()
|
||||
{
|
||||
$dropDatabaseExpectation = 'DROP DATABASE foobar';
|
||||
|
||||
$this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSQL());
|
||||
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
|
||||
$this->assertEquals($dropDatabaseExpectation, $this->_platform->getDropDatabaseSQL('foobar'));
|
||||
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
|
||||
}
|
||||
|
||||
public function testGeneratesTypeDeclarationForIntegers()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'INT',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(array())
|
||||
);
|
||||
$this->assertEquals(
|
||||
'INT IDENTITY',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
|
||||
));
|
||||
$this->assertEquals(
|
||||
'INT IDENTITY',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(
|
||||
array('autoincrement' => true, 'primary' => true)
|
||||
));
|
||||
}
|
||||
|
||||
public function testGeneratesTypeDeclarationsForStrings()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'NCHAR(10)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(
|
||||
array('length' => 10, 'fixed' => true)
|
||||
));
|
||||
$this->assertEquals(
|
||||
'NVARCHAR(50)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
|
||||
'Variable string declaration is not correct'
|
||||
);
|
||||
$this->assertEquals(
|
||||
'NVARCHAR(255)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(array()),
|
||||
'Long string declaration is not correct'
|
||||
);
|
||||
}
|
||||
|
||||
public function testPrefersIdentityColumns()
|
||||
{
|
||||
$this->assertTrue($this->_platform->prefersIdentityColumns());
|
||||
}
|
||||
|
||||
public function testSupportsIdentityColumns()
|
||||
{
|
||||
$this->assertTrue($this->_platform->supportsIdentityColumns());
|
||||
}
|
||||
|
||||
public function testDoesNotSupportSavePoints()
|
||||
{
|
||||
$this->assertTrue($this->_platform->supportsSavepoints());
|
||||
}
|
||||
|
||||
public function getGenerateIndexSql()
|
||||
{
|
||||
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
|
||||
}
|
||||
|
||||
public function getGenerateUniqueIndexSql()
|
||||
{
|
||||
return 'CREATE UNIQUE INDEX index_name ON test (test, test2) WHERE test IS NOT NULL AND test2 IS NOT NULL';
|
||||
}
|
||||
|
||||
public function getGenerateForeignKeySql()
|
||||
{
|
||||
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
|
||||
}
|
||||
|
||||
public function testModifyLimitQuery()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
|
||||
$this->assertEquals('SELECT TOP 10 * FROM user', $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryWithEmptyOffset()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
|
||||
$this->assertEquals('SELECT TOP 10 * FROM user', $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryWithOffset()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10, 5);
|
||||
$this->assertEquals('SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY username DESC) AS "doctrine_rownum", * FROM user) AS doctrine_tbl WHERE "doctrine_rownum" BETWEEN 6 AND 15', $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryWithAscOrderBy()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username ASC', 10);
|
||||
$this->assertEquals('SELECT TOP 10 * FROM user ORDER BY username ASC', $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryWithDescOrderBy()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10);
|
||||
$this->assertEquals('SELECT TOP 10 * FROM user ORDER BY username DESC', $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1360
|
||||
*/
|
||||
public function testQuoteIdentifier()
|
||||
{
|
||||
$this->assertEquals('[fo][o]', $this->_platform->quoteIdentifier('fo]o'));
|
||||
$this->assertEquals('[test]', $this->_platform->quoteIdentifier('test'));
|
||||
$this->assertEquals('[test].[test]', $this->_platform->quoteIdentifier('test.test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1360
|
||||
*/
|
||||
public function testQuoteSingleIdentifier()
|
||||
{
|
||||
$this->assertEquals('[fo][o]', $this->_platform->quoteSingleIdentifier('fo]o'));
|
||||
$this->assertEquals('[test]', $this->_platform->quoteSingleIdentifier('test'));
|
||||
$this->assertEquals('[test.test]', $this->_platform->quoteSingleIdentifier('test.test'));
|
||||
}
|
||||
}
|
134
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
vendored
Normal file
134
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Platforms;
|
||||
|
||||
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class SqlitePlatformTest extends AbstractPlatformTestCase
|
||||
{
|
||||
public function createPlatform()
|
||||
{
|
||||
return new SqlitePlatform;
|
||||
}
|
||||
|
||||
public function getGenerateTableSql()
|
||||
{
|
||||
return 'CREATE TABLE test (id INTEGER NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY("id"))';
|
||||
}
|
||||
|
||||
public function getGenerateTableWithMultiColumnUniqueIndexSql()
|
||||
{
|
||||
return array(
|
||||
'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)',
|
||||
'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)',
|
||||
);
|
||||
}
|
||||
|
||||
public function testGeneratesSqlSnippets()
|
||||
{
|
||||
$this->assertEquals('RLIKE', $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');
|
||||
}
|
||||
|
||||
public function testGeneratesTransactionCommands()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'PRAGMA read_uncommitted = 0',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'PRAGMA read_uncommitted = 1',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'PRAGMA read_uncommitted = 1',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'PRAGMA read_uncommitted = 1',
|
||||
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
|
||||
);
|
||||
}
|
||||
|
||||
public function testPrefersIdentityColumns()
|
||||
{
|
||||
$this->assertTrue($this->_platform->prefersIdentityColumns());
|
||||
}
|
||||
|
||||
public function testGeneratesTypeDeclarationForIntegers()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'INTEGER',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(array())
|
||||
);
|
||||
$this->assertEquals(
|
||||
'INTEGER',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true))
|
||||
);
|
||||
$this->assertEquals(
|
||||
'INTEGER',
|
||||
$this->_platform->getIntegerTypeDeclarationSQL(
|
||||
array('autoincrement' => true, 'primary' => true))
|
||||
);
|
||||
}
|
||||
|
||||
public function testGeneratesTypeDeclarationForStrings()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'CHAR(10)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(
|
||||
array('length' => 10, 'fixed' => true))
|
||||
);
|
||||
$this->assertEquals(
|
||||
'VARCHAR(50)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
|
||||
'Variable string declaration is not correct'
|
||||
);
|
||||
$this->assertEquals(
|
||||
'VARCHAR(255)',
|
||||
$this->_platform->getVarcharTypeDeclarationSQL(array()),
|
||||
'Long string declaration is not correct'
|
||||
);
|
||||
}
|
||||
|
||||
public function getGenerateIndexSql()
|
||||
{
|
||||
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
|
||||
}
|
||||
|
||||
public function getGenerateUniqueIndexSql()
|
||||
{
|
||||
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
|
||||
}
|
||||
|
||||
public function getGenerateForeignKeySql()
|
||||
{
|
||||
$this->markTestSkipped('SQLite does not support ForeignKeys.');
|
||||
}
|
||||
|
||||
public function testModifyLimitQuery()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
|
||||
$this->assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryWithEmptyOffset()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
|
||||
$this->assertEquals('SELECT * FROM user LIMIT 10', $sql);
|
||||
}
|
||||
|
||||
public function getGenerateAlterTableSql()
|
||||
{
|
||||
$this->markTestSkipped('SQlite does not support ALTER Table.');
|
||||
}
|
||||
|
||||
public function testGetAlterTableSqlDispatchEvent()
|
||||
{
|
||||
$this->markTestSkipped('SQlite does not support ALTER Table.');
|
||||
}
|
||||
}
|
82
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php
vendored
Normal file
82
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Query\Expression;
|
||||
|
||||
use Doctrine\DBAL\Query\Expression\CompositeExpression;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DBAL-12
|
||||
*/
|
||||
class CompositeExpressionTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
public function testCount()
|
||||
{
|
||||
$expr = new CompositeExpression(CompositeExpression::TYPE_OR, array('u.group_id = 1'));
|
||||
|
||||
$this->assertEquals(1, count($expr));
|
||||
|
||||
$expr->add('u.group_id = 2');
|
||||
|
||||
$this->assertEquals(2, count($expr));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDataForConvertToString
|
||||
*/
|
||||
public function testCompositeUsageAndGeneration($type, $parts, $expects)
|
||||
{
|
||||
$expr = new CompositeExpression($type, $parts);
|
||||
|
||||
$this->assertEquals($expects, (string) $expr);
|
||||
}
|
||||
|
||||
public function provideDataForConvertToString()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
CompositeExpression::TYPE_AND,
|
||||
array('u.user = 1'),
|
||||
'u.user = 1'
|
||||
),
|
||||
array(
|
||||
CompositeExpression::TYPE_AND,
|
||||
array('u.user = 1', 'u.group_id = 1'),
|
||||
'(u.user = 1) AND (u.group_id = 1)'
|
||||
),
|
||||
array(
|
||||
CompositeExpression::TYPE_OR,
|
||||
array('u.user = 1'),
|
||||
'u.user = 1'
|
||||
),
|
||||
array(
|
||||
CompositeExpression::TYPE_OR,
|
||||
array('u.group_id = 1', 'u.group_id = 2'),
|
||||
'(u.group_id = 1) OR (u.group_id = 2)'
|
||||
),
|
||||
array(
|
||||
CompositeExpression::TYPE_AND,
|
||||
array(
|
||||
'u.user = 1',
|
||||
new CompositeExpression(
|
||||
CompositeExpression::TYPE_OR,
|
||||
array('u.group_id = 1', 'u.group_id = 2')
|
||||
)
|
||||
),
|
||||
'(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))'
|
||||
),
|
||||
array(
|
||||
CompositeExpression::TYPE_OR,
|
||||
array(
|
||||
'u.group_id = 1',
|
||||
new CompositeExpression(
|
||||
CompositeExpression::TYPE_AND,
|
||||
array('u.user = 1', 'u.group_id = 2')
|
||||
)
|
||||
),
|
||||
'(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
201
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php
vendored
Normal file
201
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Query\Expression;
|
||||
|
||||
use Doctrine\DBAL\Query\Expression\ExpressionBuilder,
|
||||
Doctrine\DBAL\Query\Expression\CompositeExpression;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DBAL-12
|
||||
*/
|
||||
class ExpressionBuilderTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected $expr;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$conn = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
|
||||
|
||||
$this->expr = new ExpressionBuilder($conn);
|
||||
|
||||
$conn->expects($this->any())
|
||||
->method('getExpressionBuilder')
|
||||
->will($this->returnValue($this->expr));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDataForAndX
|
||||
*/
|
||||
public function testAndX($parts, $expected)
|
||||
{
|
||||
$composite = $this->expr->andX();
|
||||
|
||||
foreach ($parts as $part) {
|
||||
$composite->add($part);
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, (string) $composite);
|
||||
}
|
||||
|
||||
public function provideDataForAndX()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('u.user = 1'),
|
||||
'u.user = 1'
|
||||
),
|
||||
array(
|
||||
array('u.user = 1', 'u.group_id = 1'),
|
||||
'(u.user = 1) AND (u.group_id = 1)'
|
||||
),
|
||||
array(
|
||||
array('u.user = 1'),
|
||||
'u.user = 1'
|
||||
),
|
||||
array(
|
||||
array('u.group_id = 1', 'u.group_id = 2'),
|
||||
'(u.group_id = 1) AND (u.group_id = 2)'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'u.user = 1',
|
||||
new CompositeExpression(
|
||||
CompositeExpression::TYPE_OR,
|
||||
array('u.group_id = 1', 'u.group_id = 2')
|
||||
)
|
||||
),
|
||||
'(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'u.group_id = 1',
|
||||
new CompositeExpression(
|
||||
CompositeExpression::TYPE_AND,
|
||||
array('u.user = 1', 'u.group_id = 2')
|
||||
)
|
||||
),
|
||||
'(u.group_id = 1) AND ((u.user = 1) AND (u.group_id = 2))'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDataForOrX
|
||||
*/
|
||||
public function testOrX($parts, $expected)
|
||||
{
|
||||
$composite = $this->expr->orX();
|
||||
|
||||
foreach ($parts as $part) {
|
||||
$composite->add($part);
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, (string) $composite);
|
||||
}
|
||||
|
||||
public function provideDataForOrX()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array('u.user = 1'),
|
||||
'u.user = 1'
|
||||
),
|
||||
array(
|
||||
array('u.user = 1', 'u.group_id = 1'),
|
||||
'(u.user = 1) OR (u.group_id = 1)'
|
||||
),
|
||||
array(
|
||||
array('u.user = 1'),
|
||||
'u.user = 1'
|
||||
),
|
||||
array(
|
||||
array('u.group_id = 1', 'u.group_id = 2'),
|
||||
'(u.group_id = 1) OR (u.group_id = 2)'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'u.user = 1',
|
||||
new CompositeExpression(
|
||||
CompositeExpression::TYPE_OR,
|
||||
array('u.group_id = 1', 'u.group_id = 2')
|
||||
)
|
||||
),
|
||||
'(u.user = 1) OR ((u.group_id = 1) OR (u.group_id = 2))'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'u.group_id = 1',
|
||||
new CompositeExpression(
|
||||
CompositeExpression::TYPE_AND,
|
||||
array('u.user = 1', 'u.group_id = 2')
|
||||
)
|
||||
),
|
||||
'(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideDataForComparison
|
||||
*/
|
||||
public function testComparison($leftExpr, $operator, $rightExpr, $expected)
|
||||
{
|
||||
$part = $this->expr->comparison($leftExpr, $operator, $rightExpr);
|
||||
|
||||
$this->assertEquals($expected, (string) $part);
|
||||
}
|
||||
|
||||
public function provideDataForComparison()
|
||||
{
|
||||
return array(
|
||||
array('u.user_id', ExpressionBuilder::EQ, '1', 'u.user_id = 1'),
|
||||
array('u.user_id', ExpressionBuilder::NEQ, '1', 'u.user_id <> 1'),
|
||||
array('u.salary', ExpressionBuilder::LT, '10000', 'u.salary < 10000'),
|
||||
array('u.salary', ExpressionBuilder::LTE, '10000', 'u.salary <= 10000'),
|
||||
array('u.salary', ExpressionBuilder::GT, '10000', 'u.salary > 10000'),
|
||||
array('u.salary', ExpressionBuilder::GTE, '10000', 'u.salary >= 10000'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testEq()
|
||||
{
|
||||
$this->assertEquals('u.user_id = 1', $this->expr->eq('u.user_id', '1'));
|
||||
}
|
||||
|
||||
public function testNeq()
|
||||
{
|
||||
$this->assertEquals('u.user_id <> 1', $this->expr->neq('u.user_id', '1'));
|
||||
}
|
||||
|
||||
public function testLt()
|
||||
{
|
||||
$this->assertEquals('u.salary < 10000', $this->expr->lt('u.salary', '10000'));
|
||||
}
|
||||
|
||||
public function testLte()
|
||||
{
|
||||
$this->assertEquals('u.salary <= 10000', $this->expr->lte('u.salary', '10000'));
|
||||
}
|
||||
|
||||
public function testGt()
|
||||
{
|
||||
$this->assertEquals('u.salary > 10000', $this->expr->gt('u.salary', '10000'));
|
||||
}
|
||||
|
||||
public function testGte()
|
||||
{
|
||||
$this->assertEquals('u.salary >= 10000', $this->expr->gte('u.salary', '10000'));
|
||||
}
|
||||
|
||||
public function testIsNull()
|
||||
{
|
||||
$this->assertEquals('u.deleted IS NULL', $this->expr->isNull('u.deleted'));
|
||||
}
|
||||
|
||||
public function testIsNotNull()
|
||||
{
|
||||
$this->assertEquals('u.updated IS NOT NULL', $this->expr->isNotNull('u.updated'));
|
||||
}
|
||||
}
|
572
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
vendored
Normal file
572
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
vendored
Normal file
@@ -0,0 +1,572 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Query;
|
||||
|
||||
use Doctrine\DBAL\Query\Expression\ExpressionBuilder,
|
||||
Doctrine\DBAL\Query\QueryBuilder;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DBAL-12
|
||||
*/
|
||||
class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected $conn;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->conn = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
|
||||
|
||||
$expressionBuilder = new ExpressionBuilder($this->conn);
|
||||
|
||||
$this->conn->expects($this->any())
|
||||
->method('getExpressionBuilder')
|
||||
->will($this->returnValue($expressionBuilder));
|
||||
}
|
||||
|
||||
public function testSimpleSelect()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
|
||||
$qb->select('u.id')
|
||||
->from('users', 'u');
|
||||
|
||||
$this->assertEquals('SELECT u.id FROM users u', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectWithSimpleWhere()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.id')
|
||||
->from('users', 'u')
|
||||
->where($expr->andX($expr->eq('u.nickname', '?')));
|
||||
|
||||
$this->assertEquals("SELECT u.id FROM users u WHERE u.nickname = ?", (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectWithLeftJoin()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->leftJoin('u', 'phones', 'p', $expr->eq('p.user_id', 'u.id'));
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u LEFT JOIN phones p ON p.user_id = u.id', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectWithJoin()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->Join('u', 'phones', 'p', $expr->eq('p.user_id', 'u.id'));
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u INNER JOIN phones p ON p.user_id = u.id', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectWithInnerJoin()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->innerJoin('u', 'phones', 'p', $expr->eq('p.user_id', 'u.id'));
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u INNER JOIN phones p ON p.user_id = u.id', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectWithRightJoin()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->rightJoin('u', 'phones', 'p', $expr->eq('p.user_id', 'u.id'));
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u RIGHT JOIN phones p ON p.user_id = u.id', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectWithAndWhereConditions()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->where('u.username = ?')
|
||||
->andWhere('u.name = ?');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u WHERE (u.username = ?) AND (u.name = ?)', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectWithOrWhereConditions()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->where('u.username = ?')
|
||||
->orWhere('u.name = ?');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u WHERE (u.username = ?) OR (u.name = ?)', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectWithOrOrWhereConditions()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->orWhere('u.username = ?')
|
||||
->orWhere('u.name = ?');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u WHERE (u.username = ?) OR (u.name = ?)', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectWithAndOrWhereConditions()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->where('u.username = ?')
|
||||
->andWhere('u.username = ?')
|
||||
->orWhere('u.name = ?')
|
||||
->andWhere('u.name = ?');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u WHERE (((u.username = ?) AND (u.username = ?)) OR (u.name = ?)) AND (u.name = ?)', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectGroupBy()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->groupBy('u.id');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectEmptyGroupBy()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->groupBy(array())
|
||||
->from('users', 'u');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectEmptyAddGroupBy()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->addGroupBy(array())
|
||||
->from('users', 'u');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectAddGroupBy()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->groupBy('u.id')
|
||||
->addGroupBy('u.foo');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id, u.foo', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectAddGroupBys()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->groupBy('u.id')
|
||||
->addGroupBy('u.foo', 'u.bar');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id, u.foo, u.bar', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectHaving()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->groupBy('u.id')
|
||||
->having('u.name = ?');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id HAVING u.name = ?', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectAndHaving()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->groupBy('u.id')
|
||||
->andHaving('u.name = ?');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id HAVING u.name = ?', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectHavingAndHaving()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->groupBy('u.id')
|
||||
->having('u.name = ?')
|
||||
->andHaving('u.username = ?');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id HAVING (u.name = ?) AND (u.username = ?)', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectHavingOrHaving()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->groupBy('u.id')
|
||||
->having('u.name = ?')
|
||||
->orHaving('u.username = ?');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id HAVING (u.name = ?) OR (u.username = ?)', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectOrHavingOrHaving()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->groupBy('u.id')
|
||||
->orHaving('u.name = ?')
|
||||
->orHaving('u.username = ?');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id HAVING (u.name = ?) OR (u.username = ?)', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectHavingAndOrHaving()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->groupBy('u.id')
|
||||
->having('u.name = ?')
|
||||
->orHaving('u.username = ?')
|
||||
->andHaving('u.username = ?');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u GROUP BY u.id HAVING ((u.name = ?) OR (u.username = ?)) AND (u.username = ?)', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectOrderBy()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->orderBy('u.name');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u ORDER BY u.name ASC', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectAddOrderBy()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->orderBy('u.name')
|
||||
->addOrderBy('u.username', 'DESC');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u ORDER BY u.name ASC, u.username DESC', (string) $qb);
|
||||
}
|
||||
|
||||
public function testSelectAddAddOrderBy()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*', 'p.*')
|
||||
->from('users', 'u')
|
||||
->addOrderBy('u.name')
|
||||
->addOrderBy('u.username', 'DESC');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u ORDER BY u.name ASC, u.username DESC', (string) $qb);
|
||||
}
|
||||
|
||||
public function testEmptySelect()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$qb2 = $qb->select();
|
||||
|
||||
$this->assertSame($qb, $qb2);
|
||||
$this->assertEquals(QueryBuilder::SELECT, $qb->getType());
|
||||
}
|
||||
|
||||
public function testSelectAddSelect()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*')
|
||||
->addSelect('p.*')
|
||||
->from('users', 'u');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u', (string) $qb);
|
||||
}
|
||||
|
||||
public function testEmptyAddSelect()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$qb2 = $qb->addSelect();
|
||||
|
||||
$this->assertSame($qb, $qb2);
|
||||
$this->assertEquals(QueryBuilder::SELECT, $qb->getType());
|
||||
}
|
||||
|
||||
public function testSelectMultipleFrom()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$expr = $qb->expr();
|
||||
|
||||
$qb->select('u.*')
|
||||
->addSelect('p.*')
|
||||
->from('users', 'u')
|
||||
->from('phonenumbers', 'p');
|
||||
|
||||
$this->assertEquals('SELECT u.*, p.* FROM users u, phonenumbers p', (string) $qb);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$qb->update('users', 'u')
|
||||
->set('u.foo', '?')
|
||||
->set('u.bar', '?');
|
||||
|
||||
$this->assertEquals(QueryBuilder::UPDATE, $qb->getType());
|
||||
$this->assertEquals('UPDATE users u SET u.foo = ?, u.bar = ?', (string) $qb);
|
||||
}
|
||||
|
||||
public function testUpdateWithoutAlias()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$qb->update('users')
|
||||
->set('foo', '?')
|
||||
->set('bar', '?');
|
||||
|
||||
$this->assertEquals('UPDATE users SET foo = ?, bar = ?', (string) $qb);
|
||||
}
|
||||
|
||||
public function testUpdateWhere()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$qb->update('users', 'u')
|
||||
->set('u.foo', '?')
|
||||
->where('u.foo = ?');
|
||||
|
||||
$this->assertEquals('UPDATE users u SET u.foo = ? WHERE u.foo = ?', (string) $qb);
|
||||
}
|
||||
|
||||
public function testEmptyUpdate()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$qb2 = $qb->update();
|
||||
|
||||
$this->assertEquals(QueryBuilder::UPDATE, $qb->getType());
|
||||
$this->assertSame($qb2, $qb);
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$qb->delete('users', 'u');
|
||||
|
||||
$this->assertEquals(QueryBuilder::DELETE, $qb->getType());
|
||||
$this->assertEquals('DELETE FROM users u', (string) $qb);
|
||||
}
|
||||
|
||||
public function testDeleteWithoutAlias()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$qb->delete('users');
|
||||
|
||||
$this->assertEquals(QueryBuilder::DELETE, $qb->getType());
|
||||
$this->assertEquals('DELETE FROM users', (string) $qb);
|
||||
}
|
||||
|
||||
public function testDeleteWhere()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$qb->delete('users', 'u')
|
||||
->where('u.foo = ?');
|
||||
|
||||
$this->assertEquals('DELETE FROM users u WHERE u.foo = ?', (string) $qb);
|
||||
}
|
||||
|
||||
public function testEmptyDelete()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$qb2 = $qb->delete();
|
||||
|
||||
$this->assertEquals(QueryBuilder::DELETE, $qb->getType());
|
||||
$this->assertSame($qb2, $qb);
|
||||
}
|
||||
|
||||
public function testGetConnection()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$this->assertSame($this->conn, $qb->getConnection());
|
||||
}
|
||||
|
||||
public function testGetState()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
|
||||
$this->assertEquals(QueryBuilder::STATE_CLEAN, $qb->getState());
|
||||
|
||||
$qb->select('u.*')->from('users', 'u');
|
||||
|
||||
$this->assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState());
|
||||
|
||||
$sql1 = $qb->getSQL();
|
||||
|
||||
$this->assertEquals(QueryBuilder::STATE_CLEAN, $qb->getState());
|
||||
$this->assertEquals($sql1, $qb->getSQL());
|
||||
}
|
||||
|
||||
public function testSetMaxResults()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$qb->setMaxResults(10);
|
||||
|
||||
$this->assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState());
|
||||
$this->assertEQuals(10, $qb->getMaxResults());
|
||||
}
|
||||
|
||||
public function testSetFirstResult()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
$qb->setFirstResult(10);
|
||||
|
||||
$this->assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState());
|
||||
$this->assertEQuals(10, $qb->getFirstResult());
|
||||
}
|
||||
|
||||
public function testResetQueryPart()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
|
||||
$qb->select('u.*')->from('users', 'u')->where('u.name = ?');
|
||||
|
||||
$this->assertEquals('SELECT u.* FROM users u WHERE u.name = ?', (string)$qb);
|
||||
$qb->resetQueryPart('where');
|
||||
$this->assertEquals('SELECT u.* FROM users u', (string)$qb);
|
||||
}
|
||||
|
||||
public function testResetQueryParts()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
|
||||
$qb->select('u.*')->from('users', 'u')->where('u.name = ?')->orderBy('u.name');
|
||||
|
||||
$this->assertEquals('SELECT u.* FROM users u WHERE u.name = ? ORDER BY u.name ASC', (string)$qb);
|
||||
$qb->resetQueryParts(array('where', 'orderBy'));
|
||||
$this->assertEquals('SELECT u.* FROM users u', (string)$qb);
|
||||
}
|
||||
|
||||
public function testCreateNamedParameter()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
|
||||
$qb->select('u.*')->from('users', 'u')->where(
|
||||
$qb->expr()->eq('u.name', $qb->createNamedParameter(10, \PDO::PARAM_INT))
|
||||
);
|
||||
|
||||
$this->assertEquals('SELECT u.* FROM users u WHERE u.name = :dcValue1', (string)$qb);
|
||||
$this->assertEquals(10, $qb->getParameter('dcValue1'));
|
||||
}
|
||||
|
||||
public function testCreateNamedParameterCustomPlaceholder()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
|
||||
$qb->select('u.*')->from('users', 'u')->where(
|
||||
$qb->expr()->eq('u.name', $qb->createNamedParameter(10, \PDO::PARAM_INT, ':test'))
|
||||
);
|
||||
|
||||
$this->assertEquals('SELECT u.* FROM users u WHERE u.name = :test', (string)$qb);
|
||||
$this->assertEquals(10, $qb->getParameter('test'));
|
||||
}
|
||||
|
||||
public function testCreatePositionalParameter()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
|
||||
$qb->select('u.*')->from('users', 'u')->where(
|
||||
$qb->expr()->eq('u.name', $qb->createPositionalParameter(10, \PDO::PARAM_INT))
|
||||
);
|
||||
|
||||
$this->assertEquals('SELECT u.* FROM users u WHERE u.name = ?', (string)$qb);
|
||||
$this->assertEquals(10, $qb->getParameter(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-172
|
||||
*/
|
||||
public function testReferenceJoinFromJoin()
|
||||
{
|
||||
$qb = new QueryBuilder($this->conn);
|
||||
|
||||
$qb->select("l.id", "mdsh.xcode", "mdso.xcode")
|
||||
->from("location_tree", "l")
|
||||
->join("l", "location_tree_pos", "p", "l.id = p.tree_id")
|
||||
->rightJoin("l", "hotel", "h", "h.location_id = l.id")
|
||||
->leftJoin("l", "offer_location", "ol", "l.id=ol.location_id")
|
||||
->leftJoin("ol", "mds_offer", "mdso", "ol.offer_id = mdso.offer_id")
|
||||
->leftJoin("h", "mds_hotel", "mdsh", "h.id = mdsh.hotel_id")
|
||||
->where("p.parent_id IN (:ids)")
|
||||
->andWhere("(mdso.xcode IS NOT NULL OR mdsh.xcode IS NOT NULL)");
|
||||
|
||||
$this->setExpectedException('Doctrine\DBAL\Query\QueryException', "The given alias 'ol' is not part of any FROM clause table. The currently registered FROM-clause aliases are: l");
|
||||
$this->assertEquals('', $qb->getSQL());
|
||||
}
|
||||
}
|
214
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php
vendored
Normal file
214
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php
vendored
Normal file
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\SQLParserUtils;
|
||||
|
||||
require_once __DIR__ . '/../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DBAL-78
|
||||
* @group DDC-1372
|
||||
*/
|
||||
class SQLParserUtilsTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
static public function dataGetPlaceholderPositions()
|
||||
{
|
||||
return array(
|
||||
// none
|
||||
array('SELECT * FROM Foo', true, array()),
|
||||
array('SELECT * FROM Foo', false, array()),
|
||||
|
||||
// Positionals
|
||||
array('SELECT ?', true, array(7)),
|
||||
array('SELECT * FROM Foo WHERE bar IN (?, ?, ?)', true, array(32, 35, 38)),
|
||||
array('SELECT ? FROM ?', true, array(7, 14)),
|
||||
array('SELECT "?" FROM foo', true, array()),
|
||||
array("SELECT '?' FROM foo", true, array()),
|
||||
array('SELECT "?" FROM foo WHERE bar = ?', true, array(32)),
|
||||
array("SELECT '?' FROM foo WHERE bar = ?", true, array(32)),
|
||||
|
||||
// named
|
||||
array('SELECT :foo FROM :bar', false, array(7 => 'foo', 17 => 'bar')),
|
||||
array('SELECT * FROM Foo WHERE bar IN (:name1, :name2)', false, array(32 => 'name1', 40 => 'name2')),
|
||||
array('SELECT ":foo" FROM Foo WHERE bar IN (:name1, :name2)', false, array(37 => 'name1', 45 => 'name2')),
|
||||
array("SELECT ':foo' FROM Foo WHERE bar IN (:name1, :name2)", false, array(37 => 'name1', 45 => 'name2')),
|
||||
array('SELECT :foo_id', false, array(7 => 'foo_id')), // Ticket DBAL-231
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGetPlaceholderPositions
|
||||
* @param type $query
|
||||
* @param type $isPositional
|
||||
* @param type $expectedParamPos
|
||||
*/
|
||||
public function testGetPlaceholderPositions($query, $isPositional, $expectedParamPos)
|
||||
{
|
||||
$actualParamPos = SQLParserUtils::getPlaceholderPositions($query, $isPositional);
|
||||
$this->assertEquals($expectedParamPos, $actualParamPos);
|
||||
}
|
||||
|
||||
static public function dataExpandListParameters()
|
||||
{
|
||||
return array(
|
||||
// Positional: Very simple with one needle
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE foo IN (?)",
|
||||
array(array(1, 2, 3)),
|
||||
array(Connection::PARAM_INT_ARRAY),
|
||||
'SELECT * FROM Foo WHERE foo IN (?, ?, ?)',
|
||||
array(1, 2, 3),
|
||||
array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT)
|
||||
),
|
||||
// Positional: One non-list before d one after list-needle
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE foo = ? AND bar IN (?)",
|
||||
array("string", array(1, 2, 3)),
|
||||
array(\PDO::PARAM_STR, Connection::PARAM_INT_ARRAY),
|
||||
'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?)',
|
||||
array("string", 1, 2, 3),
|
||||
array(\PDO::PARAM_STR, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT)
|
||||
),
|
||||
// Positional: One non-list after list-needle
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE bar IN (?) AND baz = ?",
|
||||
array(array(1, 2, 3), "foo"),
|
||||
array(Connection::PARAM_INT_ARRAY, \PDO::PARAM_STR),
|
||||
'SELECT * FROM Foo WHERE bar IN (?, ?, ?) AND baz = ?',
|
||||
array(1, 2, 3, "foo"),
|
||||
array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR)
|
||||
),
|
||||
// Positional: One non-list before and one after list-needle
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ?",
|
||||
array(1, array(1, 2, 3), 4),
|
||||
array(\PDO::PARAM_INT, Connection::PARAM_INT_ARRAY, \PDO::PARAM_INT),
|
||||
'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ?',
|
||||
array(1, 1, 2, 3, 4),
|
||||
array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT)
|
||||
),
|
||||
// Positional: Two lists
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE foo IN (?, ?)",
|
||||
array(array(1, 2, 3), array(4, 5)),
|
||||
array(Connection::PARAM_INT_ARRAY, Connection::PARAM_INT_ARRAY),
|
||||
'SELECT * FROM Foo WHERE foo IN (?, ?, ?, ?, ?)',
|
||||
array(1, 2, 3, 4, 5),
|
||||
array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT)
|
||||
),
|
||||
// Named parameters : Very simple with param int
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE foo = :foo",
|
||||
array('foo'=>1),
|
||||
array('foo'=>\PDO::PARAM_INT),
|
||||
'SELECT * FROM Foo WHERE foo = ?',
|
||||
array(1),
|
||||
array(\PDO::PARAM_INT)
|
||||
),
|
||||
|
||||
// Named parameters : Very simple with param int and string
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE foo = :foo AND bar = :bar",
|
||||
array('bar'=>'Some String','foo'=>1),
|
||||
array('foo'=>\PDO::PARAM_INT,'bar'=>\PDO::PARAM_STR),
|
||||
'SELECT * FROM Foo WHERE foo = ? AND bar = ?',
|
||||
array(1,'Some String'),
|
||||
array(\PDO::PARAM_INT, \PDO::PARAM_STR)
|
||||
),
|
||||
|
||||
// Named parameters : Very simple with one needle
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE foo IN (:foo)",
|
||||
array('foo'=>array(1, 2, 3)),
|
||||
array('foo'=>Connection::PARAM_INT_ARRAY),
|
||||
'SELECT * FROM Foo WHERE foo IN (?, ?, ?)',
|
||||
array(1, 2, 3),
|
||||
array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT)
|
||||
),
|
||||
// Named parameters: One non-list before d one after list-needle
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar)",
|
||||
array('foo'=>"string", 'bar'=>array(1, 2, 3)),
|
||||
array('foo'=>\PDO::PARAM_STR, 'bar'=>Connection::PARAM_INT_ARRAY),
|
||||
'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?)',
|
||||
array("string", 1, 2, 3),
|
||||
array(\PDO::PARAM_STR, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT)
|
||||
),
|
||||
// Named parameters: One non-list after list-needle
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE bar IN (:bar) AND baz = :baz",
|
||||
array('bar'=>array(1, 2, 3), 'baz'=>"foo"),
|
||||
array('bar'=>Connection::PARAM_INT_ARRAY, 'baz'=>\PDO::PARAM_STR),
|
||||
'SELECT * FROM Foo WHERE bar IN (?, ?, ?) AND baz = ?',
|
||||
array(1, 2, 3, "foo"),
|
||||
array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR)
|
||||
),
|
||||
// Named parameters: One non-list before and one after list-needle
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar) AND baz = :baz",
|
||||
array('bar'=>array(1, 2, 3),'foo'=>1, 'baz'=>4),
|
||||
array('bar'=>Connection::PARAM_INT_ARRAY, 'foo'=>\PDO::PARAM_INT, 'baz'=>\PDO::PARAM_INT),
|
||||
'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ?',
|
||||
array(1, 1, 2, 3, 4),
|
||||
array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT)
|
||||
),
|
||||
// Named parameters: Two lists
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE foo IN (:a, :b)",
|
||||
array('b'=>array(4, 5),'a'=>array(1, 2, 3)),
|
||||
array('a'=>Connection::PARAM_INT_ARRAY, 'b'=>Connection::PARAM_INT_ARRAY),
|
||||
'SELECT * FROM Foo WHERE foo IN (?, ?, ?, ?, ?)',
|
||||
array(1, 2, 3, 4, 5),
|
||||
array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT)
|
||||
),
|
||||
// Named parameters : With the same name arg type string
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE foo <> :arg AND bar = :arg",
|
||||
array('arg'=>"Some String"),
|
||||
array('arg'=>\PDO::PARAM_STR),
|
||||
'SELECT * FROM Foo WHERE foo <> ? AND bar = ?',
|
||||
array("Some String","Some String"),
|
||||
array(\PDO::PARAM_STR,\PDO::PARAM_STR,)
|
||||
),
|
||||
// Named parameters : With the same name arg
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE foo IN (:arg) AND NOT bar IN (:arg)",
|
||||
array('arg'=>array(1, 2, 3)),
|
||||
array('arg'=>Connection::PARAM_INT_ARRAY),
|
||||
'SELECT * FROM Foo WHERE foo IN (?, ?, ?) AND NOT bar IN (?, ?, ?)',
|
||||
array(1, 2, 3, 1, 2, 3),
|
||||
array(\PDO::PARAM_INT,\PDO::PARAM_INT, \PDO::PARAM_INT,\PDO::PARAM_INT,\PDO::PARAM_INT, \PDO::PARAM_INT)
|
||||
),
|
||||
|
||||
// Named parameters : Same name, other name in between DBAL-299
|
||||
array(
|
||||
"SELECT * FROM Foo WHERE (:foo = 2) AND (:bar = 3) AND (:foo = 2)",
|
||||
array('foo'=>2,'bar'=>3),
|
||||
array('foo'=>\PDO::PARAM_INT,'bar'=>\PDO::PARAM_INT),
|
||||
'SELECT * FROM Foo WHERE (? = 2) AND (? = 3) AND (? = 2)',
|
||||
array(2, 3, 2),
|
||||
array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataExpandListParameters
|
||||
* @param type $q
|
||||
* @param type $p
|
||||
* @param type $t
|
||||
* @param type $expectedQuery
|
||||
* @param type $expectedParams
|
||||
* @param type $expectedTypes
|
||||
*/
|
||||
public function testExpandListParameters($q, $p, $t, $expectedQuery, $expectedParams, $expectedTypes)
|
||||
{
|
||||
list($query, $params, $types) = SQLParserUtils::expandListParameters($q, $p, $t);
|
||||
|
||||
$this->assertEquals($expectedQuery, $query, "Query was not rewritten correctly.");
|
||||
$this->assertEquals($expectedParams, $params, "Params dont match");
|
||||
$this->assertEquals($expectedTypes, $types, "Types dont match");
|
||||
}
|
||||
}
|
114
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php
vendored
Normal file
114
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Schema;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
class ColumnTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGet()
|
||||
{
|
||||
$column = $this->createColumn();
|
||||
|
||||
$this->assertEquals("foo", $column->getName());
|
||||
$this->assertSame(Type::getType('string'), $column->getType());
|
||||
|
||||
$this->assertEquals(200, $column->getLength());
|
||||
$this->assertEquals(5, $column->getPrecision());
|
||||
$this->assertEquals(2, $column->getScale());
|
||||
$this->assertTrue($column->getUnsigned());
|
||||
$this->assertFalse($column->getNotNull());
|
||||
$this->assertTrue($column->getFixed());
|
||||
$this->assertEquals("baz", $column->getDefault());
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar'), $column->getPlatformOptions());
|
||||
$this->assertTrue($column->hasPlatformOption('foo'));
|
||||
$this->assertEquals('bar', $column->getPlatformOption('foo'));
|
||||
$this->assertFalse($column->hasPlatformOption('bar'));
|
||||
|
||||
$this->assertEquals(array('bar' => 'baz'), $column->getCustomSchemaOptions());
|
||||
$this->assertTrue($column->hasCustomSchemaOption('bar'));
|
||||
$this->assertEquals('baz', $column->getCustomSchemaOption('bar'));
|
||||
$this->assertFalse($column->hasCustomSchemaOption('foo'));
|
||||
}
|
||||
|
||||
public function testToArray()
|
||||
{
|
||||
$expected = array(
|
||||
'name' => 'foo',
|
||||
'type' => Type::getType('string'),
|
||||
'default' => 'baz',
|
||||
'notnull' => false,
|
||||
'length' => 200,
|
||||
'precision' => 5,
|
||||
'scale' => 2,
|
||||
'fixed' => true,
|
||||
'unsigned' => true,
|
||||
'autoincrement' => false,
|
||||
'columnDefinition' => null,
|
||||
'comment' => null,
|
||||
'foo' => 'bar',
|
||||
'bar' => 'baz'
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $this->createColumn()->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Column
|
||||
*/
|
||||
public function createColumn()
|
||||
{
|
||||
$options = array(
|
||||
'length' => 200,
|
||||
'precision' => 5,
|
||||
'scale' => 2,
|
||||
'unsigned' => true,
|
||||
'notnull' => false,
|
||||
'fixed' => true,
|
||||
'default' => 'baz',
|
||||
'platformOptions' => array('foo' => 'bar'),
|
||||
'customSchemaOptions' => array('bar' => 'baz'),
|
||||
);
|
||||
|
||||
$string = Type::getType('string');
|
||||
return new Column("foo", $string, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-64
|
||||
*/
|
||||
public function testQuotedColumnName()
|
||||
{
|
||||
$string = Type::getType('string');
|
||||
$column = new Column("`bar`", $string, array());
|
||||
|
||||
$mysqlPlatform = new \Doctrine\DBAL\Platforms\MySqlPlatform();
|
||||
$sqlitePlatform = new \Doctrine\DBAL\Platforms\SqlitePlatform();
|
||||
|
||||
$this->assertEquals('bar', $column->getName());
|
||||
$this->assertEquals('`bar`', $column->getQuotedName($mysqlPlatform));
|
||||
$this->assertEquals('"bar"', $column->getQuotedName($sqlitePlatform));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-42
|
||||
*/
|
||||
public function testColumnComment()
|
||||
{
|
||||
$column = new Column("bar", Type::getType('string'));
|
||||
$this->assertNull($column->getComment());
|
||||
|
||||
$column->setComment("foo");
|
||||
$this->assertEquals("foo", $column->getComment());
|
||||
|
||||
$columnArray = $column->toArray();
|
||||
$this->assertArrayHasKey('comment', $columnArray);
|
||||
$this->assertEquals('foo', $columnArray['comment']);
|
||||
}
|
||||
}
|
787
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
vendored
Normal file
787
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
vendored
Normal file
@@ -0,0 +1,787 @@
|
||||
<?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 LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Schema;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema,
|
||||
Doctrine\DBAL\Schema\SchemaConfig,
|
||||
Doctrine\DBAL\Schema\Table,
|
||||
Doctrine\DBAL\Schema\Column,
|
||||
Doctrine\DBAL\Schema\Index,
|
||||
Doctrine\DBAL\Schema\Sequence,
|
||||
Doctrine\DBAL\Schema\SchemaDiff,
|
||||
Doctrine\DBAL\Schema\TableDiff,
|
||||
Doctrine\DBAL\Schema\Comparator,
|
||||
Doctrine\DBAL\Types\Type,
|
||||
Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
|
||||
/**
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
|
||||
* @license http://ez.no/licenses/new_bsd New BSD License
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class ComparatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCompareSame1()
|
||||
{
|
||||
$schema1 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer' ) ),
|
||||
)
|
||||
),
|
||||
) );
|
||||
$schema2 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer') ),
|
||||
)
|
||||
),
|
||||
) );
|
||||
|
||||
$this->assertEquals(new SchemaDiff(), Comparator::compareSchemas( $schema1, $schema2 ) );
|
||||
}
|
||||
|
||||
public function testCompareSame2()
|
||||
{
|
||||
$schema1 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer')),
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
)
|
||||
),
|
||||
) );
|
||||
$schema2 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer')),
|
||||
)
|
||||
),
|
||||
) );
|
||||
$this->assertEquals(new SchemaDiff(), Comparator::compareSchemas( $schema1, $schema2 ) );
|
||||
}
|
||||
|
||||
public function testCompareMissingTable()
|
||||
{
|
||||
$schemaConfig = new \Doctrine\DBAL\Schema\SchemaConfig;
|
||||
$table = new Table('bugdb', array ('integerfield1' => new Column('integerfield1', Type::getType('integer'))));
|
||||
$table->setSchemaConfig($schemaConfig);
|
||||
|
||||
$schema1 = new Schema( array($table), array(), $schemaConfig );
|
||||
$schema2 = new Schema( array(), array(), $schemaConfig );
|
||||
|
||||
$expected = new SchemaDiff( array(), array(), array('bugdb' => $table) );
|
||||
|
||||
$this->assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) );
|
||||
}
|
||||
|
||||
public function testCompareNewTable()
|
||||
{
|
||||
$schemaConfig = new \Doctrine\DBAL\Schema\SchemaConfig;
|
||||
$table = new Table('bugdb', array ('integerfield1' => new Column('integerfield1', Type::getType('integer'))));
|
||||
$table->setSchemaConfig($schemaConfig);
|
||||
|
||||
$schema1 = new Schema( array(), array(), $schemaConfig );
|
||||
$schema2 = new Schema( array($table), array(), $schemaConfig );
|
||||
|
||||
$expected = new SchemaDiff( array('bugdb' => $table), array(), array() );
|
||||
$this->assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) );
|
||||
}
|
||||
|
||||
public function testCompareOnlyAutoincrementChanged()
|
||||
{
|
||||
$column1 = new Column('foo', Type::getType('integer'), array('autoincrement' => true));
|
||||
$column2 = new Column('foo', Type::getType('integer'), array('autoincrement' => false));
|
||||
|
||||
$comparator = new Comparator();
|
||||
$changedProperties = $comparator->diffColumn($column1, $column2);
|
||||
|
||||
$this->assertEquals(array('autoincrement'), $changedProperties);
|
||||
}
|
||||
|
||||
public function testCompareMissingField()
|
||||
{
|
||||
$missingColumn = new Column('integerfield1', Type::getType('integer'));
|
||||
$schema1 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => $missingColumn,
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
)
|
||||
),
|
||||
) );
|
||||
$schema2 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
)
|
||||
),
|
||||
) );
|
||||
|
||||
$expected = new SchemaDiff ( array(),
|
||||
array (
|
||||
'bugdb' => new TableDiff( 'bugdb', array(), array(),
|
||||
array (
|
||||
'integerfield1' => $missingColumn,
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) );
|
||||
}
|
||||
|
||||
public function testCompareNewField()
|
||||
{
|
||||
$schema1 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer')),
|
||||
)
|
||||
),
|
||||
) );
|
||||
$schema2 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer')),
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
)
|
||||
),
|
||||
) );
|
||||
|
||||
$expected = new SchemaDiff ( array(),
|
||||
array (
|
||||
'bugdb' => new TableDiff ('bugdb',
|
||||
array (
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) );
|
||||
}
|
||||
|
||||
public function testCompareChangedColumns_ChangeType()
|
||||
{
|
||||
$column1 = new Column('charfield1', Type::getType('string'));
|
||||
$column2 = new Column('charfield1', Type::getType('integer'));
|
||||
|
||||
$c = new Comparator();
|
||||
$this->assertEquals(array('type'), $c->diffColumn($column1, $column2));
|
||||
$this->assertEquals(array(), $c->diffColumn($column1, $column1));
|
||||
}
|
||||
|
||||
public function testCompareChangedColumns_ChangeCustomSchemaOption()
|
||||
{
|
||||
$column1 = new Column('charfield1', Type::getType('string'));
|
||||
$column2 = new Column('charfield1', Type::getType('string'));
|
||||
|
||||
$column1->setCustomSchemaOption('foo', 'bar');
|
||||
$column2->setCustomSchemaOption('foo', 'bar');
|
||||
|
||||
$column1->setCustomSchemaOption('foo1', 'bar1');
|
||||
$column2->setCustomSchemaOption('foo2', 'bar2');
|
||||
|
||||
$c = new Comparator();
|
||||
$this->assertEquals(array('foo1', 'foo2'), $c->diffColumn($column1, $column2));
|
||||
$this->assertEquals(array(), $c->diffColumn($column1, $column1));
|
||||
}
|
||||
|
||||
public function testCompareRemovedIndex()
|
||||
{
|
||||
$schema1 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer')),
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
),
|
||||
array (
|
||||
'primary' => new Index('primary',
|
||||
array(
|
||||
'integerfield1'
|
||||
),
|
||||
true
|
||||
)
|
||||
)
|
||||
),
|
||||
) );
|
||||
$schema2 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer')),
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
)
|
||||
),
|
||||
) );
|
||||
|
||||
$expected = new SchemaDiff ( array(),
|
||||
array (
|
||||
'bugdb' => new TableDiff( 'bugdb', array(), array(), array(), array(), array(),
|
||||
array (
|
||||
'primary' => new Index('primary',
|
||||
array(
|
||||
'integerfield1'
|
||||
),
|
||||
true
|
||||
)
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) );
|
||||
}
|
||||
|
||||
public function testCompareNewIndex()
|
||||
{
|
||||
$schema1 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer')),
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
)
|
||||
),
|
||||
) );
|
||||
$schema2 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer')),
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
),
|
||||
array (
|
||||
'primary' => new Index('primary',
|
||||
array(
|
||||
'integerfield1'
|
||||
),
|
||||
true
|
||||
)
|
||||
)
|
||||
),
|
||||
) );
|
||||
|
||||
$expected = new SchemaDiff ( array(),
|
||||
array (
|
||||
'bugdb' => new TableDiff( 'bugdb', array(), array(), array(),
|
||||
array (
|
||||
'primary' => new Index('primary',
|
||||
array(
|
||||
'integerfield1'
|
||||
),
|
||||
true
|
||||
)
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) );
|
||||
}
|
||||
|
||||
public function testCompareChangedIndex()
|
||||
{
|
||||
$schema1 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer')),
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
),
|
||||
array (
|
||||
'primary' => new Index('primary',
|
||||
array(
|
||||
'integerfield1'
|
||||
),
|
||||
true
|
||||
)
|
||||
)
|
||||
),
|
||||
) );
|
||||
$schema2 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer')),
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
),
|
||||
array (
|
||||
'primary' => new Index('primary',
|
||||
array('integerfield1', 'integerfield2'),
|
||||
true
|
||||
)
|
||||
)
|
||||
),
|
||||
) );
|
||||
|
||||
$expected = new SchemaDiff ( array(),
|
||||
array (
|
||||
'bugdb' => new TableDiff( 'bugdb', array(), array(), array(), array(),
|
||||
array (
|
||||
'primary' => new Index('primary',
|
||||
array(
|
||||
'integerfield1',
|
||||
'integerfield2'
|
||||
),
|
||||
true
|
||||
)
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
$actual = Comparator::compareSchemas( $schema1, $schema2 );
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testCompareChangedIndexFieldPositions()
|
||||
{
|
||||
$schema1 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer')),
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
),
|
||||
array (
|
||||
'primary' => new Index('primary', array('integerfield1', 'integerfield2'), true)
|
||||
)
|
||||
),
|
||||
) );
|
||||
$schema2 = new Schema( array(
|
||||
'bugdb' => new Table('bugdb',
|
||||
array (
|
||||
'integerfield1' => new Column('integerfield1', Type::getType('integer')),
|
||||
'integerfield2' => new Column('integerfield2', Type::getType('integer')),
|
||||
),
|
||||
array (
|
||||
'primary' => new Index('primary', array('integerfield2', 'integerfield1'), true)
|
||||
)
|
||||
),
|
||||
) );
|
||||
|
||||
$expected = new SchemaDiff ( array(),
|
||||
array (
|
||||
'bugdb' => new TableDiff('bugdb', array(), array(), array(), array(),
|
||||
array (
|
||||
'primary' => new Index('primary', array('integerfield2', 'integerfield1'), true)
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
$actual = Comparator::compareSchemas( $schema1, $schema2 );
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testCompareSequences()
|
||||
{
|
||||
$seq1 = new Sequence('foo', 1, 1);
|
||||
$seq2 = new Sequence('foo', 1, 2);
|
||||
$seq3 = new Sequence('foo', 2, 1);
|
||||
|
||||
$c = new Comparator();
|
||||
|
||||
$this->assertTrue($c->diffSequence($seq1, $seq2));
|
||||
$this->assertTrue($c->diffSequence($seq1, $seq3));
|
||||
}
|
||||
|
||||
public function testRemovedSequence()
|
||||
{
|
||||
$schema1 = new Schema();
|
||||
$seq = $schema1->createSequence('foo');
|
||||
|
||||
$schema2 = new Schema();
|
||||
|
||||
$c = new Comparator();
|
||||
$diffSchema = $c->compare($schema1, $schema2);
|
||||
|
||||
$this->assertEquals(1, count($diffSchema->removedSequences));
|
||||
$this->assertSame($seq, $diffSchema->removedSequences[0]);
|
||||
}
|
||||
|
||||
public function testAddedSequence()
|
||||
{
|
||||
$schema1 = new Schema();
|
||||
|
||||
$schema2 = new Schema();
|
||||
$seq = $schema2->createSequence('foo');
|
||||
|
||||
$c = new Comparator();
|
||||
$diffSchema = $c->compare($schema1, $schema2);
|
||||
|
||||
$this->assertEquals(1, count($diffSchema->newSequences));
|
||||
$this->assertSame($seq, $diffSchema->newSequences[0]);
|
||||
}
|
||||
|
||||
public function testTableAddForeignKey()
|
||||
{
|
||||
$tableForeign = new Table("bar");
|
||||
$tableForeign->addColumn('id', 'integer');
|
||||
|
||||
$table1 = new Table("foo");
|
||||
$table1->addColumn('fk', 'integer');
|
||||
|
||||
$table2 = new Table("foo");
|
||||
$table2->addColumn('fk', 'integer');
|
||||
$table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id'));
|
||||
|
||||
$c = new Comparator();
|
||||
$tableDiff = $c->diffTable($table1, $table2);
|
||||
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
|
||||
$this->assertEquals(1, count($tableDiff->addedForeignKeys));
|
||||
}
|
||||
|
||||
public function testTableRemoveForeignKey()
|
||||
{
|
||||
$tableForeign = new Table("bar");
|
||||
$tableForeign->addColumn('id', 'integer');
|
||||
|
||||
$table1 = new Table("foo");
|
||||
$table1->addColumn('fk', 'integer');
|
||||
|
||||
$table2 = new Table("foo");
|
||||
$table2->addColumn('fk', 'integer');
|
||||
$table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id'));
|
||||
|
||||
$c = new Comparator();
|
||||
$tableDiff = $c->diffTable($table2, $table1);
|
||||
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
|
||||
$this->assertEquals(1, count($tableDiff->removedForeignKeys));
|
||||
}
|
||||
|
||||
public function testTableUpdateForeignKey()
|
||||
{
|
||||
$tableForeign = new Table("bar");
|
||||
$tableForeign->addColumn('id', 'integer');
|
||||
|
||||
$table1 = new Table("foo");
|
||||
$table1->addColumn('fk', 'integer');
|
||||
$table1->addForeignKeyConstraint($tableForeign, array('fk'), array('id'));
|
||||
|
||||
$table2 = new Table("foo");
|
||||
$table2->addColumn('fk', 'integer');
|
||||
$table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id'), array('onUpdate' => 'CASCADE'));
|
||||
|
||||
$c = new Comparator();
|
||||
$tableDiff = $c->diffTable($table1, $table2);
|
||||
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
|
||||
$this->assertEquals(1, count($tableDiff->changedForeignKeys));
|
||||
}
|
||||
|
||||
public function testTablesCaseInsensitive()
|
||||
{
|
||||
$schemaA = new Schema();
|
||||
$schemaA->createTable('foo');
|
||||
$schemaA->createTable('bAr');
|
||||
$schemaA->createTable('BAZ');
|
||||
$schemaA->createTable('new');
|
||||
|
||||
$schemaB = new Schema();
|
||||
$schemaB->createTable('FOO');
|
||||
$schemaB->createTable('bar');
|
||||
$schemaB->createTable('Baz');
|
||||
$schemaB->createTable('old');
|
||||
|
||||
$c = new Comparator();
|
||||
$diff = $c->compare($schemaA, $schemaB);
|
||||
|
||||
$this->assertSchemaTableChangeCount($diff, 1, 0, 1);
|
||||
}
|
||||
|
||||
public function testSequencesCaseInsenstive()
|
||||
{
|
||||
$schemaA = new Schema();
|
||||
$schemaA->createSequence('foo');
|
||||
$schemaA->createSequence('BAR');
|
||||
$schemaA->createSequence('Baz');
|
||||
$schemaA->createSequence('new');
|
||||
|
||||
$schemaB = new Schema();
|
||||
$schemaB->createSequence('FOO');
|
||||
$schemaB->createSequence('Bar');
|
||||
$schemaB->createSequence('baz');
|
||||
$schemaB->createSequence('old');
|
||||
|
||||
$c = new Comparator();
|
||||
$diff = $c->compare($schemaA, $schemaB);
|
||||
|
||||
$this->assertSchemaSequenceChangeCount($diff, 1, 0, 1);
|
||||
}
|
||||
|
||||
public function testCompareColumnCompareCaseInsensitive()
|
||||
{
|
||||
$tableA = new Table("foo");
|
||||
$tableA->addColumn('id', 'integer');
|
||||
|
||||
$tableB = new Table("foo");
|
||||
$tableB->addColumn('ID', 'integer');
|
||||
|
||||
$c = new Comparator();
|
||||
$tableDiff = $c->diffTable($tableA, $tableB);
|
||||
|
||||
$this->assertFalse($tableDiff);
|
||||
}
|
||||
|
||||
public function testCompareIndexBasedOnPropertiesNotName()
|
||||
{
|
||||
$tableA = new Table("foo");
|
||||
$tableA->addColumn('id', 'integer');
|
||||
$tableA->addIndex(array("id"), "foo_bar_idx");
|
||||
|
||||
$tableB = new Table("foo");
|
||||
$tableB->addColumn('ID', 'integer');
|
||||
$tableB->addIndex(array("id"), "bar_foo_idx");
|
||||
|
||||
$c = new Comparator();
|
||||
$tableDiff = $c->diffTable($tableA, $tableB);
|
||||
|
||||
$this->assertFalse($tableDiff);
|
||||
}
|
||||
|
||||
public function testCompareForeignKeyBasedOnPropertiesNotName()
|
||||
{
|
||||
$tableA = new Table("foo");
|
||||
$tableA->addColumn('id', 'integer');
|
||||
$tableA->addNamedForeignKeyConstraint('foo_constraint', 'bar', array('id'), array('id'));
|
||||
|
||||
$tableB = new Table("foo");
|
||||
$tableB->addColumn('ID', 'integer');
|
||||
$tableB->addNamedForeignKeyConstraint('bar_constraint', 'bar', array('id'), array('id'));
|
||||
|
||||
$c = new Comparator();
|
||||
$tableDiff = $c->diffTable($tableA, $tableB);
|
||||
|
||||
$this->assertFalse($tableDiff);
|
||||
}
|
||||
|
||||
public function testCompareForeignKey_RestrictNoAction_AreTheSame()
|
||||
{
|
||||
$fk1 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'NO ACTION'));
|
||||
$fk2 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'RESTRICT'));
|
||||
|
||||
$c = new Comparator();
|
||||
$this->assertFalse($c->diffForeignKey($fk1, $fk2));
|
||||
}
|
||||
|
||||
public function testDetectRenameColumn()
|
||||
{
|
||||
$tableA = new Table("foo");
|
||||
$tableA->addColumn('foo', 'integer');
|
||||
|
||||
$tableB = new Table("foo");
|
||||
$tableB->addColumn('bar', 'integer');
|
||||
|
||||
$c = new Comparator();
|
||||
$tableDiff = $c->diffTable($tableA, $tableB);
|
||||
|
||||
$this->assertEquals(0, count($tableDiff->addedColumns));
|
||||
$this->assertEquals(0, count($tableDiff->removedColumns));
|
||||
$this->assertArrayHasKey('foo', $tableDiff->renamedColumns);
|
||||
$this->assertEquals('bar', $tableDiff->renamedColumns['foo']->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* You can easily have ambiguouties in the column renaming. If these
|
||||
* are detected no renaming should take place, instead adding and dropping
|
||||
* should be used exclusively.
|
||||
*
|
||||
* @group DBAL-24
|
||||
*/
|
||||
public function testDetectRenameColumnAmbiguous()
|
||||
{
|
||||
$tableA = new Table("foo");
|
||||
$tableA->addColumn('foo', 'integer');
|
||||
$tableA->addColumn('bar', 'integer');
|
||||
|
||||
$tableB = new Table("foo");
|
||||
$tableB->addColumn('baz', 'integer');
|
||||
|
||||
$c = new Comparator();
|
||||
$tableDiff = $c->diffTable($tableA, $tableB);
|
||||
|
||||
$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->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.");
|
||||
}
|
||||
|
||||
public function testDetectChangeIdentifierType()
|
||||
{
|
||||
$this->markTestSkipped('DBAL-2 was reopened, this test cannot work anymore.');
|
||||
|
||||
$tableA = new Table("foo");
|
||||
$tableA->addColumn('id', 'integer', array('autoincrement' => false));
|
||||
|
||||
$tableB = new Table("foo");
|
||||
$tableB->addColumn('id', 'integer', array('autoincrement' => true));
|
||||
|
||||
$c = new Comparator();
|
||||
$tableDiff = $c->diffTable($tableA, $tableB);
|
||||
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
|
||||
$this->assertArrayHasKey('id', $tableDiff->changedColumns);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group DBAL-105
|
||||
*/
|
||||
public function testDiff()
|
||||
{
|
||||
$table = new \Doctrine\DBAL\Schema\Table('twitter_users');
|
||||
$table->addColumn('id', 'integer', array('autoincrement' => true));
|
||||
$table->addColumn('twitterId', 'integer', array('nullable' => false));
|
||||
$table->addColumn('displayName', 'string', array('nullable' => false));
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
$newtable = new \Doctrine\DBAL\Schema\Table('twitter_users');
|
||||
$newtable->addColumn('id', 'integer', array('autoincrement' => true));
|
||||
$newtable->addColumn('twitter_id', 'integer', array('nullable' => false));
|
||||
$newtable->addColumn('display_name', 'string', array('nullable' => false));
|
||||
$newtable->addColumn('logged_in_at', 'datetime', array('nullable' => true));
|
||||
$newtable->setPrimaryKey(array('id'));
|
||||
|
||||
$c = new Comparator();
|
||||
$tableDiff = $c->diffTable($table, $newtable);
|
||||
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
|
||||
$this->assertEquals(array('twitterid', 'displayname'), array_keys($tableDiff->renamedColumns));
|
||||
$this->assertEquals(array('logged_in_at'), array_keys($tableDiff->addedColumns));
|
||||
$this->assertEquals(0, count($tableDiff->removedColumns));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group DBAL-112
|
||||
*/
|
||||
public function testChangedSequence()
|
||||
{
|
||||
$schema = new Schema();
|
||||
$sequence = $schema->createSequence('baz');
|
||||
|
||||
$schemaNew = clone $schema;
|
||||
/* @var $schemaNew Schema */
|
||||
$schemaNew->getSequence('baz')->setAllocationSize(20);
|
||||
|
||||
$c = new \Doctrine\DBAL\Schema\Comparator;
|
||||
$diff = $c->compare($schema, $schemaNew);
|
||||
|
||||
$this->assertSame($diff->changedSequences[0] , $schemaNew->getSequence('baz'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-106
|
||||
*/
|
||||
public function testDiffDecimalWithNullPrecision()
|
||||
{
|
||||
$column = new Column('foo', Type::getType('decimal'));
|
||||
$column->setPrecision(null);
|
||||
|
||||
$column2 = new Column('foo', Type::getType('decimal'));
|
||||
|
||||
$c = new Comparator();
|
||||
$this->assertEquals(array(), $c->diffColumn($column, $column2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-204
|
||||
*/
|
||||
public function testFqnSchemaComparision()
|
||||
{
|
||||
$config = new SchemaConfig();
|
||||
$config->setName("foo");
|
||||
|
||||
$oldSchema = new Schema(array(), array(), $config);
|
||||
$oldSchema->createTable('bar');
|
||||
|
||||
$newSchema= new Schema(array(), array(), $config);
|
||||
$newSchema->createTable('foo.bar');
|
||||
|
||||
$c = new Comparator();
|
||||
$this->assertEquals(new SchemaDiff(), $c->compare($oldSchema, $newSchema));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-204
|
||||
*/
|
||||
public function testFqnSchemaComparisionDifferentSchemaNameButSameTableNoDiff()
|
||||
{
|
||||
$config = new SchemaConfig();
|
||||
$config->setName("foo");
|
||||
|
||||
$oldSchema = new Schema(array(), array(), $config);
|
||||
$oldSchema->createTable('foo.bar');
|
||||
|
||||
$newSchema = new Schema();
|
||||
$newSchema->createTable('bar');
|
||||
|
||||
$c = new Comparator();
|
||||
$diff = $c->compare($oldSchema, $newSchema);
|
||||
$this->assertEquals(new SchemaDiff(), $c->compare($oldSchema, $newSchema));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-204
|
||||
*/
|
||||
public function testFqnSchemaComparisionNoSchemaSame()
|
||||
{
|
||||
$config = new SchemaConfig();
|
||||
$config->setName("foo");
|
||||
$oldSchema = new Schema(array(), array(), $config);
|
||||
$oldSchema->createTable('bar');
|
||||
|
||||
$newSchema = new Schema();
|
||||
$newSchema->createTable('bar');
|
||||
|
||||
$c = new Comparator();
|
||||
$diff = $c->compare($oldSchema, $newSchema);
|
||||
|
||||
$this->assertEquals(new SchemaDiff(), $c->compare($oldSchema, $newSchema));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SchemaDiff $diff
|
||||
* @param int $newTableCount
|
||||
* @param int $changeTableCount
|
||||
* @param int $removeTableCount
|
||||
*/
|
||||
public function assertSchemaTableChangeCount($diff, $newTableCount=0, $changeTableCount=0, $removeTableCount=0)
|
||||
{
|
||||
$this->assertEquals($newTableCount, count($diff->newTables));
|
||||
$this->assertEquals($changeTableCount, count($diff->changedTables));
|
||||
$this->assertEquals($removeTableCount, count($diff->removedTables));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SchemaDiff $diff
|
||||
* @param int $newSequenceCount
|
||||
* @param int $changeSequenceCount
|
||||
* @param int $changeSequenceCount
|
||||
*/
|
||||
public function assertSchemaSequenceChangeCount($diff, $newSequenceCount=0, $changeSequenceCount=0, $removeSequenceCount=0)
|
||||
{
|
||||
$this->assertEquals($newSequenceCount, count($diff->newSequences), "Expected number of new sequences is wrong.");
|
||||
$this->assertEquals($changeSequenceCount, count($diff->changedSequences), "Expected number of changed sequences is wrong.");
|
||||
$this->assertEquals($removeSequenceCount, count($diff->removedSequences), "Expected number of removed sequences is wrong.");
|
||||
}
|
||||
}
|
99
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php
vendored
Normal file
99
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Schema;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Schema\Index;
|
||||
|
||||
class IndexTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function createIndex($unique=false, $primary=false)
|
||||
{
|
||||
return new Index("foo", array("bar", "baz"), $unique, $primary);
|
||||
}
|
||||
|
||||
public function testCreateIndex()
|
||||
{
|
||||
$idx = $this->createIndex();
|
||||
$this->assertEquals("foo", $idx->getName());
|
||||
$columns = $idx->getColumns();
|
||||
$this->assertEquals(2, count($columns));
|
||||
$this->assertEquals(array("bar", "baz"), $columns);
|
||||
$this->assertFalse($idx->isUnique());
|
||||
$this->assertFalse($idx->isPrimary());
|
||||
}
|
||||
|
||||
public function testCreatePrimary()
|
||||
{
|
||||
$idx = $this->createIndex(false, true);
|
||||
$this->assertTrue($idx->isUnique());
|
||||
$this->assertTrue($idx->isPrimary());
|
||||
}
|
||||
|
||||
public function testCreateUnique()
|
||||
{
|
||||
$idx = $this->createIndex(true, false);
|
||||
$this->assertTrue($idx->isUnique());
|
||||
$this->assertFalse($idx->isPrimary());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-50
|
||||
*/
|
||||
public function testFullfilledByUnique()
|
||||
{
|
||||
$idx1 = $this->createIndex(true, false);
|
||||
$idx2 = $this->createIndex(true, false);
|
||||
$idx3 = $this->createIndex();
|
||||
|
||||
$this->assertTrue($idx1->isFullfilledBy($idx2));
|
||||
$this->assertFalse($idx1->isFullfilledBy($idx3));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-50
|
||||
*/
|
||||
public function testFullfilledByPrimary()
|
||||
{
|
||||
$idx1 = $this->createIndex(true, true);
|
||||
$idx2 = $this->createIndex(true, true);
|
||||
$idx3 = $this->createIndex(true, false);
|
||||
|
||||
$this->assertTrue($idx1->isFullfilledBy($idx2));
|
||||
$this->assertFalse($idx1->isFullfilledBy($idx3));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-50
|
||||
*/
|
||||
public function testFullfilledByIndex()
|
||||
{
|
||||
$idx1 = $this->createIndex();
|
||||
$idx2 = $this->createIndex();
|
||||
$pri = $this->createIndex(true, true);
|
||||
$uniq = $this->createIndex(true);
|
||||
|
||||
$this->assertTrue($idx1->isFullfilledBy($idx2));
|
||||
$this->assertTrue($idx1->isFullfilledBy($pri));
|
||||
$this->assertTrue($idx1->isFullfilledBy($uniq));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-285
|
||||
*/
|
||||
public function testIndexQuotes()
|
||||
{
|
||||
$index = new Index("foo", array("`bar`", "`baz`"));
|
||||
|
||||
$this->assertTrue($index->spansColumns(array("bar", "baz")));
|
||||
$this->assertTrue($index->hasColumnAtPosition("bar", 0));
|
||||
$this->assertTrue($index->hasColumnAtPosition("baz", 1));
|
||||
|
||||
$this->assertFalse($index->hasColumnAtPosition("bar", 1));
|
||||
$this->assertFalse($index->hasColumnAtPosition("baz", 0));
|
||||
}
|
||||
}
|
76
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php
vendored
Normal file
76
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Schema;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Configuration;
|
||||
use Doctrine\DBAL\Events;
|
||||
use Doctrine\DBAL\Schema\MySqlSchemaManager;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
use Doctrine\Tests\TestUtil;
|
||||
|
||||
class MySqlSchemaManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager
|
||||
*/
|
||||
private $manager;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$eventManager = new EventManager();
|
||||
$driverMock = $this->getMock('Doctrine\DBAL\Driver');
|
||||
$platform = $this->getMock('Doctrine\DBAL\Platforms\MySqlPlatform');
|
||||
$this->conn = $this->getMock(
|
||||
'Doctrine\DBAL\Connection',
|
||||
array('fetchAll'),
|
||||
array(array('platform' => $platform), $driverMock, new Configuration(), $eventManager)
|
||||
);
|
||||
$this->manager = new MySqlSchemaManager($this->conn);
|
||||
}
|
||||
|
||||
public function testCompositeForeignKeys()
|
||||
{
|
||||
$this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue($this->getFKDefinition()));
|
||||
$fkeys = $this->manager->listTableForeignKeys('dummy');
|
||||
$this->assertEquals(1, count($fkeys), "Table has to have one foreign key.");
|
||||
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]);
|
||||
$this->assertEquals(array('column_1', 'column_2', 'column_3'), array_map('strtolower', $fkeys[0]->getLocalColumns()));
|
||||
$this->assertEquals(array('column_1', 'column_2', 'column_3'), array_map('strtolower', $fkeys[0]->getForeignColumns()));
|
||||
}
|
||||
|
||||
public function getFKDefinition()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
"CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E",
|
||||
"COLUMN_NAME" => "column_1",
|
||||
"REFERENCED_TABLE_NAME" => "dummy",
|
||||
"REFERENCED_COLUMN_NAME" => "column_1",
|
||||
"update_rule" => "RESTRICT",
|
||||
"delete_rule" => "RESTRICT",
|
||||
),
|
||||
array(
|
||||
"CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E",
|
||||
"COLUMN_NAME" => "column_2",
|
||||
"REFERENCED_TABLE_NAME" => "dummy",
|
||||
"REFERENCED_COLUMN_NAME" => "column_2",
|
||||
"update_rule" => "RESTRICT",
|
||||
"delete_rule" => "RESTRICT",
|
||||
),
|
||||
array(
|
||||
"CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E",
|
||||
"COLUMN_NAME" => "column_3",
|
||||
"REFERENCED_TABLE_NAME" => "dummy",
|
||||
"REFERENCED_COLUMN_NAME" => "column_3",
|
||||
"update_rule" => "RESTRICT",
|
||||
"delete_rule" => "RESTRICT",
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
67
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php
vendored
Normal file
67
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Schema\Platforms;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
class MySQLSchemaTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Comparator
|
||||
*/
|
||||
private $comparator;
|
||||
/**
|
||||
*
|
||||
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
|
||||
*/
|
||||
private $platform;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->comparator = new \Doctrine\DBAL\Schema\Comparator;
|
||||
$this->platform = new \Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||
}
|
||||
|
||||
public function testSwitchPrimaryKeyOrder()
|
||||
{
|
||||
$tableOld = new Table("test");
|
||||
$tableOld->addColumn('foo_id', 'integer');
|
||||
$tableOld->addColumn('bar_id', 'integer');
|
||||
$tableNew = clone $tableOld;
|
||||
|
||||
$tableOld->setPrimaryKey(array('foo_id', 'bar_id'));
|
||||
$tableNew->setPrimaryKey(array('bar_id', 'foo_id'));
|
||||
|
||||
$diff = $this->comparator->diffTable($tableOld, $tableNew);
|
||||
$sql = $this->platform->getAlterTableSQL($diff);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'ALTER TABLE test DROP PRIMARY KEY',
|
||||
'ALTER TABLE test ADD PRIMARY KEY (bar_id, foo_id)'
|
||||
), $sql
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-132
|
||||
*/
|
||||
public function testGenerateForeignKeySQL()
|
||||
{
|
||||
$tableOld = new Table("test");
|
||||
$tableOld->addColumn('foo_id', 'integer');
|
||||
$tableOld->addUnnamedForeignKeyConstraint('test_foreign', array('foo_id'), array('foo_id'));
|
||||
|
||||
$sqls = array();
|
||||
foreach ($tableOld->getForeignKeys() AS $fk) {
|
||||
$sqls[] = $this->platform->getCreateForeignKeySQL($fk, $tableOld);
|
||||
}
|
||||
|
||||
$this->assertEquals(array("ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C8E48560F FOREIGN KEY (foo_id) REFERENCES test_foreign (foo_id)"), $sqls);
|
||||
}
|
||||
}
|
109
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php
vendored
Normal file
109
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Schema;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema,
|
||||
Doctrine\DBAL\Schema\Table,
|
||||
Doctrine\DBAL\Schema\Column,
|
||||
Doctrine\DBAL\Schema\Index,
|
||||
Doctrine\DBAL\Schema\Sequence,
|
||||
Doctrine\DBAL\Schema\SchemaDiff,
|
||||
Doctrine\DBAL\Schema\TableDiff,
|
||||
Doctrine\DBAL\Schema\Comparator,
|
||||
Doctrine\DBAL\Types\Type;
|
||||
|
||||
class SchemaDiffTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSchemaDiffToSql()
|
||||
{
|
||||
$diff = $this->createSchemaDiff();
|
||||
$platform = $this->createPlatform(true);
|
||||
|
||||
$sql = $diff->toSql($platform);
|
||||
|
||||
$expected = array('drop_orphan_fk', 'alter_seq', 'drop_seq', 'create_seq', 'create_table', 'create_foreign_key', 'drop_table', 'alter_table');
|
||||
|
||||
$this->assertEquals($expected, $sql);
|
||||
}
|
||||
|
||||
public function testSchemaDiffToSaveSql()
|
||||
{
|
||||
$diff = $this->createSchemaDiff();
|
||||
$platform = $this->createPlatform(false);
|
||||
|
||||
$sql = $diff->toSaveSql($platform);
|
||||
|
||||
$expected = array('alter_seq', 'create_seq', 'create_table', 'create_foreign_key', 'alter_table');
|
||||
|
||||
$this->assertEquals($expected, $sql);
|
||||
}
|
||||
|
||||
public function createPlatform($unsafe = false)
|
||||
{
|
||||
$platform = $this->getMock('Doctrine\Tests\DBAL\Mocks\MockPlatform');
|
||||
if ($unsafe) {
|
||||
$platform->expects($this->exactly(1))
|
||||
->method('getDropSequenceSql')
|
||||
->with($this->isInstanceOf('Doctrine\DBAL\Schema\Sequence'))
|
||||
->will($this->returnValue('drop_seq'));
|
||||
}
|
||||
$platform->expects($this->exactly(1))
|
||||
->method('getAlterSequenceSql')
|
||||
->with($this->isInstanceOf('Doctrine\DBAL\Schema\Sequence'))
|
||||
->will($this->returnValue('alter_seq'));
|
||||
$platform->expects($this->exactly(1))
|
||||
->method('getCreateSequenceSql')
|
||||
->with($this->isInstanceOf('Doctrine\DBAL\Schema\Sequence'))
|
||||
->will($this->returnValue('create_seq'));
|
||||
if ($unsafe) {
|
||||
$platform->expects($this->exactly(1))
|
||||
->method('getDropTableSql')
|
||||
->with($this->isInstanceof('Doctrine\DBAL\Schema\Table'))
|
||||
->will($this->returnValue('drop_table'));
|
||||
}
|
||||
$platform->expects($this->exactly(1))
|
||||
->method('getCreateTableSql')
|
||||
->with($this->isInstanceof('Doctrine\DBAL\Schema\Table'))
|
||||
->will($this->returnValue(array('create_table')));
|
||||
$platform->expects($this->exactly(1))
|
||||
->method('getCreateForeignKeySQL')
|
||||
->with($this->isInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint'))
|
||||
->will($this->returnValue('create_foreign_key'));
|
||||
$platform->expects($this->exactly(1))
|
||||
->method('getAlterTableSql')
|
||||
->with($this->isInstanceOf('Doctrine\DBAL\Schema\TableDiff'))
|
||||
->will($this->returnValue(array('alter_table')));
|
||||
if ($unsafe) {
|
||||
$platform->expects($this->exactly(1))
|
||||
->method('getDropForeignKeySql')
|
||||
->with($this->isInstanceof('Doctrine\DBAL\Schema\ForeignKeyConstraint'), $this->equalTo('local_table'))
|
||||
->will($this->returnValue('drop_orphan_fk'));
|
||||
}
|
||||
$platform->expects($this->exactly(1))
|
||||
->method('supportsSequences')
|
||||
->will($this->returnValue(true));
|
||||
$platform->expects($this->exactly(2))
|
||||
->method('supportsForeignKeyConstraints')
|
||||
->will($this->returnValue(true));
|
||||
return $platform;
|
||||
}
|
||||
|
||||
public function createSchemaDiff()
|
||||
{
|
||||
$diff = new SchemaDiff();
|
||||
$diff->changedSequences['foo_seq'] = new Sequence('foo_seq');
|
||||
$diff->newSequences['bar_seq'] = new Sequence('bar_seq');
|
||||
$diff->removedSequences['baz_seq'] = new Sequence('baz_seq');
|
||||
$diff->newTables['foo_table'] = new Table('foo_table');
|
||||
$diff->removedTables['bar_table'] = new Table('bar_table');
|
||||
$diff->changedTables['baz_table'] = new TableDiff('baz_table');
|
||||
$diff->newTables['foo_table']->addColumn('foreign_id', 'integer');
|
||||
$diff->newTables['foo_table']->addForeignKeyConstraint('foreign_table', array('foreign_id'), array('id'));
|
||||
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('id'), 'foreign_table', array('id'));
|
||||
$fk->setLocalTable(new Table('local_table'));
|
||||
$diff->orphanedForeignKeys[] = $fk;
|
||||
return $diff;
|
||||
}
|
||||
}
|
224
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php
vendored
Normal file
224
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php
vendored
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Schema;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Sequence;
|
||||
|
||||
class SchemaTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testAddTable()
|
||||
{
|
||||
$tableName = "public.foo";
|
||||
$table = new Table($tableName);
|
||||
|
||||
$schema = new Schema(array($table));
|
||||
|
||||
$this->assertTrue($schema->hasTable($tableName));
|
||||
|
||||
$tables = $schema->getTables();
|
||||
$this->assertTrue( isset($tables[$tableName]) );
|
||||
$this->assertSame($table, $tables[$tableName]);
|
||||
$this->assertSame($table, $schema->getTable($tableName));
|
||||
$this->assertTrue($schema->hasTable($tableName));
|
||||
}
|
||||
|
||||
public function testTableMatchingCaseInsenstive()
|
||||
{
|
||||
$table = new Table("Foo");
|
||||
|
||||
$schema = new Schema(array($table));
|
||||
$this->assertTrue($schema->hasTable("foo"));
|
||||
$this->assertTrue($schema->hasTable("FOO"));
|
||||
|
||||
$this->assertSame($table, $schema->getTable('FOO'));
|
||||
$this->assertSame($table, $schema->getTable('foo'));
|
||||
$this->assertSame($table, $schema->getTable('Foo'));
|
||||
}
|
||||
|
||||
public function testGetUnknownTableThrowsException()
|
||||
{
|
||||
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
|
||||
|
||||
$schema = new Schema();
|
||||
$schema->getTable("unknown");
|
||||
}
|
||||
|
||||
public function testCreateTableTwiceThrowsException()
|
||||
{
|
||||
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
|
||||
|
||||
$tableName = "foo";
|
||||
$table = new Table($tableName);
|
||||
$tables = array($table, $table);
|
||||
|
||||
$schema = new Schema($tables);
|
||||
}
|
||||
|
||||
public function testRenameTable()
|
||||
{
|
||||
$tableName = "foo";
|
||||
$table = new Table($tableName);
|
||||
$schema = new Schema(array($table));
|
||||
|
||||
$this->assertTrue($schema->hasTable("foo"));
|
||||
$schema->renameTable("foo", "bar");
|
||||
$this->assertFalse($schema->hasTable("foo"));
|
||||
$this->assertTrue($schema->hasTable("bar"));
|
||||
$this->assertSame($table, $schema->getTable("bar"));
|
||||
}
|
||||
|
||||
public function testDropTable()
|
||||
{
|
||||
$tableName = "foo";
|
||||
$table = new Table($tableName);
|
||||
$schema = new Schema(array($table));
|
||||
|
||||
$this->assertTrue($schema->hasTable("foo"));
|
||||
|
||||
$schema->dropTable("foo");
|
||||
|
||||
$this->assertFalse($schema->hasTable("foo"));
|
||||
}
|
||||
|
||||
public function testCreateTable()
|
||||
{
|
||||
$schema = new Schema();
|
||||
|
||||
$this->assertFalse($schema->hasTable("foo"));
|
||||
|
||||
$table = $schema->createTable("foo");
|
||||
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\Table', $table);
|
||||
$this->assertEquals("foo", $table->getName());
|
||||
$this->assertTrue($schema->hasTable("foo"));
|
||||
}
|
||||
|
||||
public function testAddSequences()
|
||||
{
|
||||
$sequence = new Sequence("a_seq", 1, 1);
|
||||
|
||||
$schema = new Schema(array(), array($sequence));
|
||||
|
||||
$this->assertTrue($schema->hasSequence("a_seq"));
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence("a_seq"));
|
||||
|
||||
$sequences = $schema->getSequences();
|
||||
$this->assertArrayHasKey('public.a_seq', $sequences);
|
||||
}
|
||||
|
||||
public function testSequenceAccessCaseInsensitive()
|
||||
{
|
||||
$sequence = new Sequence("a_Seq");
|
||||
|
||||
$schema = new Schema(array(), array($sequence));
|
||||
$this->assertTrue($schema->hasSequence('a_seq'));
|
||||
$this->assertTrue($schema->hasSequence('a_Seq'));
|
||||
$this->assertTrue($schema->hasSequence('A_SEQ'));
|
||||
|
||||
$this->assertEquals($sequence, $schema->getSequence('a_seq'));
|
||||
$this->assertEquals($sequence, $schema->getSequence('a_Seq'));
|
||||
$this->assertEquals($sequence, $schema->getSequence('A_SEQ'));
|
||||
}
|
||||
|
||||
public function testGetUnknownSequenceThrowsException()
|
||||
{
|
||||
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
|
||||
|
||||
$schema = new Schema();
|
||||
$schema->getSequence("unknown");
|
||||
}
|
||||
|
||||
public function testCreateSequence()
|
||||
{
|
||||
$schema = new Schema();
|
||||
$sequence = $schema->createSequence('a_seq', 10, 20);
|
||||
|
||||
$this->assertEquals('a_seq', $sequence->getName());
|
||||
$this->assertEquals(10, $sequence->getAllocationSize());
|
||||
$this->assertEquals(20, $sequence->getInitialValue());
|
||||
|
||||
$this->assertTrue($schema->hasSequence("a_seq"));
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence("a_seq"));
|
||||
|
||||
$sequences = $schema->getSequences();
|
||||
$this->assertArrayHasKey('public.a_seq', $sequences);
|
||||
}
|
||||
|
||||
public function testDropSequence()
|
||||
{
|
||||
$sequence = new Sequence("a_seq", 1, 1);
|
||||
|
||||
$schema = new Schema(array(), array($sequence));
|
||||
|
||||
$schema->dropSequence("a_seq");
|
||||
$this->assertFalse($schema->hasSequence("a_seq"));
|
||||
}
|
||||
|
||||
public function testAddSequenceTwiceThrowsException()
|
||||
{
|
||||
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
|
||||
|
||||
$sequence = new Sequence("a_seq", 1, 1);
|
||||
|
||||
$schema = new Schema(array(), array($sequence, $sequence));
|
||||
}
|
||||
|
||||
public function testConfigMaxIdentifierLength()
|
||||
{
|
||||
$schemaConfig = new \Doctrine\DBAL\Schema\SchemaConfig();
|
||||
$schemaConfig->setMaxIdentifierLength(5);
|
||||
|
||||
$schema = new Schema(array(), array(), $schemaConfig);
|
||||
$table = $schema->createTable("smalltable");
|
||||
$table->addColumn('long_id', 'integer');
|
||||
$table->addIndex(array('long_id'));
|
||||
|
||||
$index = current($table->getIndexes());
|
||||
$this->assertEquals(5, strlen($index->getName()));
|
||||
}
|
||||
|
||||
public function testDeepClone()
|
||||
{
|
||||
$schema = new Schema();
|
||||
$sequence = $schema->createSequence('baz');
|
||||
|
||||
$tableA = $schema->createTable('foo');
|
||||
$tableA->addColumn('id', 'integer');
|
||||
|
||||
$tableB = $schema->createTable('bar');
|
||||
$tableB->addColumn('id', 'integer');
|
||||
$tableB->addColumn('foo_id', 'integer');
|
||||
$tableB->addForeignKeyConstraint($tableA, array('foo_id'), array('id'));
|
||||
|
||||
$schemaNew = clone $schema;
|
||||
|
||||
$this->assertNotSame($sequence, $schemaNew->getSequence('baz'));
|
||||
|
||||
$this->assertNotSame($tableA, $schemaNew->getTable('foo'));
|
||||
$this->assertNotSame($tableA->getColumn('id'), $schemaNew->getTable('foo')->getColumn('id'));
|
||||
|
||||
$this->assertNotSame($tableB, $schemaNew->getTable('bar'));
|
||||
$this->assertNotSame($tableB->getColumn('id'), $schemaNew->getTable('bar')->getColumn('id'));
|
||||
|
||||
$fk = $schemaNew->getTable('bar')->getForeignKeys();
|
||||
$fk = current($fk);
|
||||
$this->assertSame($schemaNew->getTable('bar'), $this->readAttribute($fk, '_localTable'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-219
|
||||
*/
|
||||
public function testHasTableForQuotedAsset()
|
||||
{
|
||||
$schema = new Schema();
|
||||
|
||||
$tableA = $schema->createTable('foo');
|
||||
$tableA->addColumn('id', 'integer');
|
||||
|
||||
$this->assertTrue($schema->hasTable('`foo`'));
|
||||
}
|
||||
}
|
500
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/TableTest.php
vendored
Normal file
500
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/TableTest.php
vendored
Normal file
@@ -0,0 +1,500 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Schema;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\TableBuilder;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Schema\Index;
|
||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
class TableTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
public function testCreateWithInvalidTableName()
|
||||
{
|
||||
$this->setExpectedException('Doctrine\DBAL\DBALException');
|
||||
$table = new \Doctrine\DBAL\Schema\Table('');
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
$table = new Table("foo", array(), array(), array());
|
||||
$this->assertEquals("foo", $table->getName());
|
||||
}
|
||||
|
||||
public function testColumns()
|
||||
{
|
||||
$type = Type::getType('integer');
|
||||
$columns = array();
|
||||
$columns[] = new Column("foo", $type);
|
||||
$columns[] = new Column("bar", $type);
|
||||
$table = new Table("foo", $columns, array(), array());
|
||||
|
||||
$this->assertTrue($table->hasColumn("foo"));
|
||||
$this->assertTrue($table->hasColumn("bar"));
|
||||
$this->assertFalse($table->hasColumn("baz"));
|
||||
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn("foo"));
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn("bar"));
|
||||
|
||||
$this->assertEquals(2, count($table->getColumns()));
|
||||
}
|
||||
|
||||
public function testColumnsCaseInsensitive()
|
||||
{
|
||||
$table = new Table("foo");
|
||||
$column = $table->addColumn('Foo', 'integer');
|
||||
|
||||
$this->assertTrue($table->hasColumn('Foo'));
|
||||
$this->assertTrue($table->hasColumn('foo'));
|
||||
$this->assertTrue($table->hasColumn('FOO'));
|
||||
|
||||
$this->assertSame($column, $table->getColumn('Foo'));
|
||||
$this->assertSame($column, $table->getColumn('foo'));
|
||||
$this->assertSame($column, $table->getColumn('FOO'));
|
||||
}
|
||||
|
||||
public function testCreateColumn()
|
||||
{
|
||||
$type = Type::getType('integer');
|
||||
|
||||
$table = new Table("foo");
|
||||
|
||||
$this->assertFalse($table->hasColumn("bar"));
|
||||
$table->addColumn("bar", 'integer');
|
||||
$this->assertTrue($table->hasColumn("bar"));
|
||||
$this->assertSame($type, $table->getColumn("bar")->getType());
|
||||
}
|
||||
|
||||
public function testDropColumn()
|
||||
{
|
||||
$type = Type::getType('integer');
|
||||
$columns = array();
|
||||
$columns[] = new Column("foo", $type);
|
||||
$columns[] = new Column("bar", $type);
|
||||
$table = new Table("foo", $columns, array(), array());
|
||||
|
||||
$this->assertTrue($table->hasColumn("foo"));
|
||||
$this->assertTrue($table->hasColumn("bar"));
|
||||
|
||||
$table->dropColumn("foo")->dropColumn("bar");
|
||||
|
||||
$this->assertFalse($table->hasColumn("foo"));
|
||||
$this->assertFalse($table->hasColumn("bar"));
|
||||
}
|
||||
|
||||
public function testGetUnknownColumnThrowsException()
|
||||
{
|
||||
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
|
||||
|
||||
$table = new Table("foo", array(), array(), array());
|
||||
$table->getColumn('unknown');
|
||||
}
|
||||
|
||||
public function testAddColumnTwiceThrowsException()
|
||||
{
|
||||
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
|
||||
|
||||
$type = \Doctrine\DBAL\Types\Type::getType('integer');
|
||||
$columns = array();
|
||||
$columns[] = new Column("foo", $type);
|
||||
$columns[] = new Column("foo", $type);
|
||||
$table = new Table("foo", $columns, array(), array());
|
||||
}
|
||||
|
||||
public function testCreateIndex()
|
||||
{
|
||||
$type = \Doctrine\DBAL\Types\Type::getType('integer');
|
||||
$columns = array(new Column("foo", $type), new Column("bar", $type), new Column("baz", $type));
|
||||
$table = new Table("foo", $columns);
|
||||
|
||||
$table->addIndex(array("foo", "bar"), "foo_foo_bar_idx");
|
||||
$table->addUniqueIndex(array("bar", "baz"), "foo_bar_baz_uniq");
|
||||
|
||||
$this->assertTrue($table->hasIndex("foo_foo_bar_idx"));
|
||||
$this->assertTrue($table->hasIndex("foo_bar_baz_uniq"));
|
||||
}
|
||||
|
||||
public function testIndexCaseInsensitive()
|
||||
{
|
||||
$type = \Doctrine\DBAL\Types\Type::getType('integer');
|
||||
$columns = array(
|
||||
new Column("foo", $type),
|
||||
new Column("bar", $type),
|
||||
new Column("baz", $type)
|
||||
);
|
||||
$table = new Table("foo", $columns);
|
||||
|
||||
$table->addIndex(array("foo", "bar", "baz"), "Foo_Idx");
|
||||
|
||||
$this->assertTrue($table->hasIndex('foo_idx'));
|
||||
$this->assertTrue($table->hasIndex('Foo_Idx'));
|
||||
$this->assertTrue($table->hasIndex('FOO_IDX'));
|
||||
}
|
||||
|
||||
public function testAddIndexes()
|
||||
{
|
||||
$type = \Doctrine\DBAL\Types\Type::getType('integer');
|
||||
$columns = array(
|
||||
new Column("foo", $type),
|
||||
new Column("bar", $type),
|
||||
);
|
||||
$indexes = array(
|
||||
new Index("the_primary", array("foo"), true, true),
|
||||
new Index("bar_idx", array("bar"), false, false),
|
||||
);
|
||||
$table = new Table("foo", $columns, $indexes, array());
|
||||
|
||||
$this->assertTrue($table->hasIndex("the_primary"));
|
||||
$this->assertTrue($table->hasIndex("bar_idx"));
|
||||
$this->assertFalse($table->hasIndex("some_idx"));
|
||||
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey());
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex('the_primary'));
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex('bar_idx'));
|
||||
}
|
||||
|
||||
public function testGetUnknownIndexThrowsException()
|
||||
{
|
||||
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
|
||||
|
||||
$table = new Table("foo", array(), array(), array());
|
||||
$table->getIndex("unknownIndex");
|
||||
}
|
||||
|
||||
public function testAddTwoPrimaryThrowsException()
|
||||
{
|
||||
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
|
||||
|
||||
$type = \Doctrine\DBAL\Types\Type::getType('integer');
|
||||
$columns = array(new Column("foo", $type), new Column("bar", $type));
|
||||
$indexes = array(
|
||||
new Index("the_primary", array("foo"), true, true),
|
||||
new Index("other_primary", array("bar"), true, true),
|
||||
);
|
||||
$table = new Table("foo", $columns, $indexes, array());
|
||||
}
|
||||
|
||||
public function testAddTwoIndexesWithSameNameThrowsException()
|
||||
{
|
||||
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
|
||||
|
||||
$type = \Doctrine\DBAL\Types\Type::getType('integer');
|
||||
$columns = array(new Column("foo", $type), new Column("bar", $type));
|
||||
$indexes = array(
|
||||
new Index("an_idx", array("foo"), false, false),
|
||||
new Index("an_idx", array("bar"), false, false),
|
||||
);
|
||||
$table = new Table("foo", $columns, $indexes, array());
|
||||
}
|
||||
|
||||
public function testConstraints()
|
||||
{
|
||||
$constraint = new ForeignKeyConstraint(array(), "foo", array());
|
||||
|
||||
$tableA = new Table("foo", array(), array(), array($constraint));
|
||||
$constraints = $tableA->getForeignKeys();
|
||||
|
||||
$this->assertEquals(1, count($constraints));
|
||||
$this->assertSame($constraint, array_shift($constraints));
|
||||
}
|
||||
|
||||
public function testOptions()
|
||||
{
|
||||
$table = new Table("foo", array(), array(), array(), false, array("foo" => "bar"));
|
||||
|
||||
$this->assertTrue($table->hasOption("foo"));
|
||||
$this->assertEquals("bar", $table->getOption("foo"));
|
||||
}
|
||||
|
||||
public function testBuilderSetPrimaryKey()
|
||||
{
|
||||
$table = new Table("foo");
|
||||
|
||||
$table->addColumn("bar", 'integer');
|
||||
$table->setPrimaryKey(array("bar"));
|
||||
|
||||
$this->assertTrue($table->hasIndex("primary"));
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey());
|
||||
$this->assertTrue($table->getIndex("primary")->isUnique());
|
||||
$this->assertTrue($table->getIndex("primary")->isPrimary());
|
||||
}
|
||||
|
||||
public function testBuilderAddUniqueIndex()
|
||||
{
|
||||
$table = new Table("foo");
|
||||
|
||||
$table->addColumn("bar", 'integer');
|
||||
$table->addUniqueIndex(array("bar"), "my_idx");
|
||||
|
||||
$this->assertTrue($table->hasIndex("my_idx"));
|
||||
$this->assertTrue($table->getIndex("my_idx")->isUnique());
|
||||
$this->assertFalse($table->getIndex("my_idx")->isPrimary());
|
||||
}
|
||||
|
||||
public function testBuilderAddIndex()
|
||||
{
|
||||
$table = new Table("foo");
|
||||
|
||||
$table->addColumn("bar", 'integer');
|
||||
$table->addIndex(array("bar"), "my_idx");
|
||||
|
||||
$this->assertTrue($table->hasIndex("my_idx"));
|
||||
$this->assertFalse($table->getIndex("my_idx")->isUnique());
|
||||
$this->assertFalse($table->getIndex("my_idx")->isPrimary());
|
||||
}
|
||||
|
||||
public function testBuilderAddIndexWithInvalidNameThrowsException()
|
||||
{
|
||||
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
|
||||
|
||||
$table = new Table("foo");
|
||||
$table->addColumn("bar",'integer');
|
||||
$table->addIndex(array("bar"), "invalid name %&/");
|
||||
}
|
||||
|
||||
public function testBuilderAddIndexWithUnknownColumnThrowsException()
|
||||
{
|
||||
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
|
||||
|
||||
$table = new Table("foo");
|
||||
$table->addIndex(array("bar"), "invalidName");
|
||||
}
|
||||
|
||||
public function testBuilderOptions()
|
||||
{
|
||||
$table = new Table("foo");
|
||||
$table->addOption("foo", "bar");
|
||||
$this->assertTrue($table->hasOption("foo"));
|
||||
$this->assertEquals("bar", $table->getOption("foo"));
|
||||
}
|
||||
|
||||
public function testAddForeignKeyConstraint_UnknownLocalColumn_ThrowsException()
|
||||
{
|
||||
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
|
||||
|
||||
$table = new Table("foo");
|
||||
$table->addColumn("id", 'integer');
|
||||
|
||||
$foreignTable = new Table("bar");
|
||||
$foreignTable->addColumn("id", 'integer');
|
||||
|
||||
$table->addForeignKeyConstraint($foreignTable, array("foo"), array("id"));
|
||||
}
|
||||
|
||||
public function testAddForeignKeyConstraint_UnknownForeignColumn_ThrowsException()
|
||||
{
|
||||
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
|
||||
|
||||
$table = new Table("foo");
|
||||
$table->addColumn("id", 'integer');
|
||||
|
||||
$foreignTable = new Table("bar");
|
||||
$foreignTable->addColumn("id", 'integer');
|
||||
|
||||
$table->addForeignKeyConstraint($foreignTable, array("id"), array("foo"));
|
||||
}
|
||||
|
||||
public function testAddForeignKeyConstraint()
|
||||
{
|
||||
$table = new Table("foo");
|
||||
$table->addColumn("id", 'integer');
|
||||
|
||||
$foreignTable = new Table("bar");
|
||||
$foreignTable->addColumn("id", 'integer');
|
||||
|
||||
$table->addForeignKeyConstraint($foreignTable, array("id"), array("id"), array("foo" => "bar"));
|
||||
|
||||
$constraints = $table->getForeignKeys();
|
||||
$this->assertEquals(1, count($constraints));
|
||||
$constraint = current($constraints);
|
||||
|
||||
$this->assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $constraint);
|
||||
|
||||
$this->assertTrue($constraint->hasOption("foo"));
|
||||
$this->assertEquals("bar", $constraint->getOption("foo"));
|
||||
}
|
||||
|
||||
public function testAddIndexWithCaseSensitiveColumnProblem()
|
||||
{
|
||||
$table = new Table("foo");
|
||||
$table->addColumn("id", 'integer');
|
||||
|
||||
$table->addIndex(array("ID"), "my_idx");
|
||||
|
||||
$this->assertTrue($table->hasIndex('my_idx'));
|
||||
$this->assertEquals(array("ID"), $table->getIndex("my_idx")->getColumns());
|
||||
$this->assertTrue($table->getIndex('my_idx')->spansColumns(array('id')));
|
||||
}
|
||||
|
||||
public function testAddPrimaryKey_ColumnsAreExplicitlySetToNotNull()
|
||||
{
|
||||
$table = new Table("foo");
|
||||
$column = $table->addColumn("id", 'integer', array('notnull' => false));
|
||||
|
||||
$this->assertFalse($column->getNotnull());
|
||||
|
||||
$table->setPrimaryKey(array('id'));
|
||||
|
||||
$this->assertTrue($column->getNotnull());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-133
|
||||
*/
|
||||
public function testAllowImplicitSchemaTableInAutogeneratedIndexNames()
|
||||
{
|
||||
$table = new Table("foo.bar");
|
||||
$table->addColumn('baz', 'integer', array());
|
||||
$table->addIndex(array('baz'));
|
||||
|
||||
$this->assertEquals(1, count($table->getIndexes()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-50
|
||||
*/
|
||||
public function testAddIndexTwice_IgnoreSecond()
|
||||
{
|
||||
$table = new Table("foo.bar");
|
||||
$table->addColumn('baz', 'integer', array());
|
||||
$table->addIndex(array('baz'));
|
||||
$table->addIndex(array('baz'));
|
||||
|
||||
$this->assertEquals(1, count($table->getIndexes()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-50
|
||||
*/
|
||||
public function testAddForeignKeyIndexImplicitly()
|
||||
{
|
||||
$table = new Table("foo");
|
||||
$table->addColumn("id", 'integer');
|
||||
|
||||
$foreignTable = new Table("bar");
|
||||
$foreignTable->addColumn("id", 'integer');
|
||||
|
||||
$table->addForeignKeyConstraint($foreignTable, array("id"), array("id"), array("foo" => "bar"));
|
||||
|
||||
$indexes = $table->getIndexes();
|
||||
$this->assertEquals(1, count($indexes));
|
||||
$index = current($indexes);
|
||||
|
||||
$this->assertTrue($table->hasIndex($index->getName()));
|
||||
$this->assertEquals(array('id'), $index->getColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-50
|
||||
*/
|
||||
public function testOverruleIndex()
|
||||
{
|
||||
$table = new Table("bar");
|
||||
$table->addColumn('baz', 'integer', array());
|
||||
$table->addIndex(array('baz'));
|
||||
|
||||
$indexes = $table->getIndexes();
|
||||
$this->assertEquals(1, count($indexes));
|
||||
$index = current($indexes);
|
||||
|
||||
$table->addUniqueIndex(array('baz'));
|
||||
$this->assertEquals(1, count($table->getIndexes()));
|
||||
$this->assertFalse($table->hasIndex($index->getName()));
|
||||
}
|
||||
|
||||
public function testPrimaryKeyOverrulesUniqueIndex()
|
||||
{
|
||||
$table = new Table("bar");
|
||||
$table->addColumn('baz', 'integer', array());
|
||||
$table->addUniqueIndex(array('baz'));
|
||||
|
||||
$table->setPrimaryKey(array('baz'));
|
||||
|
||||
$indexes = $table->getIndexes();
|
||||
$this->assertEquals(1, count($indexes), "Table should only contain the primary key table index, not the unique one anymore, because it was overruled.");
|
||||
|
||||
$index = current($indexes);
|
||||
$this->assertTrue($index->isPrimary());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-64
|
||||
*/
|
||||
public function testQuotedTableName()
|
||||
{
|
||||
$table = new Table("`bar`");
|
||||
|
||||
$mysqlPlatform = new \Doctrine\DBAL\Platforms\MySqlPlatform();
|
||||
$sqlitePlatform = new \Doctrine\DBAL\Platforms\SqlitePlatform();
|
||||
|
||||
$this->assertEquals('bar', $table->getName());
|
||||
$this->assertEquals('`bar`', $table->getQuotedName($mysqlPlatform));
|
||||
$this->assertEquals('"bar"', $table->getQuotedName($sqlitePlatform));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-79
|
||||
*/
|
||||
public function testTableHasPrimaryKey()
|
||||
{
|
||||
$table = new Table("test");
|
||||
|
||||
$this->assertFalse($table->hasPrimaryKey());
|
||||
|
||||
$table->addColumn("foo", "integer");
|
||||
$table->setPrimaryKey(array("foo"));
|
||||
|
||||
$this->assertTrue($table->hasPrimaryKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-91
|
||||
*/
|
||||
public function testAddIndexWithQuotedColumns()
|
||||
{
|
||||
$table = new Table("test");
|
||||
$table->addColumn('"foo"', 'integer');
|
||||
$table->addColumn('bar', 'integer');
|
||||
$table->addIndex(array('"foo"', '"bar"'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-91
|
||||
*/
|
||||
public function testAddForeignKeyWithQuotedColumnsAndTable()
|
||||
{
|
||||
$table = new Table("test");
|
||||
$table->addColumn('"foo"', 'integer');
|
||||
$table->addColumn('bar', 'integer');
|
||||
$table->addForeignKeyConstraint('"boing"', array('"foo"', '"bar"'), array("id"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-177
|
||||
*/
|
||||
public function testQuoteSchemaPrefixed()
|
||||
{
|
||||
$table = new Table("`test`.`test`");
|
||||
$this->assertEquals("test.test", $table->getName());
|
||||
$this->assertEquals("`test`.`test`", $table->getQuotedName(new \Doctrine\DBAL\Platforms\MySqlPlatform));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-204
|
||||
*/
|
||||
public function testFullQualifiedTableName()
|
||||
{
|
||||
$table = new Table("`test`.`test`");
|
||||
$this->assertEquals('test.test', $table->getFullQualifiedName("test"));
|
||||
$this->assertEquals('test.test', $table->getFullQualifiedName("other"));
|
||||
|
||||
$table = new Table("test");
|
||||
$this->assertEquals('test.test', $table->getFullQualifiedName("test"));
|
||||
$this->assertEquals('other.test', $table->getFullQualifiedName("other"));
|
||||
}
|
||||
}
|
77
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php
vendored
Normal file
77
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Schema\Visitor;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\SchemaConfig;
|
||||
use Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets;
|
||||
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||
|
||||
class RemoveNamespacedAssetsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @group DBAL-204
|
||||
*/
|
||||
public function testRemoveNamespacedAssets()
|
||||
{
|
||||
$config = new SchemaConfig;
|
||||
$config->setName("test");
|
||||
$schema = new Schema(array(), array(), $config);
|
||||
|
||||
$schema->createTable("test.test");
|
||||
$schema->createTable("foo.bar");
|
||||
$schema->createTable("baz");
|
||||
|
||||
$schema->visit(new RemoveNamespacedAssets());
|
||||
|
||||
$tables = $schema->getTables();
|
||||
$this->assertEquals(array("test.test", "test.baz"), array_keys($tables), "Only 2 tables should be present, both in 'test' namespace.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-204
|
||||
*/
|
||||
public function testCleanupForeignKeys()
|
||||
{
|
||||
$config = new SchemaConfig;
|
||||
$config->setName("test");
|
||||
$schema = new Schema(array(), array(), $config);
|
||||
|
||||
$fooTable = $schema->createTable("foo.bar");
|
||||
$fooTable->addColumn('id', 'integer');
|
||||
|
||||
$testTable = $schema->createTable("test.test");
|
||||
$testTable->addColumn('id', 'integer');
|
||||
|
||||
$testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id"));
|
||||
|
||||
$schema->visit(new RemoveNamespacedAssets());
|
||||
|
||||
$sql = $schema->toSql(new MySqlPlatform());
|
||||
$this->assertEquals(1, count($sql), "Just one CREATE TABLE statement, no foreign key and table to foo.bar");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-204
|
||||
*/
|
||||
public function testCleanupForeignKeysDifferentOrder()
|
||||
{
|
||||
$config = new SchemaConfig;
|
||||
$config->setName("test");
|
||||
$schema = new Schema(array(), array(), $config);
|
||||
|
||||
$testTable = $schema->createTable("test.test");
|
||||
$testTable->addColumn('id', 'integer');
|
||||
|
||||
$fooTable = $schema->createTable("foo.bar");
|
||||
$fooTable->addColumn('id', 'integer');
|
||||
|
||||
$testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id"));
|
||||
|
||||
$schema->visit(new RemoveNamespacedAssets());
|
||||
|
||||
$sql = $schema->toSql(new MySqlPlatform());
|
||||
$this->assertEquals(1, count($sql), "Just one CREATE TABLE statement, no foreign key and table to foo.bar");
|
||||
}
|
||||
}
|
||||
|
80
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php
vendored
Normal file
80
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Schema\Visitor;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
class SchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCreateSchema()
|
||||
{
|
||||
$platformMock = $this->getMock(
|
||||
'Doctrine\DBAL\Platforms\MySqlPlatform',
|
||||
array('getCreateTableSql', 'getCreateSequenceSql', 'getCreateForeignKeySql')
|
||||
);
|
||||
$platformMock->expects($this->exactly(2))
|
||||
->method('getCreateTableSql')
|
||||
->will($this->returnValue(array("foo")));
|
||||
$platformMock->expects($this->exactly(1))
|
||||
->method('getCreateSequenceSql')
|
||||
->will($this->returnValue(array("bar")));
|
||||
$platformMock->expects($this->exactly(1))
|
||||
->method('getCreateForeignKeySql')
|
||||
->will($this->returnValue(array("baz")));
|
||||
|
||||
$schema = $this->createFixtureSchema();
|
||||
|
||||
$sql = $schema->toSql($platformMock);
|
||||
|
||||
$this->assertEquals(array("foo", "foo", "bar", "baz"), $sql);
|
||||
}
|
||||
|
||||
public function testDropSchema()
|
||||
{
|
||||
$platformMock = $this->getMock(
|
||||
'Doctrine\DBAL\Platforms\MySqlPlatform',
|
||||
array('getDropTableSql', 'getDropSequenceSql', 'getDropForeignKeySql')
|
||||
);
|
||||
$platformMock->expects($this->exactly(2))
|
||||
->method('getDropTableSql')
|
||||
->will($this->returnValue("tbl"));
|
||||
$platformMock->expects($this->exactly(1))
|
||||
->method('getDropSequenceSql')
|
||||
->will($this->returnValue("seq"));
|
||||
$platformMock->expects($this->exactly(1))
|
||||
->method('getDropForeignKeySql')
|
||||
->will($this->returnValue("fk"));
|
||||
|
||||
$schema = $this->createFixtureSchema();
|
||||
|
||||
$sql = $schema->toDropSql($platformMock);
|
||||
|
||||
$this->assertEquals(array("fk", "seq", "tbl", "tbl"), $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Schema
|
||||
*/
|
||||
public function createFixtureSchema()
|
||||
{
|
||||
$schema = new Schema();
|
||||
$tableA = $schema->createTable("foo");
|
||||
$tableA->addColumn("id", 'integer');
|
||||
$tableA->addColumn("bar", 'string', array('length' => 255));
|
||||
$tableA->setPrimaryKey(array("id"));
|
||||
|
||||
$schema->createSequence("foo_seq");
|
||||
|
||||
$tableB = $schema->createTable("bar");
|
||||
$tableB->addColumn("id", 'integer');
|
||||
$tableB->setPrimaryKey(array("id"));
|
||||
|
||||
$tableA->addForeignKeyConstraint($tableB, array("bar"), array("id"));
|
||||
|
||||
return $schema;
|
||||
}
|
||||
}
|
61
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php
vendored
Normal file
61
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class ArrayTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('array');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
error_reporting(-1); // reactive all error levels
|
||||
}
|
||||
|
||||
|
||||
public function testArrayConvertsToDatabaseValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
is_string($this->_type->convertToDatabaseValue(array(), $this->_platform))
|
||||
);
|
||||
}
|
||||
|
||||
public function testArrayConvertsToPHPValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
is_array($this->_type->convertToPHPValue(serialize(array()), $this->_platform))
|
||||
);
|
||||
}
|
||||
|
||||
public function testConversionFailure()
|
||||
{
|
||||
error_reporting( (E_ALL | E_STRICT) - \E_NOTICE );
|
||||
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
|
||||
$this->_type->convertToPHPValue('abcdefg', $this->_platform);
|
||||
}
|
||||
|
||||
public function testNullConversion()
|
||||
{
|
||||
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-73
|
||||
*/
|
||||
public function testFalseConversion()
|
||||
{
|
||||
$this->assertFalse($this->_type->convertToPHPValue(serialize(false), $this->_platform));
|
||||
}
|
||||
}
|
26
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/BlobTest.php
vendored
Normal file
26
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/BlobTest.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class BlobTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('blob');
|
||||
}
|
||||
|
||||
public function testBlobNullConvertsToPHPValue()
|
||||
{
|
||||
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
|
||||
}
|
||||
}
|
36
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php
vendored
Normal file
36
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class BooleanTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('boolean');
|
||||
}
|
||||
|
||||
public function testBooleanConvertsToDatabaseValue()
|
||||
{
|
||||
$this->assertInternalType('integer', $this->_type->convertToDatabaseValue(1, $this->_platform));
|
||||
}
|
||||
|
||||
public function testBooleanConvertsToPHPValue()
|
||||
{
|
||||
$this->assertInternalType('bool', $this->_type->convertToPHPValue(0, $this->_platform));
|
||||
}
|
||||
|
||||
public function testBooleanNullConvertsToPHPValue()
|
||||
{
|
||||
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
|
||||
}
|
||||
}
|
75
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/DateTest.php
vendored
Normal file
75
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/DateTest.php
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class DateTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type,
|
||||
$_tz;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('date');
|
||||
$this->_tz = date_default_timezone_get();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
date_default_timezone_set($this->_tz);
|
||||
}
|
||||
|
||||
public function testDateConvertsToDatabaseValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
is_string($this->_type->convertToDatabaseValue(new \DateTime(), $this->_platform))
|
||||
);
|
||||
}
|
||||
|
||||
public function testDateConvertsToPHPValue()
|
||||
{
|
||||
// Birthday of jwage and also birthday of Doctrine. Send him a present ;)
|
||||
$this->assertTrue(
|
||||
$this->_type->convertToPHPValue('1985-09-01', $this->_platform)
|
||||
instanceof \DateTime
|
||||
);
|
||||
}
|
||||
|
||||
public function testDateResetsNonDatePartsToZeroUnixTimeValues()
|
||||
{
|
||||
$date = $this->_type->convertToPHPValue('1985-09-01', $this->_platform);
|
||||
|
||||
$this->assertEquals('00:00:00', $date->format('H:i:s'));
|
||||
}
|
||||
|
||||
public function testDateRests_SummerTimeAffection()
|
||||
{
|
||||
date_default_timezone_set('Europe/Berlin');
|
||||
|
||||
$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);
|
||||
$this->assertEquals('00:00:00', $date->format('H:i:s'));
|
||||
$this->assertEquals('2009-11-01', $date->format('Y-m-d'));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
50
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php
vendored
Normal file
50
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class DateTimeTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('datetime');
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
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);
|
||||
$this->assertInstanceOf('DateTime', $date);
|
||||
$this->assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
50
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php
vendored
Normal file
50
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class DateTimeTzTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('datetimetz');
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
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);
|
||||
$this->assertInstanceOf('DateTime', $date);
|
||||
$this->assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
31
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php
vendored
Normal file
31
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class DecimalTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('decimal');
|
||||
}
|
||||
|
||||
public function testDecimalConvertsToPHPValue()
|
||||
{
|
||||
$this->assertInternalType('string', $this->_type->convertToPHPValue('5.5', $this->_platform));
|
||||
}
|
||||
|
||||
public function testDecimalNullConvertsToPHPValue()
|
||||
{
|
||||
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
|
||||
}
|
||||
}
|
39
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/FloatTest.php
vendored
Normal file
39
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/FloatTest.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class FloatTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected $_platform, $_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('float');
|
||||
}
|
||||
|
||||
public function testFloatConvertsToPHPValue()
|
||||
{
|
||||
$this->assertInternalType('float', $this->_type->convertToPHPValue('5.5', $this->_platform));
|
||||
}
|
||||
|
||||
public function testFloatNullConvertsToPHPValue()
|
||||
{
|
||||
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
|
||||
}
|
||||
|
||||
public function testFloatConvertToDatabaseValue()
|
||||
{
|
||||
$this->assertInternalType('float', $this->_type->convertToDatabaseValue(5.5, $this->_platform));
|
||||
}
|
||||
|
||||
public function testFloatNullConvertToDatabaseValue()
|
||||
{
|
||||
$this->assertNull($this->_type->convertToDatabaseValue(null, $this->_platform));
|
||||
}
|
||||
}
|
32
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php
vendored
Normal file
32
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class IntegerTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('integer');
|
||||
}
|
||||
|
||||
public function testIntegerConvertsToPHPValue()
|
||||
{
|
||||
$this->assertInternalType('integer', $this->_type->convertToPHPValue('1', $this->_platform));
|
||||
$this->assertInternalType('integer', $this->_type->convertToPHPValue('0', $this->_platform));
|
||||
}
|
||||
|
||||
public function testIntegerNullConvertsToPHPValue()
|
||||
{
|
||||
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
|
||||
}
|
||||
}
|
56
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php
vendored
Normal file
56
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class ObjectTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('object');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
error_reporting(-1); // reactive all error levels
|
||||
}
|
||||
|
||||
public function testObjectConvertsToDatabaseValue()
|
||||
{
|
||||
$this->assertInternalType('string', $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform));
|
||||
}
|
||||
|
||||
public function testObjectConvertsToPHPValue()
|
||||
{
|
||||
$this->assertInternalType('object', $this->_type->convertToPHPValue(serialize(new \stdClass), $this->_platform));
|
||||
}
|
||||
|
||||
public function testConversionFailure()
|
||||
{
|
||||
error_reporting( (E_ALL | E_STRICT) - \E_NOTICE );
|
||||
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
|
||||
$this->_type->convertToPHPValue('abcdefg', $this->_platform);
|
||||
}
|
||||
|
||||
public function testNullConversion()
|
||||
{
|
||||
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-73
|
||||
*/
|
||||
public function testFalseConversion()
|
||||
{
|
||||
$this->assertFalse($this->_type->convertToPHPValue(serialize(false), $this->_platform));
|
||||
}
|
||||
}
|
32
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php
vendored
Normal file
32
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class SmallIntTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('smallint');
|
||||
}
|
||||
|
||||
public function testSmallIntConvertsToPHPValue()
|
||||
{
|
||||
$this->assertInternalType('integer', $this->_type->convertToPHPValue('1', $this->_platform));
|
||||
$this->assertInternalType('integer', $this->_type->convertToPHPValue('0', $this->_platform));
|
||||
}
|
||||
|
||||
public function testSmallIntNullConvertsToPHPValue()
|
||||
{
|
||||
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
|
||||
}
|
||||
}
|
49
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/StringTest.php
vendored
Normal file
49
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/StringTest.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class StringTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('string');
|
||||
}
|
||||
|
||||
public function testReturnsSqlDeclarationFromPlatformVarchar()
|
||||
{
|
||||
$this->assertEquals("DUMMYVARCHAR()", $this->_type->getSqlDeclaration(array(), $this->_platform));
|
||||
}
|
||||
|
||||
public function testReturnsDefaultLengthFromPlatformVarchar()
|
||||
{
|
||||
$this->assertEquals(255, $this->_type->getDefaultLength($this->_platform));
|
||||
}
|
||||
|
||||
public function testConvertToPHPValue()
|
||||
{
|
||||
$this->assertInternalType("string", $this->_type->convertToPHPValue("foo", $this->_platform));
|
||||
$this->assertInternalType("string", $this->_type->convertToPHPValue("", $this->_platform));
|
||||
}
|
||||
|
||||
public function testNullConversion()
|
||||
{
|
||||
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
|
||||
}
|
||||
|
||||
public function testSQLConversion()
|
||||
{
|
||||
$this->assertFalse($this->_type->canRequireSQLConversion(), "String type can never require SQL conversion to work.");
|
||||
$this->assertEquals('t.foo', $this->_type->convertToDatabaseValueSQL('t.foo', $this->_platform));
|
||||
$this->assertEquals('t.foo', $this->_type->convertToPHPValueSQL('t.foo', $this->_platform));
|
||||
}
|
||||
}
|
47
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/TimeTest.php
vendored
Normal file
47
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/TimeTest.php
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class TimeTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
$this->_type = Type::getType('time');
|
||||
}
|
||||
|
||||
public function testTimeConvertsToDatabaseValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
is_string($this->_type->convertToDatabaseValue(new \DateTime(), $this->_platform))
|
||||
);
|
||||
}
|
||||
|
||||
public function testTimeConvertsToPHPValue()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->_type->convertToPHPValue('5:30:55', $this->_platform)
|
||||
instanceof \DateTime
|
||||
);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
62
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php
vendored
Normal file
62
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\Tests\DBAL\Mocks;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class VarDateTimeTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
protected
|
||||
$_platform,
|
||||
$_type;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
|
||||
if (!Type::hasType('vardatetime')) {
|
||||
Type::addType('vardatetime', 'Doctrine\DBAL\Types\VarDateTimeType');
|
||||
}
|
||||
$this->_type = Type::getType('vardatetime');
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
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);
|
||||
$this->assertInstanceOf('DateTime', $date);
|
||||
$this->assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s'));
|
||||
$this->assertEquals('000000', $date->format('u'));
|
||||
}
|
||||
|
||||
public function testInvalidDateTimeFormatConversion()
|
||||
{
|
||||
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
|
||||
$this->_type->convertToPHPValue('abcdefg', $this->_platform);
|
||||
}
|
||||
|
||||
public function testConversionWithMicroseconds()
|
||||
{
|
||||
$date = $this->_type->convertToPHPValue('1985-09-01 00:00:00.123456', $this->_platform);
|
||||
$this->assertInstanceOf('DateTime', $date);
|
||||
$this->assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s'));
|
||||
$this->assertEquals('123456', $date->format('u'));
|
||||
}
|
||||
|
||||
public function testNullConversion()
|
||||
{
|
||||
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
|
||||
}
|
||||
}
|
78
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/UtilTest.php
vendored
Normal file
78
vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/UtilTest.php
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\DBAL;
|
||||
|
||||
require_once __DIR__ . '/../TestInit.php';
|
||||
|
||||
class UtilTest extends \Doctrine\Tests\DbalTestCase
|
||||
{
|
||||
static public function dataConvertPositionalToNamedParameters()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'SELECT name FROM users WHERE id = ?',
|
||||
'SELECT name FROM users WHERE id = :param1',
|
||||
array(1 => ':param1')
|
||||
),
|
||||
array(
|
||||
'SELECT name FROM users WHERE id = ? AND status = ?',
|
||||
'SELECT name FROM users WHERE id = :param1 AND status = :param2',
|
||||
array(1 => ':param1', 2 => ':param2'),
|
||||
),
|
||||
array(
|
||||
"UPDATE users SET name = '???', status = ?",
|
||||
"UPDATE users SET name = '???', status = :param1",
|
||||
array(1 => ':param1'),
|
||||
),
|
||||
array(
|
||||
"UPDATE users SET status = ?, name = '???'",
|
||||
"UPDATE users SET status = :param1, name = '???'",
|
||||
array(1 => ':param1'),
|
||||
),
|
||||
array(
|
||||
"UPDATE users SET foo = ?, name = '???', status = ?",
|
||||
"UPDATE users SET foo = :param1, name = '???', status = :param2",
|
||||
array(1 => ':param1', 2 => ':param2'),
|
||||
),
|
||||
array(
|
||||
'UPDATE users SET name = "???", status = ?',
|
||||
'UPDATE users SET name = "???", status = :param1',
|
||||
array(1 => ':param1'),
|
||||
),
|
||||
array(
|
||||
'UPDATE users SET status = ?, name = "???"',
|
||||
'UPDATE users SET status = :param1, name = "???"',
|
||||
array(1 => ':param1'),
|
||||
),
|
||||
array(
|
||||
'UPDATE users SET foo = ?, name = "???", status = ?',
|
||||
'UPDATE users SET foo = :param1, name = "???", status = :param2',
|
||||
array(1 => ':param1', 2 => ':param2'),
|
||||
),
|
||||
array(
|
||||
'SELECT * FROM users WHERE id = ? AND name = "" AND status = ?',
|
||||
'SELECT * FROM users WHERE id = :param1 AND name = "" AND status = :param2',
|
||||
array(1 => ':param1', 2 => ':param2'),
|
||||
),
|
||||
array(
|
||||
"SELECT * FROM users WHERE id = ? AND name = '' AND status = ?",
|
||||
"SELECT * FROM users WHERE id = :param1 AND name = '' AND status = :param2",
|
||||
array(1 => ':param1', 2 => ':param2'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataConvertPositionalToNamedParameters
|
||||
* @param string $inputSQL
|
||||
* @param string $expectedOutputSQL
|
||||
* @param array $expectedOutputParamsMap
|
||||
*/
|
||||
public function testConvertPositionalToNamedParameters($inputSQL, $expectedOutputSQL, $expectedOutputParamsMap)
|
||||
{
|
||||
list($statement, $params) = \Doctrine\DBAL\Driver\OCI8\OCI8Statement::convertPositionalToNamedPlaceholders($inputSQL);
|
||||
|
||||
$this->assertEquals($expectedOutputSQL, $statement);
|
||||
$this->assertEquals($expectedOutputParamsMap, $params);
|
||||
}
|
||||
}
|
77
vendor/doctrine/dbal/tests/Doctrine/Tests/DbalFunctionalTestCase.php
vendored
Normal file
77
vendor/doctrine/dbal/tests/Doctrine/Tests/DbalFunctionalTestCase.php
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests;
|
||||
|
||||
class DbalFunctionalTestCase extends DbalTestCase
|
||||
{
|
||||
/**
|
||||
* Shared connection when a TestCase is run alone (outside of it's functional suite)
|
||||
*
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
private static $_sharedConn;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $_conn;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Logging\DebugStack
|
||||
*/
|
||||
protected $_sqlLoggerStack;
|
||||
|
||||
protected function resetSharedConn()
|
||||
{
|
||||
if (self::$_sharedConn) {
|
||||
self::$_sharedConn->close();
|
||||
self::$_sharedConn = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if ( ! isset(self::$_sharedConn)) {
|
||||
self::$_sharedConn = TestUtil::getConnection();
|
||||
}
|
||||
$this->_conn = self::$_sharedConn;
|
||||
|
||||
$this->_sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack();
|
||||
$this->_conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack);
|
||||
}
|
||||
|
||||
protected function onNotSuccessfulTest(\Exception $e)
|
||||
{
|
||||
if ($e instanceof \PHPUnit_Framework_AssertionFailedError) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if(isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) {
|
||||
$queries = "";
|
||||
$i = count($this->_sqlLoggerStack->queries);
|
||||
foreach (array_reverse($this->_sqlLoggerStack->queries) AS $query) {
|
||||
$params = array_map(function($p) { if (is_object($p)) return get_class($p); else return "'".$p."'"; }, $query['params'] ?: array());
|
||||
$queries .= ($i+1).". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL;
|
||||
$i--;
|
||||
}
|
||||
|
||||
$trace = $e->getTrace();
|
||||
$traceMsg = "";
|
||||
foreach($trace AS $part) {
|
||||
if(isset($part['file'])) {
|
||||
if(strpos($part['file'], "PHPUnit/") !== false) {
|
||||
// Beginning with PHPUnit files we don't print the trace anymore.
|
||||
break;
|
||||
}
|
||||
|
||||
$traceMsg .= $part['file'].":".$part['line'].PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
$message = "[".get_class($e)."] ".$e->getMessage().PHP_EOL.PHP_EOL."With queries:".PHP_EOL.$queries.PHP_EOL."Trace:".PHP_EOL.$traceMsg;
|
||||
|
||||
throw new \Exception($message, (int)$e->getCode(), $e);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
10
vendor/doctrine/dbal/tests/Doctrine/Tests/DbalTestCase.php
vendored
Normal file
10
vendor/doctrine/dbal/tests/Doctrine/Tests/DbalTestCase.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests;
|
||||
|
||||
/**
|
||||
* Base testcase class for all dbal testcases.
|
||||
*/
|
||||
class DbalTestCase extends DoctrineTestCase
|
||||
{
|
||||
}
|
10
vendor/doctrine/dbal/tests/Doctrine/Tests/DoctrineTestCase.php
vendored
Normal file
10
vendor/doctrine/dbal/tests/Doctrine/Tests/DoctrineTestCase.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests;
|
||||
|
||||
/**
|
||||
* Base testcase class for all Doctrine testcases.
|
||||
*/
|
||||
abstract class DoctrineTestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
}
|
92
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/ConnectionMock.php
vendored
Normal file
92
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/ConnectionMock.php
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Mocks;
|
||||
|
||||
class ConnectionMock extends \Doctrine\DBAL\Connection
|
||||
{
|
||||
private $_fetchOneResult;
|
||||
private $_platformMock;
|
||||
private $_lastInsertId = 0;
|
||||
private $_inserts = array();
|
||||
|
||||
public function __construct(array $params, $driver, $config = null, $eventManager = null)
|
||||
{
|
||||
$this->_platformMock = new DatabasePlatformMock();
|
||||
|
||||
parent::__construct($params, $driver, $config, $eventManager);
|
||||
|
||||
// Override possible assignment of platform to database platform mock
|
||||
$this->_platform = $this->_platformMock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function getDatabasePlatform()
|
||||
{
|
||||
return $this->_platformMock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function insert($tableName, array $data, array $types = array())
|
||||
{
|
||||
$this->_inserts[$tableName][] = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function lastInsertId($seqName = null)
|
||||
{
|
||||
return $this->_lastInsertId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function fetchColumn($statement, array $params = array(), $colnum = 0)
|
||||
{
|
||||
return $this->_fetchOneResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function quote($input, $type = null)
|
||||
{
|
||||
if (is_string($input)) {
|
||||
return "'" . $input . "'";
|
||||
}
|
||||
return $input;
|
||||
}
|
||||
|
||||
/* Mock API */
|
||||
|
||||
public function setFetchOneResult($fetchOneResult)
|
||||
{
|
||||
$this->_fetchOneResult = $fetchOneResult;
|
||||
}
|
||||
|
||||
public function setDatabasePlatform($platform)
|
||||
{
|
||||
$this->_platformMock = $platform;
|
||||
}
|
||||
|
||||
public function setLastInsertId($id)
|
||||
{
|
||||
$this->_lastInsertId = $id;
|
||||
}
|
||||
|
||||
public function getInserts()
|
||||
{
|
||||
return $this->_inserts;
|
||||
}
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->_inserts = array();
|
||||
$this->_lastInsertId = 0;
|
||||
}
|
||||
}
|
98
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php
vendored
Normal file
98
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Mocks;
|
||||
|
||||
class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
|
||||
{
|
||||
private $_sequenceNextValSql = "";
|
||||
private $_prefersIdentityColumns = true;
|
||||
private $_prefersSequences = false;
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function getNativeDeclaration(array $field) {}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function getPortableDeclaration(array $field) {}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function prefersIdentityColumns()
|
||||
{
|
||||
return $this->_prefersIdentityColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function prefersSequences()
|
||||
{
|
||||
return $this->_prefersSequences;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
public function getSequenceNextValSQL($sequenceName)
|
||||
{
|
||||
return $this->_sequenceNextValSql;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
public function getBooleanTypeDeclarationSQL(array $field) {}
|
||||
|
||||
/** @override */
|
||||
public function getIntegerTypeDeclarationSQL(array $field) {}
|
||||
|
||||
/** @override */
|
||||
public function getBigIntTypeDeclarationSQL(array $field) {}
|
||||
|
||||
/** @override */
|
||||
public function getSmallIntTypeDeclarationSQL(array $field) {}
|
||||
|
||||
/** @override */
|
||||
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) {}
|
||||
|
||||
/** @override */
|
||||
public function getVarcharTypeDeclarationSQL(array $field) {}
|
||||
|
||||
/** @override */
|
||||
public function getClobTypeDeclarationSQL(array $field) {}
|
||||
|
||||
/* MOCK API */
|
||||
|
||||
public function setPrefersIdentityColumns($bool)
|
||||
{
|
||||
$this->_prefersIdentityColumns = $bool;
|
||||
}
|
||||
|
||||
public function setPrefersSequences($bool)
|
||||
{
|
||||
$this->_prefersSequences = $bool;
|
||||
}
|
||||
|
||||
public function setSequenceNextValSql($sql)
|
||||
{
|
||||
$this->_sequenceNextValSql = $sql;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'mock';
|
||||
}
|
||||
protected function initializeDoctrineTypeMappings() {
|
||||
}
|
||||
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
|
||||
{
|
||||
|
||||
}
|
||||
/**
|
||||
* Gets the SQL Snippet used to declare a BLOB column type.
|
||||
*/
|
||||
public function getBlobTypeDeclarationSQL(array $field)
|
||||
{
|
||||
throw DBALException::notSupported(__METHOD__);
|
||||
}
|
||||
}
|
17
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php
vendored
Normal file
17
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Mocks;
|
||||
|
||||
class DriverConnectionMock implements \Doctrine\DBAL\Driver\Connection
|
||||
{
|
||||
public function prepare($prepareString) {}
|
||||
public function query() {}
|
||||
public function quote($input, $type=\PDO::PARAM_STR) {}
|
||||
public function exec($statement) {}
|
||||
public function lastInsertId($name = null) {}
|
||||
public function beginTransaction() {}
|
||||
public function commit() {}
|
||||
public function rollBack() {}
|
||||
public function errorCode() {}
|
||||
public function errorInfo() {}
|
||||
}
|
72
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/DriverMock.php
vendored
Normal file
72
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/DriverMock.php
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Mocks;
|
||||
|
||||
|
||||
class DriverMock implements \Doctrine\DBAL\Driver
|
||||
{
|
||||
private $_platformMock;
|
||||
|
||||
private $_schemaManagerMock;
|
||||
|
||||
public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
|
||||
{
|
||||
return new DriverConnectionMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the Sqlite PDO DSN.
|
||||
*
|
||||
* @return string The DSN.
|
||||
* @override
|
||||
*/
|
||||
protected function _constructPdoDsn(array $params)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function getDatabasePlatform()
|
||||
{
|
||||
if ( ! $this->_platformMock) {
|
||||
$this->_platformMock = new DatabasePlatformMock;
|
||||
}
|
||||
return $this->_platformMock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
|
||||
{
|
||||
if($this->_schemaManagerMock == null) {
|
||||
return new SchemaManagerMock($conn);
|
||||
} else {
|
||||
return $this->_schemaManagerMock;
|
||||
}
|
||||
}
|
||||
|
||||
/* MOCK API */
|
||||
|
||||
public function setDatabasePlatform(\Doctrine\DBAL\Platforms\AbstractPlatform $platform)
|
||||
{
|
||||
$this->_platformMock = $platform;
|
||||
}
|
||||
|
||||
public function setSchemaManager(\Doctrine\DBAL\Schema\AbstractSchemaManager $sm)
|
||||
{
|
||||
$this->_schemaManagerMock = $sm;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'mock';
|
||||
}
|
||||
|
||||
public function getDatabase(\Doctrine\DBAL\Connection $conn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
101
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php
vendored
Normal file
101
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Mocks;
|
||||
|
||||
/**
|
||||
* This class is a mock of the Statement interface that can be passed in to the Hydrator
|
||||
* to test the hydration standalone with faked result sets.
|
||||
*
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class HydratorMockStatement implements \Doctrine\DBAL\Driver\Statement
|
||||
{
|
||||
private $_resultSet;
|
||||
|
||||
/**
|
||||
* Creates a new mock statement that will serve the provided fake result set to clients.
|
||||
*
|
||||
* @param array $resultSet The faked SQL result set.
|
||||
*/
|
||||
public function __construct(array $resultSet)
|
||||
{
|
||||
$this->_resultSet = $resultSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches all rows from the result set.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchAll($fetchStyle = null, $columnIndex = null, array $ctorArgs = null)
|
||||
{
|
||||
return $this->_resultSet;
|
||||
}
|
||||
|
||||
public function fetchColumn($columnNumber = 0)
|
||||
{
|
||||
$row = current($this->_resultSet);
|
||||
if ( ! is_array($row)) return false;
|
||||
$val = array_shift($row);
|
||||
return $val !== null ? $val : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the next row in the result set.
|
||||
*
|
||||
*/
|
||||
public function fetch($fetchStyle = null)
|
||||
{
|
||||
$current = current($this->_resultSet);
|
||||
next($this->_resultSet);
|
||||
return $current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the cursor, enabling the statement to be executed again.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function closeCursor()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function setResultSet(array $resultSet)
|
||||
{
|
||||
reset($resultSet);
|
||||
$this->_resultSet = $resultSet;
|
||||
}
|
||||
|
||||
public function bindColumn($column, &$param, $type = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function bindValue($param, $value, $type = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function bindParam($column, &$variable, $type = null, $length = null, $driverOptions = array())
|
||||
{
|
||||
}
|
||||
|
||||
public function columnCount()
|
||||
{
|
||||
}
|
||||
|
||||
public function errorCode()
|
||||
{
|
||||
}
|
||||
|
||||
public function errorInfo()
|
||||
{
|
||||
}
|
||||
|
||||
public function execute($params = array())
|
||||
{
|
||||
}
|
||||
|
||||
public function rowCount()
|
||||
{
|
||||
}
|
||||
}
|
13
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php
vendored
Normal file
13
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Mocks;
|
||||
|
||||
class SchemaManagerMock extends \Doctrine\DBAL\Schema\AbstractSchemaManager
|
||||
{
|
||||
public function __construct(\Doctrine\DBAL\Connection $conn)
|
||||
{
|
||||
parent::__construct($conn);
|
||||
}
|
||||
|
||||
protected function _getPortableTableColumnDefinition($tableColumn) {}
|
||||
}
|
81
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/TaskMock.php
vendored
Normal file
81
vendor/doctrine/dbal/tests/Doctrine/Tests/Mocks/TaskMock.php
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* 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 LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Tests\Mocks;
|
||||
|
||||
use Doctrine\Common\Cli\AbstractNamespace;
|
||||
|
||||
/**
|
||||
* TaskMock used for testing the CLI interface.
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
class TaskMock extends \Doctrine\Common\Cli\Tasks\AbstractTask
|
||||
{
|
||||
/**
|
||||
* Since instances of this class can be created elsewhere all instances
|
||||
* register themselves in this array for later inspection.
|
||||
*
|
||||
* @var array(TaskMock)
|
||||
*/
|
||||
static public $instances = array();
|
||||
|
||||
private $runCounter = 0;
|
||||
|
||||
/**
|
||||
* Constructor of Task Mock Object.
|
||||
* Makes sure the object can be inspected later.
|
||||
*
|
||||
* @param AbstractNamespace CLI Namespace, passed to parent constructor
|
||||
*/
|
||||
function __construct(AbstractNamespace $namespace)
|
||||
{
|
||||
self::$instances[] = $this;
|
||||
|
||||
parent::__construct($namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of times run() was called on this object.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRunCounter()
|
||||
{
|
||||
return $this->runCounter;
|
||||
}
|
||||
|
||||
/* Mock API */
|
||||
|
||||
/**
|
||||
* Method invoked by CLI to run task.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->runCounter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method supposed to generate the CLI Task Documentation
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
}
|
||||
}
|
22
vendor/doctrine/dbal/tests/Doctrine/Tests/TestInit.php
vendored
Normal file
22
vendor/doctrine/dbal/tests/Doctrine/Tests/TestInit.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/*
|
||||
* This file bootstraps the test environment.
|
||||
*/
|
||||
namespace Doctrine\Tests;
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
|
||||
require_once __DIR__ . '/../../../lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
|
||||
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Common', __DIR__ . '/../../../lib/vendor/doctrine-common/lib');
|
||||
$classLoader->register();
|
||||
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL', __DIR__ . '/../../../lib');
|
||||
$classLoader->register();
|
||||
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Tests', __DIR__ . '/../../');
|
||||
$classLoader->register();
|
||||
|
||||
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', __DIR__ . "/../../../lib/vendor");
|
||||
$classLoader->register();
|
||||
|
131
vendor/doctrine/dbal/tests/Doctrine/Tests/TestUtil.php
vendored
Normal file
131
vendor/doctrine/dbal/tests/Doctrine/Tests/TestUtil.php
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests;
|
||||
|
||||
/**
|
||||
* TestUtil is a class with static utility methods used during tests.
|
||||
*
|
||||
* @author robo
|
||||
*/
|
||||
class TestUtil
|
||||
{
|
||||
/**
|
||||
* Gets a <b>real</b> database connection using the following parameters
|
||||
* of the $GLOBALS array:
|
||||
*
|
||||
* 'db_type' : The name of the Doctrine DBAL database driver to use.
|
||||
* 'db_username' : The username to use for connecting.
|
||||
* 'db_password' : The password to use for connecting.
|
||||
* 'db_host' : The hostname of the database to connect to.
|
||||
* 'db_name' : The name of the database to connect to.
|
||||
* 'db_port' : The port of the database to connect to.
|
||||
*
|
||||
* Usually these variables of the $GLOBALS array are filled by PHPUnit based
|
||||
* on an XML configuration file. If no such parameters exist, an SQLite
|
||||
* in-memory database is used.
|
||||
*
|
||||
* IMPORTANT:
|
||||
* 1) Each invocation of this method returns a NEW database connection.
|
||||
* 2) The database is dropped and recreated to ensure it's clean.
|
||||
*
|
||||
* @return Doctrine\DBAL\Connection The database connection instance.
|
||||
*/
|
||||
public static function getConnection()
|
||||
{
|
||||
if (isset($GLOBALS['db_type'], $GLOBALS['db_username'], $GLOBALS['db_password'],
|
||||
$GLOBALS['db_host'], $GLOBALS['db_name'], $GLOBALS['db_port']) &&
|
||||
isset($GLOBALS['tmpdb_type'], $GLOBALS['tmpdb_username'], $GLOBALS['tmpdb_password'],
|
||||
$GLOBALS['tmpdb_host'], $GLOBALS['tmpdb_name'], $GLOBALS['tmpdb_port'])) {
|
||||
$realDbParams = array(
|
||||
'driver' => $GLOBALS['db_type'],
|
||||
'user' => $GLOBALS['db_username'],
|
||||
'password' => $GLOBALS['db_password'],
|
||||
'host' => $GLOBALS['db_host'],
|
||||
'dbname' => $GLOBALS['db_name'],
|
||||
'port' => $GLOBALS['db_port']
|
||||
);
|
||||
$tmpDbParams = array(
|
||||
'driver' => $GLOBALS['tmpdb_type'],
|
||||
'user' => $GLOBALS['tmpdb_username'],
|
||||
'password' => $GLOBALS['tmpdb_password'],
|
||||
'host' => $GLOBALS['tmpdb_host'],
|
||||
'dbname' => $GLOBALS['tmpdb_name'],
|
||||
'port' => $GLOBALS['tmpdb_port']
|
||||
);
|
||||
|
||||
if (isset($GLOBALS['db_unix_socket'])) {
|
||||
$realDbParams['unix_socket'] = $GLOBALS['db_unix_socket'];
|
||||
}
|
||||
|
||||
if (isset($GLOBALS['tmpdb_unix_socket'])) {
|
||||
$tmpDbParams['unix_socket'] = $GLOBALS['tmpdb_unix_socket'];
|
||||
}
|
||||
|
||||
$realConn = \Doctrine\DBAL\DriverManager::getConnection($realDbParams);
|
||||
|
||||
$platform = $realConn->getDatabasePlatform();
|
||||
|
||||
if ($platform->supportsCreateDropDatabase()) {
|
||||
$dbname = $realConn->getDatabase();
|
||||
// Connect to tmpdb in order to drop and create the real test db.
|
||||
$tmpConn = \Doctrine\DBAL\DriverManager::getConnection($tmpDbParams);
|
||||
$realConn->close();
|
||||
|
||||
$tmpConn->getSchemaManager()->dropDatabase($dbname);
|
||||
$tmpConn->getSchemaManager()->createDatabase($dbname);
|
||||
|
||||
$tmpConn->close();
|
||||
} else {
|
||||
$sm = $realConn->getSchemaManager();
|
||||
|
||||
/* @var $schema Schema */
|
||||
$schema = $sm->createSchema();
|
||||
$stmts = $schema->toDropSql($realConn->getDatabasePlatform());
|
||||
|
||||
foreach ($stmts AS $stmt) {
|
||||
$realConn->exec($stmt);
|
||||
}
|
||||
}
|
||||
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($realDbParams, null, null);
|
||||
} else {
|
||||
$params = array(
|
||||
'driver' => 'pdo_sqlite',
|
||||
'memory' => true
|
||||
);
|
||||
if (isset($GLOBALS['db_path'])) {
|
||||
$params['path'] = $GLOBALS['db_path'];
|
||||
unlink($GLOBALS['db_path']);
|
||||
}
|
||||
$conn = \Doctrine\DBAL\DriverManager::getConnection($params);
|
||||
}
|
||||
|
||||
if (isset($GLOBALS['db_event_subscribers'])) {
|
||||
$evm = $conn->getEventManager();
|
||||
foreach (explode(",", $GLOBALS['db_event_subscribers']) AS $subscriberClass) {
|
||||
$subscriberInstance = new $subscriberClass();
|
||||
$evm->addEventSubscriber($subscriberInstance);
|
||||
}
|
||||
}
|
||||
|
||||
return $conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Doctrine\DBAL\Connection
|
||||
*/
|
||||
public static function getTempConnection()
|
||||
{
|
||||
$tmpDbParams = array(
|
||||
'driver' => $GLOBALS['tmpdb_type'],
|
||||
'user' => $GLOBALS['tmpdb_username'],
|
||||
'password' => $GLOBALS['tmpdb_password'],
|
||||
'host' => $GLOBALS['tmpdb_host'],
|
||||
'dbname' => $GLOBALS['tmpdb_name'],
|
||||
'port' => $GLOBALS['tmpdb_port']
|
||||
);
|
||||
|
||||
// Connect to tmpdb in order to drop and create the real test db.
|
||||
return \Doctrine\DBAL\DriverManager::getConnection($tmpDbParams);
|
||||
}
|
||||
}
|
25
vendor/doctrine/dbal/tests/README.markdown
vendored
Normal file
25
vendor/doctrine/dbal/tests/README.markdown
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
# Running the Doctrine 2 Testsuite
|
||||
|
||||
## Setting up a PHPUnit Configuration XML
|
||||
|
||||
..
|
||||
|
||||
## Testing Lock-Support
|
||||
|
||||
The Lock support in Doctrine 2 is tested using Gearman, which allows to run concurrent tasks in parallel.
|
||||
Install Gearman with PHP as follows:
|
||||
|
||||
1. Go to http://www.gearman.org and download the latest Gearman Server
|
||||
2. Compile it and then call ldconfig
|
||||
3. Start it up "gearmand -vvvv"
|
||||
4. Install pecl/gearman by calling "gearman-beta"
|
||||
|
||||
You can then go into tests/ and start up two workers:
|
||||
|
||||
php Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php
|
||||
|
||||
Then run the locking test-suite:
|
||||
|
||||
phpunit --configuration <myconfig.xml> Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php
|
||||
|
||||
This can run considerable time, because it is using sleep() to test for the timing ranges of locks.
|
32
vendor/doctrine/dbal/tests/travis/mysql.travis.xml
vendored
Normal file
32
vendor/doctrine/dbal/tests/travis/mysql.travis.xml
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<phpunit>
|
||||
<php>
|
||||
<var name="db_type" value="pdo_mysql"/>
|
||||
<var name="db_host" value="localhost" />
|
||||
<var name="db_username" value="travis" />
|
||||
<var name="db_password" value="" />
|
||||
<var name="db_name" value="doctrine_tests" />
|
||||
<var name="db_port" value="3306"/>
|
||||
|
||||
<var name="tmpdb_type" value="pdo_mysql"/>
|
||||
<var name="tmpdb_host" value="localhost" />
|
||||
<var name="tmpdb_username" value="travis" />
|
||||
<var name="tmpdb_password" value="" />
|
||||
<var name="tmpdb_name" value="doctrine_tests_tmp" />
|
||||
<var name="tmpdb_port" value="3306"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Doctrine DBAL Test Suite">
|
||||
<directory>./../Doctrine/Tests/DBAL</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<groups>
|
||||
<exclude>
|
||||
<group>performance</group>
|
||||
<group>locking_functional</group>
|
||||
</exclude>
|
||||
</groups>
|
||||
|
||||
</phpunit>
|
||||
|
29
vendor/doctrine/dbal/tests/travis/pgsql.travis.xml
vendored
Normal file
29
vendor/doctrine/dbal/tests/travis/pgsql.travis.xml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<phpunit>
|
||||
<php>
|
||||
<var name="db_type" value="pdo_pgsql"/>
|
||||
<var name="db_host" value="localhost" />
|
||||
<var name="db_username" value="postgres" />
|
||||
<var name="db_password" value="" />
|
||||
<var name="db_name" value="doctrine_tests" />
|
||||
<var name="db_port" value="5432"/>
|
||||
|
||||
<var name="tmpdb_type" value="pdo_pgsql"/>
|
||||
<var name="tmpdb_host" value="localhost" />
|
||||
<var name="tmpdb_username" value="postgres" />
|
||||
<var name="tmpdb_password" value="" />
|
||||
<var name="tmpdb_name" value="doctrine_tests_tmp" />
|
||||
<var name="tmpdb_port" value="5432"/>
|
||||
</php>
|
||||
<testsuites>
|
||||
<testsuite name="Doctrine DBAL Test Suite">
|
||||
<directory>./../Doctrine/Tests/DBAL</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<groups>
|
||||
<exclude>
|
||||
<group>performance</group>
|
||||
<group>locking_functional</group>
|
||||
</exclude>
|
||||
</groups>
|
||||
</phpunit>
|
14
vendor/doctrine/dbal/tests/travis/sqlite.travis.xml
vendored
Normal file
14
vendor/doctrine/dbal/tests/travis/sqlite.travis.xml
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<phpunit>
|
||||
<testsuites>
|
||||
<testsuite name="Doctrine DBAL Test Suite">
|
||||
<directory>./../Doctrine/Tests/DBAL</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<groups>
|
||||
<exclude>
|
||||
<group>performance</group>
|
||||
<group>locking_functional</group>
|
||||
</exclude>
|
||||
</groups>
|
||||
</phpunit>
|
Reference in New Issue
Block a user