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 63 64 65 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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Functional\Schema;
use Doctrine\DBAL\Exception\DatabaseObjectNotFoundException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\TestUtil;
use Doctrine\DBAL\Types\BinaryType;
use Doctrine\DBAL\Types\DateTimeType;
use Doctrine\DBAL\Types\DateTimeTzType;
use Doctrine\DBAL\Types\DateType;
use Doctrine\DBAL\Types\Types;
use PHPUnit\Framework\Attributes\RequiresPhpunit;
use function array_map;
#[RequiresPhpunit('< 11.5.18')]
class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
protected function supportsPlatform(AbstractPlatform $platform): bool
{
return $platform instanceof OraclePlatform;
}
/**
* Oracle currently stores VARBINARY columns as RAW (fixed-size)
*/
protected function assertVarBinaryColumnIsValid(Table $table, string $columnName, int $expectedLength): void
{
$column = $table->getColumn($columnName);
self::assertInstanceOf(BinaryType::class, $column->getType());
self::assertSame($expectedLength, $column->getLength());
}
public function testAlterTableColumnNotNull(): void
{
$tableName = 'list_table_column_notnull';
$table = new Table($tableName);
$table->addColumn('id', Types::INTEGER);
$table->addColumn('foo', Types::INTEGER);
$table->addColumn('bar', Types::STRING, ['length' => 32]);
$table->setPrimaryKey(['id']);
$this->dropAndCreateTable($table);
$columns = $this->schemaManager->listTableColumns($tableName);
self::assertTrue($columns['id']->getNotnull());
self::assertTrue($columns['foo']->getNotnull());
self::assertTrue($columns['bar']->getNotnull());
$diffTable = clone $table;
$diffTable->modifyColumn('foo', ['notnull' => false]);
$diffTable->modifyColumn('bar', ['length' => 1024]);
$diff = $this->schemaManager->createComparator()
->compareTables($table, $diffTable);
$this->schemaManager->alterTable($diff);
$columns = $this->schemaManager->listTableColumns($tableName);
self::assertTrue($columns['id']->getNotnull());
self::assertFalse($columns['foo']->getNotnull());
self::assertTrue($columns['bar']->getNotnull());
}
public function testListTableColumnsSameTableNamesInDifferentSchemas(): void
{
$table = $this->createListTableColumns();
$this->dropAndCreateTable($table);
$otherTable = new Table($table->getName());
$otherTable->addColumn('id', Types::STRING, ['length' => 32]);
$connection = TestUtil::getPrivilegedConnection();
$schemaManager = $connection->createSchemaManager();
try {
$schemaManager->dropTable($otherTable->getName());
} catch (DatabaseObjectNotFoundException) {
}
$schemaManager->createTable($otherTable);
$connection->close();
$columns = $this->schemaManager->listTableColumns($table->getName());
self::assertCount(7, $columns);
}
public function testListTableIndexesPrimaryKeyConstraintNameDiffersFromIndexName(): void
{
$table = new Table('list_table_indexes_pk_id_test');
$table->setSchemaConfig($this->schemaManager->createSchemaConfig());
$table->addColumn('id', Types::INTEGER, ['notnull' => true]);
$table->addUniqueIndex(['id'], 'id_unique_index');
$this->dropAndCreateTable($table);
$this->schemaManager->createIndex(
new Index('id_pk_id_index', ['id'], true, true),
'list_table_indexes_pk_id_test',
);
$tableIndexes = $this->schemaManager->listTableIndexes('list_table_indexes_pk_id_test');
self::assertArrayHasKey('primary', $tableIndexes, 'listTableIndexes() has to return a "primary" array key.');
self::assertEquals(['id'], array_map('strtolower', $tableIndexes['primary']->getColumns()));
self::assertTrue($tableIndexes['primary']->isUnique());
self::assertTrue($tableIndexes['primary']->isPrimary());
}
public function testListTableDateTypeColumns(): void
{
$table = new Table('tbl_date');
$table->addColumn('col_date', Types::DATE_MUTABLE);
$table->addColumn('col_datetime', Types::DATETIME_MUTABLE);
$table->addColumn('col_datetimetz', Types::DATETIMETZ_MUTABLE);
$this->dropAndCreateTable($table);
$columns = $this->schemaManager->listTableColumns('tbl_date');
self::assertInstanceOf(DateType::class, $columns['col_date']->getType());
self::assertInstanceOf(DateTimeType::class, $columns['col_datetime']->getType());
self::assertInstanceOf(DateTimeTzType::class, $columns['col_datetimetz']->getType());
}
public function testCreateAndListSequences(): void
{
self::markTestSkipped(
"Skipped for uppercase letters are contained in sequences' names. Fix the schema manager in 3.0.",
);
}
public function testQuotedTableNameRemainsQuotedInSchema(): void
{
$table = new Table('"tester"');
$table->addColumn('"id"', Types::INTEGER);
$table->addColumn('"name"', Types::STRING, ['length' => 32]);
$this->dropAndCreateTable($table);
$schemaManager = $this->connection->createSchemaManager();
$oldSchema = $schemaManager->introspectSchema();
$newSchema = clone $oldSchema;
$newSchema->getTable('"tester"')->dropColumn('"name"');
$diff = $schemaManager->createComparator()
->compareSchemas($oldSchema, $newSchema);
$schemaManager->alterSchema($diff);
$columns = $schemaManager->listTableColumns('"tester"');
self::assertCount(1, $columns);
}
}
|