1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
<?php
namespace Illuminate\Tests\Integration\Database\SchemaTest;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Illuminate\Database\Grammar;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Tests\Integration\Database\DatabaseTestCase;
class ConfigureCustomDoctrineTypeTest extends DatabaseTestCase
{
protected function defineEnvironment($app)
{
parent::defineEnvironment($app);
$app['config']['database.connections.sqlite.database'] = ':memory:';
$app['config']['database.dbal.types'] = [
'bit' => MySQLBitType::class,
'xml' => PostgresXmlType::class,
];
}
public function testRegisterCustomDoctrineTypesWithNonDefaultDatabaseConnections()
{
$this->assertTrue(
DB::connection()
->getDoctrineSchemaManager()
->getDatabasePlatform()
->hasDoctrineTypeMappingFor('xml')
);
// Custom type mappings are registered for a connection when it's created,
// this is not the default connection but it has the custom type mappings
$this->assertTrue(
DB::connection('sqlite')
->getDoctrineSchemaManager()
->getDatabasePlatform()
->hasDoctrineTypeMappingFor('xml')
);
}
public function testRenameConfiguredCustomDoctrineColumnTypeWithPostgres()
{
if ($this->driver !== 'pgsql') {
$this->markTestSkipped('Test requires a Postgres connection.');
}
Grammar::macro('typeXml', function () {
return 'xml';
});
Schema::create('test', function (Blueprint $table) {
$table->addColumn('xml', 'test_column');
});
Schema::table('test', function (Blueprint $table) {
$table->renameColumn('test_column', 'renamed_column');
});
$this->assertFalse(Schema::hasColumn('test', 'test_column'));
$this->assertTrue(Schema::hasColumn('test', 'renamed_column'));
}
public function testRenameConfiguredCustomDoctrineColumnTypeWithMysql()
{
if ($this->driver !== 'mysql') {
$this->markTestSkipped('Test requires a MySQL connection.');
}
Grammar::macro('typeBit', function () {
return 'bit';
});
Schema::create('test', function (Blueprint $table) {
$table->addColumn('bit', 'test_column');
});
Schema::table('test', function (Blueprint $table) {
$table->renameColumn('test_column', 'renamed_column');
});
$this->assertFalse(Schema::hasColumn('test', 'test_column'));
$this->assertTrue(Schema::hasColumn('test', 'renamed_column'));
}
}
class PostgresXmlType extends Type
{
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return 'xml';
}
public function getName()
{
return 'xml';
}
}
class MySQLBitType extends Type
{
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return 'bit';
}
public function getName()
{
return 'bit';
}
}
|