Skip to content

Commit

Permalink
Use constants for DBAL types in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys committed Apr 19, 2023
1 parent 9d601a1 commit c2938b1
Show file tree
Hide file tree
Showing 62 changed files with 1,043 additions and 919 deletions.
3 changes: 2 additions & 1 deletion tests/Functional/AutoIncrementColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Types\Types;

class AutoIncrementColumnTest extends FunctionalTestCase
{
Expand All @@ -13,7 +14,7 @@ class AutoIncrementColumnTest extends FunctionalTestCase
protected function setUp(): void
{
$table = new Table('auto_increment_table');
$table->addColumn('id', 'integer', ['autoincrement' => true]);
$table->addColumn('id', Types::INTEGER, ['autoincrement' => true]);
$table->setPrimaryKey(['id']);

$this->dropAndCreateTable($table);
Expand Down
12 changes: 8 additions & 4 deletions tests/Functional/BlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;

use function fopen;
use function str_repeat;
Expand All @@ -23,9 +24,9 @@ protected function setUp(): void
}

$table = new Table('blob_table');
$table->addColumn('id', 'integer');
$table->addColumn('clobcolumn', 'text', ['notnull' => false]);
$table->addColumn('blobcolumn', 'blob', ['notnull' => false]);
$table->addColumn('id', Types::INTEGER);
$table->addColumn('clobcolumn', Types::TEXT, ['notnull' => false]);
$table->addColumn('blobcolumn', Types::BLOB, ['notnull' => false]);
$table->setPrimaryKey(['id']);

$this->dropAndCreateTable($table);
Expand Down Expand Up @@ -173,7 +174,10 @@ private function assertBlobContains(string $text): void
{
[, $blobValue] = $this->fetchRow();

$blobValue = Type::getType('blob')->convertToPHPValue($blobValue, $this->connection->getDatabasePlatform());
$blobValue = Type::getType(Types::BLOB)->convertToPHPValue(
$blobValue,
$this->connection->getDatabasePlatform(),
);

self::assertIsResource($blobValue);
self::assertEquals($text, stream_get_contents($blobValue));
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public function testExceptionOnPrepareAndExecute(): void
private function createTestTable(): void
{
$table = new Table(self::TABLE);
$table->addColumn('id', 'integer');
$table->addColumn('id', Types::INTEGER);
$table->setPrimaryKey(['id']);

$this->dropAndCreateTable($table);
Expand Down
10 changes: 5 additions & 5 deletions tests/Functional/DataAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class DataAccessTest extends FunctionalTestCase
protected function setUp(): void
{
$table = new Table('fetch_table');
$table->addColumn('test_int', 'integer');
$table->addColumn('test_string', 'string');
$table->addColumn('test_datetime', 'datetime', ['notnull' => false]);
$table->addColumn('test_int', Types::INTEGER);
$table->addColumn('test_string', Types::STRING);
$table->addColumn('test_datetime', Types::DATETIME_MUTABLE, ['notnull' => false]);
$table->setPrimaryKey(['test_int']);

$this->dropAndCreateTable($table);
Expand Down Expand Up @@ -438,8 +438,8 @@ public function testSqliteDateArithmeticWithDynamicInterval(): void
}

$table = new Table('fetch_table_date_math');
$table->addColumn('test_date', 'date');
$table->addColumn('test_days', 'integer');
$table->addColumn('test_date', Types::DATE_MUTABLE);
$table->addColumn('test_days', Types::INTEGER);
$table->setPrimaryKey(['test_date']);

$sm = $this->connection->getSchemaManager();
Expand Down
5 changes: 3 additions & 2 deletions tests/Functional/Driver/OCI8/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;
use Doctrine\DBAL\Types\Types;

/** @requires extension oci8 */
class ConnectionTest extends FunctionalTestCase
Expand All @@ -21,8 +22,8 @@ protected function setUp(): void
public function testLastInsertIdAcceptsFqn(): void
{
$table = new Table('DBAL2595');
$table->addColumn('id', 'integer', ['autoincrement' => true]);
$table->addColumn('foo', 'integer');
$table->addColumn('id', Types::INTEGER, ['autoincrement' => true]);
$table->addColumn('foo', Types::INTEGER);

$this->dropAndCreateTable($table);

Expand Down
27 changes: 14 additions & 13 deletions tests/Functional/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;
use Doctrine\DBAL\Types\Types;
use Throwable;

use function array_merge;
Expand All @@ -32,7 +33,7 @@ class ExceptionTest extends FunctionalTestCase
public function testPrimaryConstraintViolationException(): void
{
$table = new Table('duplicatekey_table');
$table->addColumn('id', 'integer', []);
$table->addColumn('id', Types::INTEGER, []);
$table->setPrimaryKey(['id']);
$this->dropAndCreateTable($table);

Expand All @@ -54,7 +55,7 @@ public function testTableExistsException(): void
{
$schemaManager = $this->connection->getSchemaManager();
$table = new Table('alreadyexist_table');
$table->addColumn('id', 'integer', []);
$table->addColumn('id', Types::INTEGER, []);
$table->setPrimaryKey(['id']);

$this->expectException(Exception\TableExistsException::class);
Expand Down Expand Up @@ -187,8 +188,8 @@ public function testForeignKeyConstraintViolationExceptionOnTruncate(): void
public function testNotNullConstraintViolationException(): void
{
$table = new Table('notnull_table');
$table->addColumn('id', 'integer', []);
$table->addColumn('val', 'integer', ['notnull' => true]);
$table->addColumn('id', Types::INTEGER, []);
$table->addColumn('val', Types::INTEGER, ['notnull' => true]);
$table->setPrimaryKey(['id']);
$this->dropAndCreateTable($table);

Expand All @@ -199,7 +200,7 @@ public function testNotNullConstraintViolationException(): void
public function testInvalidFieldNameException(): void
{
$table = new Table('bad_columnname_table');
$table->addColumn('id', 'integer', []);
$table->addColumn('id', Types::INTEGER, []);
$this->dropAndCreateTable($table);

// prevent the PHPUnit error handler from handling the warning that db2_bind_param() may trigger
Expand All @@ -212,11 +213,11 @@ public function testInvalidFieldNameException(): void
public function testNonUniqueFieldNameException(): void
{
$table1 = new Table('ambiguous_list_table_1');
$table1->addColumn('id', 'integer');
$table1->addColumn('id', Types::INTEGER);
$this->dropAndCreateTable($table1);

$table2 = new Table('ambiguous_list_table_2');
$table2->addColumn('id', 'integer');
$table2->addColumn('id', Types::INTEGER);
$this->dropAndCreateTable($table2);

$sql = 'SELECT id FROM ambiguous_list_table_1, ambiguous_list_table_2';
Expand All @@ -227,7 +228,7 @@ public function testNonUniqueFieldNameException(): void
public function testUniqueConstraintViolationException(): void
{
$table = new Table('unique_column_table');
$table->addColumn('id', 'integer');
$table->addColumn('id', Types::INTEGER);
$table->addUniqueIndex(['id']);

$this->dropAndCreateTable($table);
Expand All @@ -240,7 +241,7 @@ public function testUniqueConstraintViolationException(): void
public function testSyntaxErrorException(): void
{
$table = new Table('syntax_error_table');
$table->addColumn('id', 'integer', []);
$table->addColumn('id', Types::INTEGER, []);
$table->setPrimaryKey(['id']);

$this->dropAndCreateTable($table);
Expand Down Expand Up @@ -280,7 +281,7 @@ public function testConnectionExceptionSqLite(): void

$schema = new Schema();
$table = $schema->createTable('no_connection');
$table->addColumn('id', 'integer');
$table->addColumn('id', Types::INTEGER);

$this->expectException(Exception\ReadOnlyException::class);
$this->expectExceptionMessage(
Expand Down Expand Up @@ -354,12 +355,12 @@ private function setUpForeignKeyConstraintViolationExceptionTest(): void
$schemaManager = $this->connection->getSchemaManager();

$table = new Table('constraint_error_table');
$table->addColumn('id', 'integer', []);
$table->addColumn('id', Types::INTEGER, []);
$table->setPrimaryKey(['id']);

$owningTable = new Table('owning_table');
$owningTable->addColumn('id', 'integer', []);
$owningTable->addColumn('constraint_id', 'integer', []);
$owningTable->addColumn('id', Types::INTEGER, []);
$owningTable->addColumn('constraint_id', Types::INTEGER, []);
$owningTable->setPrimaryKey(['id']);
$owningTable->addForeignKeyConstraint($table, ['constraint_id'], ['id']);

Expand Down
5 changes: 3 additions & 2 deletions tests/Functional/LegacyAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Types\Types;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use LogicException;

Expand All @@ -20,8 +21,8 @@ class LegacyAPITest extends FunctionalTestCase
protected function setUp(): void
{
$table = new Table('legacy_table');
$table->addColumn('test_int', 'integer');
$table->addColumn('test_string', 'string');
$table->addColumn('test_int', Types::INTEGER);
$table->addColumn('test_string', Types::STRING);
$table->setPrimaryKey(['test_int']);

$this->dropAndCreateTable($table);
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/LockMode/NoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\Types;

class NoneTest extends FunctionalTestCase
{
Expand All @@ -37,7 +38,7 @@ public function setUp(): void
}

$table = new Table('users');
$table->addColumn('id', 'integer');
$table->addColumn('id', Types::INTEGER);
$table->setPrimaryKey(['id']);

$this->dropAndCreateTable($table);
Expand Down
7 changes: 4 additions & 3 deletions tests/Functional/ModifyLimitQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Types\Types;

use function array_change_key_case;
use function count;
Expand All @@ -18,12 +19,12 @@ class ModifyLimitQueryTest extends FunctionalTestCase
protected function setUp(): void
{
$table = new Table('modify_limit_table');
$table->addColumn('test_int', 'integer');
$table->addColumn('test_int', Types::INTEGER);
$table->setPrimaryKey(['test_int']);

$table2 = new Table('modify_limit_table2');
$table2->addColumn('id', 'integer', ['autoincrement' => true]);
$table2->addColumn('test_int', 'integer');
$table2->addColumn('id', Types::INTEGER, ['autoincrement' => true]);
$table2->addColumn('test_int', Types::INTEGER);
$table2->setPrimaryKey(['id']);

$this->dropAndCreateTable($table);
Expand Down
7 changes: 4 additions & 3 deletions tests/Functional/NamedParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Types\Types;
use Throwable;

use function array_change_key_case;
Expand Down Expand Up @@ -154,9 +155,9 @@ protected function setUp(): void

try {
$table = new Table('ddc1372_foobar');
$table->addColumn('id', 'integer');
$table->addColumn('foo', 'string');
$table->addColumn('bar', 'string');
$table->addColumn('id', Types::INTEGER);
$table->addColumn('foo', Types::STRING);
$table->addColumn('bar', Types::STRING);
$table->setPrimaryKey(['id']);

$sm = $this->connection->getSchemaManager();
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Platform/AlterColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class AlterColumnTest extends FunctionalTestCase
public function testColumnPositionRetainedAfterAltering(): void
{
$table = new Table('test_alter');
$table->addColumn('c1', 'integer');
$table->addColumn('c2', 'integer');
$table->addColumn('c1', Types::INTEGER);
$table->addColumn('c2', Types::INTEGER);

$this->dropAndCreateTable($table);

Expand Down
5 changes: 3 additions & 2 deletions tests/Functional/Platform/DateExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Types\Types;

use function sprintf;

Expand All @@ -13,8 +14,8 @@ class DateExpressionTest extends FunctionalTestCase
public function testDifference(string $date1, string $date2, int $expected): void
{
$table = new Table('date_expr_test');
$table->addColumn('date1', 'datetime');
$table->addColumn('date2', 'datetime');
$table->addColumn('date1', Types::DATETIME_MUTABLE);
$table->addColumn('date2', Types::DATETIME_MUTABLE);
$this->dropAndCreateTable($table);
$this->connection->insert('date_expr_test', [
'date1' => $date1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Types\Types;

final class NewPrimaryKeyWithNewAutoIncrementColumnTest extends FunctionalTestCase
{
Expand Down Expand Up @@ -39,14 +40,14 @@ public function testAlterPrimaryKeyToAutoIncrementColumn(callable $comparatorFac
$schema = $schemaManager->introspectSchema();

$table = $schema->createTable('dbal2807');
$table->addColumn('initial_id', 'integer');
$table->addColumn('initial_id', Types::INTEGER);
$table->setPrimaryKey(['initial_id']);

$schemaManager->createTable($table);

$newSchema = clone $schema;
$newTable = $newSchema->getTable($table->getName());
$newTable->addColumn('new_id', 'integer', ['autoincrement' => true]);
$newTable->addColumn('new_id', Types::INTEGER, ['autoincrement' => true]);
$newTable->dropPrimaryKey();
$newTable->setPrimaryKey(['new_id']);

Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Platform/PlatformRestrictionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Types\Types;

use function str_repeat;

Expand All @@ -23,7 +24,7 @@ public function testMaxIdentifierLengthLimitWithAutoIncrement(): void
$tableName = str_repeat('x', $platform->getMaxIdentifierLength());
$columnName = str_repeat('y', $platform->getMaxIdentifierLength());
$table = new Table($tableName);
$table->addColumn($columnName, 'integer', ['autoincrement' => true]);
$table->addColumn($columnName, Types::INTEGER, ['autoincrement' => true]);
$table->setPrimaryKey([$columnName]);
$this->dropAndCreateTable($table);
$createdTable = $this->connection->getSchemaManager()->introspectTable($tableName);
Expand Down
7 changes: 4 additions & 3 deletions tests/Functional/Platform/RenameColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Types\Types;

use function array_keys;
use function strtolower;
Expand All @@ -15,13 +16,13 @@ class RenameColumnTest extends FunctionalTestCase
public function testColumnPositionRetainedAfterRenaming(string $columnName, string $newColumnName): void
{
$table = new Table('test_rename');
$table->addColumn($columnName, 'string');
$table->addColumn('c2', 'integer');
$table->addColumn($columnName, Types::STRING);
$table->addColumn('c2', Types::INTEGER);

$this->dropAndCreateTable($table);

$table->dropColumn($columnName)
->addColumn($newColumnName, 'string');
->addColumn($newColumnName, Types::STRING);

$sm = $this->connection->createSchemaManager();
$comparator = new Comparator();
Expand Down
Loading

0 comments on commit c2938b1

Please sign in to comment.