Got rid of or reworked the assertions which are no longer needed due to improved type system

parent ac0e13a1
......@@ -1300,7 +1300,6 @@ abstract class AbstractPlatform
if (($createFlags & self::CREATE_INDEXES) > 0) {
foreach ($table->getIndexes() as $index) {
assert($index instanceof Index);
if (! $index->isPrimary()) {
$options['indexes'][$index->getQuotedName($this)] = $index;
......
......@@ -20,7 +20,6 @@ use function array_diff;
use function array_merge;
use function array_unique;
use function array_values;
use function assert;
use function count;
use function explode;
use function implode;
......@@ -424,7 +423,6 @@ SQL
}
foreach ($diff->changedColumns as $columnDiff) {
assert($columnDiff instanceof ColumnDiff);
if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) {
continue;
}
......
......@@ -1050,10 +1050,6 @@ class SqlitePlatform extends AbstractPlatform
}
foreach ($diff->removedForeignKeys as $constraint) {
if (! $constraint instanceof ForeignKeyConstraint) {
$constraint = new Identifier($constraint);
}
$constraintName = $constraint->getName();
if ($constraintName === '') {
......
......@@ -107,8 +107,6 @@ class Comparator
}
foreach ($diff->changedTables[$localTableName]->removedForeignKeys as $key => $removedForeignKey) {
assert($removedForeignKey instanceof ForeignKeyConstraint);
// We check if the key is from the removed table if not we skip.
if ($tableName !== strtolower($removedForeignKey->getForeignTableName())) {
continue;
......
......@@ -19,7 +19,6 @@ use function array_keys;
use function array_merge;
use function array_search;
use function array_unique;
use function assert;
use function in_array;
use function is_string;
use function preg_match;
......@@ -257,7 +256,6 @@ class Table extends AbstractAsset
public function columnsAreIndexed(array $columnNames) : bool
{
foreach ($this->getIndexes() as $index) {
assert($index instanceof Index);
if ($index->spansColumns($columnNames)) {
return true;
}
......
......@@ -107,23 +107,11 @@ class ConnectionTest extends TestCase
$this->connection->isRollbackOnly();
}
public function testGetConfiguration() : void
{
$config = $this->connection->getConfiguration();
self::assertInstanceOf(Configuration::class, $config);
}
public function testGetDriver() : void
{
self::assertInstanceOf(\Doctrine\DBAL\Driver\PDOMySql\Driver::class, $this->connection->getDriver());
}
public function testGetEventManager() : void
{
self::assertInstanceOf(EventManager::class, $this->connection->getEventManager());
}
public function testConnectDispatchEvent() : void
{
$listenerMock = $this->getMockBuilder($this->getMockClass('ConnectDispatchEventListener'))
......
......@@ -53,7 +53,6 @@ class DBALExceptionTest extends TestCase
$url = 'mysql://localhost';
$exception = DriverRequired::new($url);
self::assertInstanceOf(DBALException::class, $exception);
self::assertSame(
sprintf(
'The options "driver" or "driverClass" are mandatory if a connection URL without scheme ' .
......
......@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Exception;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Exception\DriverRequired;
use PHPUnit\Framework\TestCase;
use function sprintf;
......@@ -16,7 +15,6 @@ class DriverRequiredTest extends TestCase
$url = 'mysql://localhost';
$exception = DriverRequired::new($url);
self::assertInstanceOf(DBALException::class, $exception);
self::assertSame(
sprintf(
'The options "driver" or "driverClass" are mandatory if a connection URL without scheme ' .
......
......@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Exception;
use Doctrine\DBAL\Exception\EmptyCriteriaNotAllowed;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use PHPUnit\Framework\TestCase;
class EmptyCriteriaNotAllowedTest extends TestCase
......@@ -14,7 +13,6 @@ class EmptyCriteriaNotAllowedTest extends TestCase
{
$exception = EmptyCriteriaNotAllowed::new();
self::assertInstanceOf(InvalidArgumentException::class, $exception);
self::assertSame('Empty criteria was used, expected non-empty criteria.', $exception->getMessage());
}
}
......@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Exception;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Exception\InvalidColumnIndex;
use PHPUnit\Framework\TestCase;
......@@ -14,7 +13,6 @@ class InvalidColumnIndexTest extends TestCase
{
$exception = InvalidColumnIndex::new(5, 1);
self::assertInstanceOf(DBALException::class, $exception);
self::assertSame('Invalid column index 5. The statement result contains 1 column.', $exception->getMessage());
}
......@@ -22,7 +20,6 @@ class InvalidColumnIndexTest extends TestCase
{
$exception = InvalidColumnIndex::new(5, 2);
self::assertInstanceOf(DBALException::class, $exception);
self::assertSame('Invalid column index 5. The statement result contains 2 columns.', $exception->getMessage());
}
}
......@@ -6,10 +6,8 @@ namespace Doctrine\DBAL\Tests\Functional;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ConnectionException;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Tests\FunctionalTestCase;
......@@ -41,11 +39,6 @@ class ConnectionTest extends FunctionalTestCase
$this->resetSharedConn();
}
public function testGetWrappedConnection() : void
{
self::assertInstanceOf(DriverConnection::class, $this->connection->getWrappedConnection());
}
public function testCommitWithRollbackOnlyThrowsException() : void
{
$this->connection->beginTransaction();
......@@ -346,7 +339,6 @@ class ConnectionTest extends FunctionalTestCase
$this->connection->getEventManager()
);
self::assertInstanceOf(AbstractPlatform::class, $connection->getDatabasePlatform());
self::assertFalse($connection->isConnected());
self::assertSame($params, $connection->getParams());
......
......@@ -6,7 +6,6 @@ namespace Doctrine\DBAL\Tests\Functional\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Tests\FunctionalTestCase;
abstract class AbstractDriverTest extends FunctionalTestCase
......@@ -36,9 +35,8 @@ abstract class AbstractDriverTest extends FunctionalTestCase
$user = $params['user'] ?? '';
$password = $params['password'] ?? '';
$connection = $this->driver->connect($params, $user, $password);
self::assertInstanceOf(DriverConnection::class, $connection);
$this->expectNotToPerformAssertions();
$this->driver->connect($params, $user, $password);
}
/**
......
......@@ -51,7 +51,6 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
$names = $this->schemaManager->getSchemaNames();
self::assertIsArray($names);
self::assertNotEmpty($names);
self::assertContains('public', $names, 'The public schema should be found.');
}
......@@ -143,7 +142,6 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self::assertNotNull($diff);
self::assertInstanceOf(TableDiff::class, $diff, 'There should be a difference and not false being returned from the table comparison');
self::assertEquals(['ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT'], $this->connection->getDatabasePlatform()->getAlterTableSQL($diff));
$this->schemaManager->alterTable($diff);
......@@ -380,7 +378,6 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$foundTable = false;
foreach ($tables as $table) {
self::assertInstanceOf(Table::class, $table, 'No Table instance was found in tables array.');
if (strtolower($table->getName()) !== 'list_tables_excludes_views_test_view') {
continue;
}
......
......@@ -24,7 +24,6 @@ class SQLAnywhereSchemaManagerTest extends SchemaManagerFunctionalTestCase
$views = $this->schemaManager->listViews();
self::assertCount(1, $views, 'Database has to have one view.');
self::assertInstanceOf(View::class, $views[$name]);
self::assertEquals($name, $views[$name]->getName());
self::assertRegExp('/^SELECT \* from "?DBA"?\."?view_test_table"?$/', $views[$name]->getSql());
}
......@@ -39,7 +38,6 @@ class SQLAnywhereSchemaManagerTest extends SchemaManagerFunctionalTestCase
);
$tableIndexes = $this->schemaManager->listTableIndexes('test_create_advanced_index');
self::assertIsArray($tableIndexes);
self::assertEquals('test', $tableIndexes['test']->getName());
self::assertEquals(['test'], $tableIndexes['test']->getColumns());
self::assertTrue($tableIndexes['test']->isUnique());
......
......@@ -6,7 +6,6 @@ namespace Doctrine\DBAL\Tests\Functional\Schema;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Platforms\OraclePlatform;
......@@ -126,8 +125,6 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
$connection = $this->connection->getDriver()->connect($params, $user, $password);
self::assertInstanceOf(Connection::class, $connection);
$this->schemaManager->dropDatabase('test_drop_database');
self::assertNotContains('test_drop_database', $this->schemaManager->listDatabases());
......@@ -181,12 +178,8 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
$sequence = new Sequence('list_sequences_test_seq', 20, 10);
$this->schemaManager->createSequence($sequence);
$sequences = $this->schemaManager->listSequences();
self::assertIsArray($sequences, 'listSequences() should return an array.');
$foundSequence = null;
foreach ($sequences as $sequence) {
foreach ($sequences = $this->schemaManager->listSequences() as $sequence) {
self::assertInstanceOf(Sequence::class, $sequence, 'Array elements of listSequences() should be Sequence instances.');
if (strtolower($sequence->getName()) !== 'list_sequences_test_seq') {
continue;
......@@ -242,12 +235,10 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
$this->createTestTable('list_tables_test');
$tables = $this->schemaManager->listTables();
self::assertIsArray($tables);
self::assertTrue(count($tables) > 0, "List Tables has to find at least one table named 'list_tables_test'.");
self::assertNotEmpty($tables, "List Tables has to find at least one table named 'list_tables_test'.");
$foundTable = false;
foreach ($tables as $table) {
self::assertInstanceOf(Table::class, $table);
if (strtolower($table->getName()) !== 'list_tables_test') {
continue;
}
......@@ -293,7 +284,6 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
self::assertEquals(false, $columns['id']->getunsigned());
self::assertEquals(true, $columns['id']->getnotnull());
self::assertEquals(null, $columns['id']->getdefault());
self::assertIsArray($columns['id']->getPlatformOptions());
self::assertArrayHasKey('test', $columns);
self::assertEquals(1, array_search('test', $columnsKeys));
......@@ -303,7 +293,6 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
self::assertEquals(false, $columns['test']->getFixed());
self::assertEquals(false, $columns['test']->getNotnull());
self::assertEquals('expected default', $columns['test']->getDefault());
self::assertIsArray($columns['test']->getPlatformOptions());
self::assertEquals('foo', strtolower($columns['foo']->getName()));
self::assertEquals(2, array_search('foo', $columnsKeys));
......@@ -312,7 +301,6 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
self::assertEquals(false, $columns['foo']->getFixed());
self::assertEquals(true, $columns['foo']->getNotnull());
self::assertEquals(null, $columns['foo']->getDefault());
self::assertIsArray($columns['foo']->getPlatformOptions());
self::assertEquals('bar', strtolower($columns['bar']->getName()));
self::assertEquals(3, array_search('bar', $columnsKeys));
......@@ -324,28 +312,24 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
self::assertEquals(false, $columns['bar']->getFixed());
self::assertEquals(false, $columns['bar']->getNotnull());
self::assertEquals(null, $columns['bar']->getDefault());
self::assertIsArray($columns['bar']->getPlatformOptions());
self::assertEquals('baz1', strtolower($columns['baz1']->getName()));
self::assertEquals(4, array_search('baz1', $columnsKeys));
self::assertInstanceOf(DateTimeType::class, $columns['baz1']->getType());
self::assertEquals(true, $columns['baz1']->getNotnull());
self::assertEquals(null, $columns['baz1']->getDefault());
self::assertIsArray($columns['baz1']->getPlatformOptions());
self::assertEquals('baz2', strtolower($columns['baz2']->getName()));
self::assertEquals(5, array_search('baz2', $columnsKeys));
self::assertContains($columns['baz2']->getType()->getName(), ['time', 'date', 'datetime']);
self::assertEquals(true, $columns['baz2']->getNotnull());
self::assertEquals(null, $columns['baz2']->getDefault());
self::assertIsArray($columns['baz2']->getPlatformOptions());
self::assertEquals('baz3', strtolower($columns['baz3']->getName()));
self::assertEquals(6, array_search('baz3', $columnsKeys));
self::assertContains($columns['baz3']->getType()->getName(), ['time', 'date', 'datetime']);
self::assertEquals(true, $columns['baz3']->getNotnull());
self::assertEquals(null, $columns['baz3']->getDefault());
self::assertIsArray($columns['baz3']->getPlatformOptions());
}
/**
......@@ -475,7 +459,6 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
$this->schemaManager->dropAndCreateIndex($table->getIndex('test'), $table);
$tableIndexes = $this->schemaManager->listTableIndexes('test_create_index');
self::assertIsArray($tableIndexes);
self::assertEquals('test', strtolower($tableIndexes['test']->getName()));
self::assertEquals(['test'], array_map('strtolower', $tableIndexes['test']->getColumns()));
......@@ -532,9 +515,8 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
$fkeys = $this->schemaManager->listTableForeignKeys('test_create_fk1');
self::assertEquals(1, count($fkeys), "Table 'test_create_fk1' has to have one foreign key.");
self::assertCount(1, $fkeys, "Table 'test_create_fk1' has to have one foreign key.");
self::assertInstanceOf(ForeignKeyConstraint::class, $fkeys[0]);
self::assertEquals(['foreign_key_test'], array_map('strtolower', $fkeys[0]->getLocalColumns()));
self::assertEquals(['id'], array_map('strtolower', $fkeys[0]->getForeignColumns()));
self::assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName()));
......@@ -1037,8 +1019,6 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
$foundTable = false;
foreach ($tables as $table) {
self::assertInstanceOf(Table::class, $table, 'No Table instance was found in tables array.');
if (strtolower($table->getName()) !== 'list_tables_test_new_name') {
continue;
}
......@@ -1069,9 +1049,8 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
$fkeys = $this->schemaManager->listTableForeignKeys('test_create_fk3');
self::assertEquals(1, count($fkeys), "Table 'test_create_fk3' has to have one foreign key.");
self::assertCount(1, $fkeys, "Table 'test_create_fk3' has to have one foreign key.");
self::assertInstanceOf(ForeignKeyConstraint::class, $fkeys[0]);
self::assertEquals(['id', 'foreign_key_test'], array_map('strtolower', $fkeys[0]->getLocalColumns()));
self::assertEquals(['id', 'other_id'], array_map('strtolower', $fkeys[0]->getForeignColumns()));
}
......
......@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Functional\Schema;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Table;
......@@ -58,8 +57,6 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
$connection = $this->connection->getDriver()->connect($params, $user, $password);
self::assertInstanceOf(Connection::class, $connection);
$this->schemaManager->dropDatabase('test_drop_database');
self::assertFileNotExists('test_drop_database');
......
......@@ -8,7 +8,6 @@ use Doctrine\Common\EventManager;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\Comparator;
......@@ -266,14 +265,15 @@ abstract class AbstractPlatformTestCase extends TestCase
public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys() : void
{
$fk = new ForeignKeyConstraint(['fk_name'], 'foreign', ['id'], 'constraint_fk');
if ($this->platform->supportsForeignKeyConstraints()) {
self::assertIsString($this->platform->getCreateForeignKeySQL($fk, 'test'));
} else {
$this->expectException(DBALException::class);
$this->platform->getCreateForeignKeySQL($fk, 'test');
self::markTestSkipped('The platform supports foreign key constraints');
}
$this->expectException(DBALException::class);
$this->platform->getCreateForeignKeySQL(
new ForeignKeyConstraint(['fk_name'], 'foreign', ['id'], 'constraint_fk'),
'test'
);
}
protected function getBitAndComparisonExpressionSql(string $value1, string $value2) : string
......@@ -619,7 +619,6 @@ abstract class AbstractPlatformTestCase extends TestCase
public function testKeywordList() : void
{
$keywordList = $this->platform->getReservedKeywordsList();
self::assertInstanceOf(KeywordList::class, $keywordList);
self::assertTrue($keywordList->isKeyword('table'));
}
......
......@@ -15,7 +15,6 @@ use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\Type;
use UnexpectedValueException;
use function assert;
use function sprintf;
abstract class AbstractPostgreSQLPlatformTestCase extends AbstractPlatformTestCase
......@@ -921,8 +920,6 @@ abstract class AbstractPostgreSQLPlatformTestCase extends AbstractPlatformTestCa
*/
public function testReturnsDisallowDatabaseConnectionsSQL() : void
{
assert($this->platform instanceof PostgreSQL94Platform);
self::assertSame(
"UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'foo'",
$this->platform->getDisallowDatabaseConnectionsSQL('foo')
......@@ -934,8 +931,6 @@ abstract class AbstractPostgreSQLPlatformTestCase extends AbstractPlatformTestCa
*/
public function testReturnsCloseActiveDatabaseConnectionsSQL() : void
{
assert($this->platform instanceof PostgreSQL94Platform);
self::assertSame(
"SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = 'foo'",
$this->platform->getCloseActiveDatabaseConnectionsSQL('foo')
......@@ -1024,8 +1019,6 @@ abstract class AbstractPostgreSQLPlatformTestCase extends AbstractPlatformTestCa
*/
public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() : void
{
assert($this->platform instanceof PostgreSQL94Platform);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\")
......
......@@ -8,7 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Types;
use function assert;
class PostgreSQL94PlatformTest extends AbstractPostgreSQLPlatformTestCase
{
......@@ -97,8 +96,6 @@ class PostgreSQL94PlatformTest extends AbstractPostgreSQLPlatformTestCase
*/
public function testReturnsCloseActiveDatabaseConnectionsSQL() : void
{
assert($this->platform instanceof PostgreSQL94Platform);
self::assertSame(
"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'foo'",
$this->platform->getCloseActiveDatabaseConnectionsSQL('foo')
......
......@@ -10,7 +10,6 @@ use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\MySqlSchemaManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
......@@ -42,7 +41,6 @@ class MySqlSchemaManagerTest extends TestCase
$fkeys = $this->manager->listTableForeignKeys('dummy');
self::assertCount(1, $fkeys, 'Table has to have one foreign key.');
self::assertInstanceOf(ForeignKeyConstraint::class, $fkeys[0]);
self::assertEquals(['column_1', 'column_2', 'column_3'], array_map('strtolower', $fkeys[0]->getLocalColumns()));
self::assertEquals(['column_1', 'column_2', 'column_3'], array_map('strtolower', $fkeys[0]->getForeignColumns()));
}
......
......@@ -100,7 +100,6 @@ class SchemaTest extends TestCase
$table = $schema->createTable('foo');
self::assertInstanceOf(Table::class, $table);
self::assertEquals('foo', $table->getName());
self::assertTrue($schema->hasTable('foo'));
}
......@@ -112,7 +111,7 @@ class SchemaTest extends TestCase
$schema = new Schema([], [$sequence]);
self::assertTrue($schema->hasSequence('a_seq'));
self::assertInstanceOf(Sequence::class, $schema->getSequence('a_seq'));
self::assertSame('a_seq', $schema->getSequence('a_seq')->getName());
$sequences = $schema->getSequences();
self::assertArrayHasKey('public.a_seq', $sequences);
......@@ -150,7 +149,7 @@ class SchemaTest extends TestCase
self::assertEquals(20, $sequence->getInitialValue());
self::assertTrue($schema->hasSequence('a_seq'));
self::assertInstanceOf(Sequence::class, $schema->getSequence('a_seq'));
self::assertSame('a_seq', $schema->getSequence('a_seq')->getName());
$sequences = $schema->getSequences();
self::assertArrayHasKey('public.a_seq', $sequences);
......
......@@ -46,8 +46,8 @@ class TableTest extends TestCase
self::assertTrue($table->hasColumn('bar'));
self::assertFalse($table->hasColumn('baz'));
self::assertInstanceOf(Column::class, $table->getColumn('foo'));
self::assertInstanceOf(Column::class, $table->getColumn('bar'));
self::assertSame('foo', $table->getColumn('foo')->getName());
self::assertSame('bar', $table->getColumn('bar')->getName());
self::assertCount(2, $table->getColumns());
}
......@@ -161,9 +161,9 @@ class TableTest extends TestCase
self::assertTrue($table->hasIndex('bar_idx'));
self::assertFalse($table->hasIndex('some_idx'));
self::assertInstanceOf(Index::class, $table->getPrimaryKey());
self::assertInstanceOf(Index::class, $table->getIndex('the_primary'));
self::assertInstanceOf(Index::class, $table->getIndex('bar_idx'));
self::assertNotNull($table->getPrimaryKey());
self::assertSame('the_primary', $table->getIndex('the_primary')->getName());
self::assertSame('bar_idx', $table->getIndex('bar_idx')->getName());
}
public function testGetUnknownIndexThrowsException() : void
......@@ -833,18 +833,12 @@ class TableTest extends TestCase
self::assertTrue($table->hasColumn($assetName));
self::assertTrue($table->hasColumn('foo'));
self::assertInstanceOf(Column::class, $table->getColumn($assetName));
self::assertInstanceOf(Column::class, $table->getColumn('foo'));
self::assertTrue($table->hasIndex($assetName));
self::assertTrue($table->hasIndex('foo'));
self::assertInstanceOf(Index::class, $table->getIndex($assetName));
self::assertInstanceOf(Index::class, $table->getIndex('foo'));
self::assertTrue($table->hasForeignKey($assetName));
self::assertTrue($table->hasForeignKey('foo'));
self::assertInstanceOf(ForeignKeyConstraint::class, $table->getForeignKey($assetName));
self::assertInstanceOf(ForeignKeyConstraint::class, $table->getForeignKey('foo'));
$table->renameIndex($assetName, $assetName);
self::assertTrue($table->hasIndex($assetName));
......
......@@ -30,8 +30,6 @@ abstract class BaseDateTypeTestCase extends TestCase
{
$this->platform = $this->getMockForAbstractClass(AbstractPlatform::class);
$this->currentTimezone = date_default_timezone_get();
self::assertInstanceOf(Type::class, $this->type);
}
protected function tearDown() : void
......
......@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Types;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Exception\InvalidFormat;
use Doctrine\DBAL\Types\Exception\InvalidType;
use Doctrine\DBAL\Types\Exception\ValueNotConvertible;
......@@ -25,7 +24,6 @@ class ConversionExceptionTest extends TestCase
$exception = ValueNotConvertible::new('foo', 'foo', null, $previous);
self::assertInstanceOf(ConversionException::class, $exception);
self::assertSame($previous, $exception->getPrevious());
}
......@@ -40,7 +38,6 @@ class ConversionExceptionTest extends TestCase
$type = is_object($scalarValue) ? get_class($scalarValue) : gettype($scalarValue);
self::assertInstanceOf(ConversionException::class, $exception);
self::assertSame(
sprintf(
'Could not convert PHP value "%s" of type "%s" to type "foo". Expected one of the following types: bar, baz.',
......@@ -62,7 +59,6 @@ class ConversionExceptionTest extends TestCase
$type = is_object($nonScalar) ? get_class($nonScalar) : gettype($nonScalar);
self::assertInstanceOf(ConversionException::class, $exception);
self::assertSame(
sprintf('Could not convert PHP value of type "%s" to type "foo". Expected one of the following types: bar, baz.', $type),
$exception->getMessage()
......@@ -75,7 +71,6 @@ class ConversionExceptionTest extends TestCase
$exception = InvalidType::new('foo', 'foo', ['bar', 'baz'], $previous);
self::assertInstanceOf(ConversionException::class, $exception);
self::assertSame($previous, $exception->getPrevious());
}
......@@ -85,7 +80,6 @@ class ConversionExceptionTest extends TestCase
$exception = InvalidFormat::new('foo', 'bar', 'baz', $previous);
self::assertInstanceOf(ConversionException::class, $exception);
self::assertSame($previous, $exception->getPrevious());
}
......
......@@ -5,10 +5,8 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Types\Exception;
use Doctrine\DBAL\Types\Exception\TypeAlreadyRegistered;
use Doctrine\DBAL\Types\Exception\TypesException;
use Doctrine\DBAL\Types\Type;
use PHPUnit\Framework\TestCase;
use function preg_match;
class TypeAlreadyRegisteredTest extends TestCase
{
......@@ -16,7 +14,9 @@ class TypeAlreadyRegisteredTest extends TestCase
{
$exception = TypeAlreadyRegistered::new(Type::getType('string'));
self::assertInstanceOf(TypesException::class, $exception);
self::assertTrue(preg_match('/Type of the class Doctrine\\\DBAL\\\Types\\\StringType@([0-9a-zA-Z]+) is already registered./', $exception->getMessage()) === 1);
self::assertRegExp(
'/Type of the class Doctrine\\\DBAL\\\Types\\\StringType@([0-9a-zA-Z]+) is already registered./',
$exception->getMessage()
);
}
}
......@@ -5,10 +5,8 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Types\Exception;
use Doctrine\DBAL\Types\Exception\TypeNotRegistered;
use Doctrine\DBAL\Types\Exception\TypesException;
use Doctrine\DBAL\Types\Type;
use PHPUnit\Framework\TestCase;
use function preg_match;
class TypeNotRegisteredTest extends TestCase
{
......@@ -16,7 +14,9 @@ class TypeNotRegisteredTest extends TestCase
{
$exception = TypeNotRegistered::new(Type::getType('string'));
self::assertInstanceOf(TypesException::class, $exception);
self::assertTrue(preg_match('/Type of the class Doctrine\\\DBAL\\\Types\\\StringType@([0-9a-zA-Z]+) is not registered./', $exception->getMessage()) === 1);
self::assertRegExp(
'/Type of the class Doctrine\\\DBAL\\\Types\\\StringType@([0-9a-zA-Z]+) is not registered./',
$exception->getMessage()
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment