Unverified Commit bd5e190a authored by Sergei Morozov's avatar Sergei Morozov

Merge branch 'bpo/2.7/#3086' into 2.7

parents a6b7bb81 eca1c525
...@@ -303,8 +303,8 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -303,8 +303,8 @@ class OracleSchemaManager extends AbstractSchemaManager
return new Sequence( return new Sequence(
$this->getQuotedIdentifierName($sequence['sequence_name']), $this->getQuotedIdentifierName($sequence['sequence_name']),
$sequence['increment_by'], (int) $sequence['increment_by'],
$sequence['min_value'] (int) $sequence['min_value']
); );
} }
......
...@@ -311,7 +311,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -311,7 +311,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$sequence += $data; $sequence += $data;
} }
return new Sequence($sequenceName, $sequence['increment_by'], $sequence['min_value']); return new Sequence($sequenceName, (int) $sequence['increment_by'], (int) $sequence['min_value']);
} }
/** /**
......
...@@ -76,7 +76,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -76,7 +76,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
*/ */
protected function _getPortableSequenceDefinition($sequence) protected function _getPortableSequenceDefinition($sequence)
{ {
return new Sequence($sequence['name'], $sequence['increment'], $sequence['start_value']); return new Sequence($sequence['name'], (int) $sequence['increment'], (int) $sequence['start_value']);
} }
/** /**
......
...@@ -58,8 +58,8 @@ class Sequence extends AbstractAsset ...@@ -58,8 +58,8 @@ class Sequence extends AbstractAsset
{ {
$this->_setName($name); $this->_setName($name);
$this->allocationSize = is_numeric($allocationSize) ? $allocationSize : 1; $this->allocationSize = is_numeric($allocationSize) ? $allocationSize : 1;
$this->initialValue = is_numeric($initialValue) ? $initialValue : 1; $this->initialValue = is_numeric($initialValue) ? $initialValue : 1;
$this->cache = $cache; $this->cache = $cache;
} }
/** /**
......
...@@ -18,6 +18,7 @@ use function array_filter; ...@@ -18,6 +18,7 @@ use function array_filter;
use function array_keys; use function array_keys;
use function array_map; use function array_map;
use function array_search; use function array_search;
use function array_values;
use function count; use function count;
use function current; use function current;
use function end; use function end;
...@@ -25,6 +26,7 @@ use function explode; ...@@ -25,6 +26,7 @@ use function explode;
use function get_class; use function get_class;
use function in_array; use function in_array;
use function str_replace; use function str_replace;
use function strcasecmp;
use function strlen; use function strlen;
use function strtolower; use function strtolower;
use function substr; use function substr;
...@@ -123,7 +125,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -123,7 +125,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$name = 'dropcreate_sequences_test_seq'; $name = 'dropcreate_sequences_test_seq';
$this->_sm->dropAndCreateSequence(new \Doctrine\DBAL\Schema\Sequence($name, 20, 10)); $this->_sm->dropAndCreateSequence(new Sequence($name, 20, 10));
self::assertTrue($this->hasElementWithName($this->_sm->listSequences(), $name)); self::assertTrue($this->hasElementWithName($this->_sm->listSequences(), $name));
} }
...@@ -142,11 +144,11 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -142,11 +144,11 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
public function testListSequences() public function testListSequences()
{ {
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('list_sequences_test_seq', 20, 10); $sequence = new Sequence('list_sequences_test_seq', 20, 10);
$this->_sm->createSequence($sequence); $this->_sm->createSequence($sequence);
$sequences = $this->_sm->listSequences(); $sequences = $this->_sm->listSequences();
...@@ -154,16 +156,18 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -154,16 +156,18 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
self::assertInternalType('array', $sequences, 'listSequences() should return an array.'); self::assertInternalType('array', $sequences, 'listSequences() should return an array.');
$foundSequence = null; $foundSequence = null;
foreach($sequences as $sequence) { foreach ($sequences as $sequence) {
self::assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $sequence, 'Array elements of listSequences() should be Sequence instances.'); self::assertInstanceOf(Sequence::class, $sequence, 'Array elements of listSequences() should be Sequence instances.');
if(strtolower($sequence->getName()) == 'list_sequences_test_seq') { if (strtolower($sequence->getName()) !== 'list_sequences_test_seq') {
$foundSequence = $sequence; continue;
} }
$foundSequence = $sequence;
} }
self::assertNotNull($foundSequence, "Sequence with name 'list_sequences_test_seq' was not found."); self::assertNotNull($foundSequence, "Sequence with name 'list_sequences_test_seq' was not found.");
self::assertEquals(20, $foundSequence->getAllocationSize(), "Allocation Size is expected to be 20."); self::assertSame(20, $foundSequence->getAllocationSize(), 'Allocation Size is expected to be 20.');
self::assertEquals(10, $foundSequence->getInitialValue(), "Initial Value is expected to be 10."); self::assertSame(10, $foundSequence->getInitialValue(), 'Initial Value is expected to be 10.');
} }
public function testListDatabases() public function testListDatabases()
...@@ -1452,4 +1456,37 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -1452,4 +1456,37 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
self::assertEquals($sequence2AllocationSize, $actualSequence2->getAllocationSize()); self::assertEquals($sequence2AllocationSize, $actualSequence2->getAllocationSize());
self::assertEquals($sequence2InitialValue, $actualSequence2->getInitialValue()); self::assertEquals($sequence2InitialValue, $actualSequence2->getInitialValue());
} }
/**
* @group #3086
*/
public function testComparisonWithAutoDetectedSequenceDefinition() : void
{
if (! $this->_sm->getDatabasePlatform()->supportsSequences()) {
self::markTestSkipped('This test is only supported on platforms that support sequences.');
}
$sequenceName = 'sequence_auto_detect_test';
$sequenceAllocationSize = 5;
$sequenceInitialValue = 10;
$sequence = new Sequence($sequenceName, $sequenceAllocationSize, $sequenceInitialValue);
$this->_sm->dropAndCreateSequence($sequence);
$createdSequence = array_values(
array_filter(
$this->_sm->listSequences(),
function (Sequence $sequence) use ($sequenceName) : bool {
return strcasecmp($sequence->getName(), $sequenceName) === 0;
}
)
)[0] ?? null;
self::assertNotNull($createdSequence);
$comparator = new Comparator();
$tableDiff = $comparator->diffSequence($createdSequence, $sequence);
self::assertFalse($tableDiff);
}
} }
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