AbstractMySQLDriverTest.php 4.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
<?php

namespace Doctrine\Tests\DBAL\Driver;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\MySqlSchemaManager;

class AbstractMySQLDriverTest extends AbstractDriverTest
{
    public function testReturnsDatabaseName()
    {
        parent::testReturnsDatabaseName();

        $database = 'bloo';
        $params   = array(
            'user'     => 'foo',
            'password' => 'bar',
        );

        $statement = $this->getMock('Doctrine\Tests\Mocks\DriverResultStatementMock');

        $statement->expects($this->once())
            ->method('fetchColumn')
            ->will($this->returnValue($database));

        $connection = $this->getConnectionMock();

        $connection->expects($this->once())
            ->method('getParams')
            ->will($this->returnValue($params));

        $connection->expects($this->once())
            ->method('query')
            ->will($this->returnValue($statement));

        $this->assertSame($database, $this->driver->getDatabase($connection));
    }

    protected function createDriver()
    {
        return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractMySQLDriver');
    }

    protected function createPlatform()
    {
        return new MySqlPlatform();
    }

    protected function createSchemaManager(Connection $connection)
    {
        return new MySqlSchemaManager($connection);
    }

    protected function getDatabasePlatformsForVersions()
    {
        return array(
            array('5.6.9', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
            array('5.7', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
            array('5.7.0', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
            array('5.7.1', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
            array('6', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
63 64 65
            array('10.0.15-MariaDB-1~wheezy', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
            array('10.1.2a-MariaDB-a1~lenny-log', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
            array('5.5.40-MariaDB-1~wheezy', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
        );
    }

    protected function getExceptionConversionData()
    {
        return array(
            self::EXCEPTION_CONNECTION => array(
                array('1044', null, null),
                array('1045', null, null),
                array('1046', null, null),
                array('1049', null, null),
                array('1095', null, null),
                array('1142', null, null),
                array('1143', null, null),
                array('1227', null, null),
                array('1370', null, null),
                array('2002', null, null),
                array('2005', null, null),
            ),
            self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => array(
                array('1216', null, null),
                array('1217', null, null),
                array('1451', null, null),
                array('1452', null, null),
            ),
            self::EXCEPTION_INVALID_FIELD_NAME => array(
                array('1054', null, null),
                array('1166', null, null),
                array('1611', null, null),
            ),
            self::EXCEPTION_NON_UNIQUE_FIELD_NAME => array(
                array('1052', null, null),
                array('1060', null, null),
                array('1110', null, null),
            ),
            self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => array(
                array('1048', null, null),
                array('1121', null, null),
                array('1138', null, null),
                array('1171', null, null),
                array('1252', null, null),
                array('1263', null, null),
                array('1566', null, null),
            ),
            self::EXCEPTION_SYNTAX_ERROR => array(
                array('1064', null, null),
                array('1149', null, null),
                array('1287', null, null),
                array('1341', null, null),
                array('1342', null, null),
                array('1343', null, null),
                array('1344', null, null),
                array('1382', null, null),
                array('1479', null, null),
                array('1541', null, null),
                array('1554', null, null),
                array('1626', null, null),
            ),
            self::EXCEPTION_TABLE_EXISTS => array(
                array('1050', null, null),
            ),
            self::EXCEPTION_TABLE_NOT_FOUND => array(
                array('1051', null, null),
                array('1146', null, null),
            ),
            self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => array(
                array('1062', null, null),
                array('1557', null, null),
                array('1569', null, null),
                array('1586', null, null),
            ),
        );
    }
}