Fix risky tests

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