Enable JSONB when the new JSON is used too

parent 31d01283
......@@ -444,7 +444,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$column->setPlatformOption('collation', $tableColumn['collation']);
}
if ($column->getType()->getName() === 'json_array') {
if (in_array($column->getType()->getName(), [Type::JSON_ARRAY, Type::JSON], true)) {
$column->setPlatformOption('jsonb', $jsonb);
}
......
......@@ -28,7 +28,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$params = $this->_conn->getParams();
$paths = $this->_sm->getSchemaSearchPaths();
$this->assertEquals(array($params['user'], 'public'), $paths);
$this->assertEquals([$params['user'], 'public'], $paths);
}
/**
......@@ -40,7 +40,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertInternalType('array', $names);
$this->assertTrue(count($names) > 0);
$this->assertTrue(in_array('public', $names), "The public schema should be found.");
$this->assertContains('public', $names, 'The public schema should be found.');
}
/**
......@@ -366,7 +366,10 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertSame('(id IS NULL)', $onlineTable->getIndex('simple_partial_index')->getOption('where'));
}
public function testJsonbColumn()
/**
* @dataProvider jsonbColumnTypeProvider
*/
public function testJsonbColumn(string $type): void
{
if (!$this->_sm->getDatabasePlatform() instanceof PostgreSQL94Platform) {
$this->markTestSkipped("Requires PostgresSQL 9.4+");
......@@ -374,14 +377,22 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
}
$table = new Schema\Table('test_jsonb');
$table->addColumn('foo', 'json_array')->setPlatformOption('jsonb', true);
$table->addColumn('foo', $type)->setPlatformOption('jsonb', true);
$this->_sm->dropAndCreateTable($table);
/** @var Schema\Column[] $columns */
$columns = $this->_sm->listTableColumns('test_jsonb');
$this->assertEquals('json_array', $columns['foo']->getType()->getName());
$this->assertEquals(true, $columns['foo']->getPlatformOption('jsonb'));
$this->assertSame(TYPE::JSON, $columns['foo']->getType()->getName());
$this->assertTrue(true, $columns['foo']->getPlatformOption('jsonb'));
}
public function jsonbColumnTypeProvider(): array
{
return [
[Type::JSON],
[Type::JSON_ARRAY],
];
}
/**
......
......@@ -22,9 +22,11 @@ class PostgreSQLSchemaManagerTest extends \PHPUnit_Framework_TestCase
{
$driverMock = $this->createMock('Doctrine\DBAL\Driver');
$platform = $this->createMock('Doctrine\DBAL\Platforms\PostgreSqlPlatform');
$this->connection = $this->getMockBuilder('Doctrine\DBAL\Connection')
->setConstructorArgs(array(array('platform' => $platform), $driverMock))
->setConstructorArgs([['platform' => $platform], $driverMock])
->getMock();
$this->schemaManager = new PostgreSqlSchemaManager($this->connection, $platform);
}
......@@ -36,12 +38,12 @@ class PostgreSQLSchemaManagerTest extends \PHPUnit_Framework_TestCase
$configuration = new Configuration();
$configuration->setFilterSchemaAssetsExpression('/^schema/');
$sequences = array(
array('relname' => 'foo', 'schemaname' => 'schema'),
array('relname' => 'bar', 'schemaname' => 'schema'),
array('relname' => 'baz', 'schemaname' => ''),
array('relname' => 'bloo', 'schemaname' => 'bloo_schema'),
);
$sequences = [
['relname' => 'foo', 'schemaname' => 'schema'],
['relname' => 'bar', 'schemaname' => 'schema'],
['relname' => 'baz', 'schemaname' => ''],
['relname' => 'bloo', 'schemaname' => 'bloo_schema'],
];
$this->connection->expects($this->any())
->method('getConfiguration')
......@@ -53,20 +55,20 @@ class PostgreSQLSchemaManagerTest extends \PHPUnit_Framework_TestCase
$this->connection->expects($this->at(1))
->method('fetchAll')
->will($this->returnValue(array(array('min_value' => 1, 'increment_by' => 1))));
->will($this->returnValue([['min_value' => 1, 'increment_by' => 1]]));
$this->connection->expects($this->at(2))
->method('fetchAll')
->will($this->returnValue(array(array('min_value' => 2, 'increment_by' => 2))));
->will($this->returnValue([['min_value' => 2, 'increment_by' => 2]]));
$this->connection->expects($this->exactly(3))
->method('fetchAll');
$this->assertEquals(
array(
[
new Sequence('schema.foo', 2, 2),
new Sequence('schema.bar', 1, 1),
),
],
$this->schemaManager->listSequences('database')
);
}
......
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