Vendor update && Started using DoctrineMigrations
This commit is contained in:
		
							
								
								
									
										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')));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user