Fix risky tests

parent 5ad704e9
...@@ -108,12 +108,8 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -108,12 +108,8 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
} }
$this->_conn->beginTransaction(); $this->_conn->beginTransaction();
try { $this->expectException(ConnectionException::class);
$this->_conn->setNestTransactionsWithSavepoints(true); $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() public function testSetNestedTransactionsThroughSavepointsNotSupportedThrowsException()
...@@ -228,17 +224,20 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -228,17 +224,20 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testTransactional() public function testTransactional()
{ {
$this->_conn->transactional(function($conn) { $res = $this->_conn->transactional(function($conn) {
/* @var $conn \Doctrine\DBAL\Connection */ /* @var $conn \Doctrine\DBAL\Connection */
$conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL());
}); });
self::assertNull($res);
} }
public function testTransactionalReturnValue() public function testTransactionalReturnValue()
{ {
$res = $this->_conn->transactional(function($conn) { $res = $this->_conn->transactional(function() {
return 42; return 42;
}); });
$this->assertEquals(42, $res); $this->assertEquals(42, $res);
} }
......
...@@ -771,9 +771,11 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -771,9 +771,11 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
*/ */
public function testEmptyFetchColumnReturnsFalse() public function testEmptyFetchColumnReturnsFalse()
{ {
$this->_conn->beginTransaction();
$this->_conn->exec('DELETE FROM fetch_table'); $this->_conn->exec('DELETE FROM fetch_table');
$this->assertFalse($this->_conn->fetchColumn('SELECT test_int FROM fetch_table')); $this->assertFalse($this->_conn->fetchColumn('SELECT test_int FROM fetch_table'));
$this->assertFalse($this->_conn->query('SELECT test_int FROM fetch_table')->fetchColumn()); $this->assertFalse($this->_conn->query('SELECT test_int FROM fetch_table')->fetchColumn());
$this->_conn->rollBack();
} }
/** /**
...@@ -785,10 +787,11 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -785,10 +787,11 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$stmt = $this->_conn->executeQuery($sql, array(1, "foo")); $stmt = $this->_conn->executeQuery($sql, array(1, "foo"));
$stmt->setFetchMode(\PDO::FETCH_NUM); $stmt->setFetchMode(\PDO::FETCH_NUM);
while ($row = $stmt->fetch()) { $row = $stmt->fetch();
$this->assertTrue(isset($row[0]));
$this->assertTrue(isset($row[1])); self::assertArrayHasKey(0, $row);
} self::assertArrayHasKey(1, $row);
self::assertFalse($stmt->fetch());
} }
/** /**
...@@ -810,11 +813,11 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -810,11 +813,11 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
{ {
$this->_conn->executeUpdate( $this->_conn->executeUpdate(
'INSERT INTO fetch_table (test_int, test_string) VALUES (?, ?)', 'INSERT INTO fetch_table (test_int, test_string) VALUES (?, ?)',
array(1, 'foo') array(2, 'foo')
); );
$this->assertNull( $this->assertNull(
$this->_conn->fetchColumn('SELECT test_datetime FROM fetch_table WHERE test_int = ?', array(1)) $this->_conn->fetchColumn('SELECT test_datetime FROM fetch_table WHERE test_int = ?', array(2))
); );
} }
......
...@@ -24,7 +24,6 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -24,7 +24,6 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$tableOld = new Table("switch_primary_key_columns"); $tableOld = new Table("switch_primary_key_columns");
$tableOld->addColumn('foo_id', 'integer'); $tableOld->addColumn('foo_id', 'integer');
$tableOld->addColumn('bar_id', 'integer'); $tableOld->addColumn('bar_id', 'integer');
$tableNew = clone $tableOld;
$this->_sm->createTable($tableOld); $this->_sm->createTable($tableOld);
$tableFetched = $this->_sm->listTableDetails("switch_primary_key_columns"); $tableFetched = $this->_sm->listTableDetails("switch_primary_key_columns");
...@@ -33,6 +32,13 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -33,6 +32,13 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$comparator = new Comparator; $comparator = new Comparator;
$this->_sm->alterTable($comparator->diffTable($tableFetched, $tableNew)); $this->_sm->alterTable($comparator->diffTable($tableFetched, $tableNew));
$table = $this->_sm->listTableDetails('switch_primary_key_columns');
$primaryKey = $table->getPrimaryKeyColumns();
self::assertCount(2, $primaryKey);
self::assertContains('bar_id', $primaryKey);
self::assertContains('foo_id', $primaryKey);
} }
public function testDiffTableBug() public function testDiffTableBug()
......
...@@ -83,12 +83,27 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -83,12 +83,27 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
*/ */
public function testDropAndCreateSequence() public function testDropAndCreateSequence()
{ {
if(!$this->_conn->getDatabasePlatform()->supportsSequences()) { if ( ! $this->_conn->getDatabasePlatform()->supportsSequences()) {
$this->markTestSkipped($this->_conn->getDriver()->getName().' does not support sequences.'); $this->markTestSkipped($this->_conn->getDriver()->getName().' does not support sequences.');
} }
$sequence = new \Doctrine\DBAL\Schema\Sequence('dropcreate_sequences_test_seq', 20, 10); $name = 'dropcreate_sequences_test_seq';
$this->_sm->dropAndCreateSequence($sequence);
$this->_sm->dropAndCreateSequence(new \Doctrine\DBAL\Schema\Sequence($name, 20, 10));
self::assertTrue($this->hasElementWithName($this->_sm->listSequences(), $name));
}
private function hasElementWithName(array $items, string $name) : bool
{
$filteredList = array_filter(
$items,
function (\Doctrine\DBAL\Schema\AbstractAsset $item) use ($name) : bool {
return $item->getShortestName($item->getNamespaceName()) === $name;
}
);
return count($filteredList) === 1;
} }
public function testListSequences() public function testListSequences()
...@@ -569,7 +584,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -569,7 +584,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->_sm->dropAndCreateView($view); $this->_sm->dropAndCreateView($view);
$views = $this->_sm->listViews(); self::assertTrue($this->hasElementWithName($this->_sm->listViews(), $name));
} }
public function testAutoincrementDetection() public function testAutoincrementDetection()
...@@ -648,6 +663,13 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -648,6 +663,13 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$tableDiff = $c->diffTable($tableFK, $tableFKNew); $tableDiff = $c->diffTable($tableFK, $tableFKNew);
$this->_sm->alterTable($tableDiff); $this->_sm->alterTable($tableDiff);
$table = $this->_sm->listTableDetails('test_fk_rename');
$foreignKeys = $table->getForeignKeys();
self::assertTrue($table->hasColumn('rename_fk_id'));
self::assertCount(1, $foreignKeys);
self::assertSame(['rename_fk_id'], array_map('strtolower', current($foreignKeys)->getColumns()));
} }
/** /**
...@@ -830,12 +852,17 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -830,12 +852,17 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
public function testListTableWithBlob() public function testListTableWithBlob()
{ {
$table = new Table('test_blob_table'); $table = new Table('test_blob_table');
$table->addColumn('id', 'integer', array('comment' => 'This is a comment')); $table->addColumn('id', 'integer', ['comment' => 'This is a comment']);
$table->addColumn('binarydata', 'blob', array()); $table->addColumn('binarydata', 'blob', []);
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(['id']);
$this->_sm->createTable($table); $this->_sm->createTable($table);
$this->_sm->listTableDetails('test_blob_table');
$created = $this->_sm->listTableDetails('test_blob_table');
self::assertTrue($created->hasColumn('id'));
self::assertTrue($created->hasColumn('binarydata'));
self::assertTrue($created->hasPrimaryKey());
} }
/** /**
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\Tests\DBAL\Platforms; namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Comparator;
...@@ -13,17 +14,17 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -13,17 +14,17 @@ class OraclePlatformTest extends AbstractPlatformTestCase
{ {
public static function dataValidIdentifiers() public static function dataValidIdentifiers()
{ {
return array( return [
array('a'), ['a'],
array('foo'), ['foo'],
array('Foo'), ['Foo'],
array('Foo123'), ['Foo123'],
array('Foo#bar_baz$'), ['Foo#bar_baz$'],
array('"a"'), ['"a"'],
array('"1"'), ['"1"'],
array('"foo_bar"'), ['"foo_bar"'],
array('"@$%&!"'), ['"@$%&!"'],
); ];
} }
/** /**
...@@ -33,17 +34,19 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -33,17 +34,19 @@ class OraclePlatformTest extends AbstractPlatformTestCase
{ {
$platform = $this->createPlatform(); $platform = $this->createPlatform();
$platform->assertValidIdentifier($identifier); $platform->assertValidIdentifier($identifier);
$this->addToAssertionCount(1);
} }
public static function dataInvalidIdentifiers() public static function dataInvalidIdentifiers()
{ {
return array( return [
array('1'), ['1'],
array('abc&'), ['abc&'],
array('abc-def'), ['abc-def'],
array('"'), ['"'],
array('"foo"bar"'), ['"foo"bar"'],
); ];
} }
/** /**
...@@ -51,7 +54,8 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -51,7 +54,8 @@ class OraclePlatformTest extends AbstractPlatformTestCase
*/ */
public function testInvalidIdentifiers($identifier) public function testInvalidIdentifiers($identifier)
{ {
$this->expectException('Doctrine\DBAL\DBALException'); $this->expectException(DBALException::class);
$platform = $this->createPlatform(); $platform = $this->createPlatform();
$platform->assertValidIdentifier($identifier); $platform->assertValidIdentifier($identifier);
} }
......
...@@ -336,25 +336,29 @@ class SqlitePlatformTest extends AbstractPlatformTestCase ...@@ -336,25 +336,29 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
$this->assertEquals($expected, $this->_platform->getAlterTableSQL($diff)); $this->assertEquals($expected, $this->_platform->getAlterTableSQL($diff));
} }
public function testAlterTableAddComplexColumns() /**
* @dataProvider complexDiffProvider
*/
public function testAlterTableAddComplexColumns(TableDiff $diff) : void
{ {
$diff = new TableDiff('user'); $this->expectException(DBALException::class);
$diff->addedColumns['time'] = new Column('time', Type::getType('date'), array('default' => 'CURRENT_DATE'));
try {
$this->_platform->getAlterTableSQL($diff); $this->_platform->getAlterTableSQL($diff);
$this->fail();
} catch (DBALException $e) {
} }
$diff = new TableDiff('user'); public function complexDiffProvider() : array
$diff->addedColumns['id'] = new Column('id', Type::getType('integer'), array('autoincrement' => true)); {
$date = new TableDiff('user');
$date->addedColumns['time'] = new Column('time', Type::getType('date'), array('default' => 'CURRENT_DATE'));
try {
$this->_platform->getAlterTableSQL($diff); $id = new TableDiff('user');
$this->fail(); $id->addedColumns['id'] = new Column('id', Type::getType('integer'), array('autoincrement' => true));
} catch (DBALException $e) {
} return [
'date column with default value' => [$date],
'id column with auto increment' => [$id],
];
} }
public function testCreateTableWithDeferredForeignKeys() public function testCreateTableWithDeferredForeignKeys()
......
...@@ -7,7 +7,6 @@ use Doctrine\DBAL\Schema\SqliteSchemaManager; ...@@ -7,7 +7,6 @@ use Doctrine\DBAL\Schema\SqliteSchemaManager;
class SqliteSchemaManagerTest extends \PHPUnit\Framework\TestCase class SqliteSchemaManagerTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @dataProvider getDataColumnCollation * @dataProvider getDataColumnCollation
*/ */
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\Tests\DBAL\Schema; namespace Doctrine\Tests\DBAL\Schema;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Index;
...@@ -12,8 +13,9 @@ class TableTest extends \Doctrine\Tests\DbalTestCase ...@@ -12,8 +13,9 @@ class TableTest extends \Doctrine\Tests\DbalTestCase
{ {
public function testCreateWithInvalidTableName() public function testCreateWithInvalidTableName()
{ {
$this->expectException('Doctrine\DBAL\DBALException'); $this->expectException(DBALException::class);
$table = new \Doctrine\DBAL\Schema\Table('');
new \Doctrine\DBAL\Schema\Table('');
} }
public function testGetName() public function testGetName()
...@@ -601,7 +603,9 @@ class TableTest extends \Doctrine\Tests\DbalTestCase ...@@ -601,7 +603,9 @@ class TableTest extends \Doctrine\Tests\DbalTestCase
$table = new Table("test"); $table = new Table("test");
$table->addColumn('"foo"', 'integer'); $table->addColumn('"foo"', 'integer');
$table->addColumn('bar', 'integer'); $table->addColumn('bar', 'integer');
$table->addIndex(array('"foo"', '"bar"')); $table->addIndex(['"foo"', '"bar"']);
self::assertTrue($table->columnsAreIndexed(['"foo"', '"bar"']));
} }
/** /**
...@@ -612,7 +616,9 @@ class TableTest extends \Doctrine\Tests\DbalTestCase ...@@ -612,7 +616,9 @@ class TableTest extends \Doctrine\Tests\DbalTestCase
$table = new Table("test"); $table = new Table("test");
$table->addColumn('"foo"', 'integer'); $table->addColumn('"foo"', 'integer');
$table->addColumn('bar', 'integer'); $table->addColumn('bar', 'integer');
$table->addForeignKeyConstraint('"boing"', array('"foo"', '"bar"'), array("id")); $table->addForeignKeyConstraint('"boing"', ['"foo"', '"bar"'], ["id"]);
self::assertCount(1, $table->getForeignKeys());
} }
/** /**
......
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