Skip to content

Commit

Permalink
test: compileAdd and compileChange tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yajra committed Jul 13, 2024
1 parent adb9b93 commit 37fa50b
Showing 1 changed file with 65 additions and 45 deletions.
110 changes: 65 additions & 45 deletions tests/Database/Oci8SchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public function testBasicCreateTable()
$statements[0]);
}

protected function getConnection()
{
return m::mock('Illuminate\Database\Connection');
}

public function getGrammar()
{
return new OracleGrammar;
}

public function testAddColumnWithSpace(): void
{
$blueprint = new Blueprint('users');
Expand Down Expand Up @@ -61,16 +71,6 @@ public function testCreateIndexNameUsingColumnWithSpace()
$this->assertEquals('create index users_first_name_index on "USERS" ( "FIRST NAME" )', $statements[1]);
}

protected function getConnection()
{
return m::mock('Illuminate\Database\Connection');
}

public function getGrammar()
{
return new OracleGrammar;
}

public function testBasicCreateTableWithReservedWords()
{
$blueprint = new Blueprint('users');
Expand Down Expand Up @@ -245,9 +245,11 @@ public function testBasicAlterTable()

$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "USERS" add ( "ID" number(10,0) not null, "EMAIL" varchar2(255) not null, constraint users_id_pk primary key ( "ID" ) )',
$statements[0]);
$this->assertCount(2, $statements);
$this->assertSame([
'alter table "USERS" add ( "ID" number(10,0) not null )',
'alter table "USERS" add ( "EMAIL" varchar2(255) not null )',
], $statements);
}

public function testAlterTableRenameColumn()
Expand Down Expand Up @@ -301,7 +303,9 @@ public function testAlterTableModifyColumnWithCollate()
$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('alter table "USERS" modify "EMAIL" varchar2(255) collate "LATIN1_SWEDISH_CI" not null', $statements[0]);
$this->assertSame([
'alter table "USERS" modify "EMAIL" varchar2(255) collate "LATIN1_SWEDISH_CI" not null',
], $statements);
}

public function testAlterTableModifyMultipleColumns()
Expand All @@ -314,8 +318,11 @@ public function testAlterTableModifyMultipleColumns()

$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('alter table "USERS" modify "EMAIL" varchar2(255) not null modify "NAME" varchar2(255) not null', $statements[0]);
$this->assertCount(2, $statements);
$this->assertSame([
'alter table "USERS" modify "EMAIL" varchar2(255) not null',
'alter table "USERS" modify "NAME" varchar2(255) not null',
], $statements);
}

public function testBasicAlterTableWithPrimary()
Expand All @@ -328,9 +335,11 @@ public function testBasicAlterTableWithPrimary()

$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "USERS" add ( "ID" number(10,0) not null, "EMAIL" varchar2(255) not null, constraint users_id_pk primary key ( "ID" ) )',
$statements[0]);
$this->assertCount(2, $statements);
$this->assertSame([
'alter table "USERS" add ( "ID" number(10,0) not null )',
'alter table "USERS" add ( "EMAIL" varchar2(255) not null )',
], $statements);
}

public function testBasicAlterTableWithPrefix()
Expand All @@ -347,9 +356,11 @@ public function testBasicAlterTableWithPrefix()

$statements = $blueprint->toSql($conn, $grammar);

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "PREFIX_USERS" add ( "ID" number(10,0) not null, "EMAIL" varchar2(255) not null, constraint prefix_users_id_pk primary key ( "ID" ) )',
$statements[0]);
$this->assertCount(2, $statements);
$this->assertSame([
'alter table "PREFIX_USERS" add ( "ID" number(10,0) not null )',
'alter table "PREFIX_USERS" add ( "EMAIL" varchar2(255) not null )',
], $statements);
}

public function testBasicAlterTableWithPrefixAndPrimary()
Expand All @@ -366,9 +377,11 @@ public function testBasicAlterTableWithPrefixAndPrimary()

$statements = $blueprint->toSql($conn, $grammar);

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "PREFIX_USERS" add ( "ID" number(10,0) not null, "EMAIL" varchar2(255) not null, constraint prefix_users_id_pk primary key ( "ID" ) )',
$statements[0]);
$this->assertCount(2, $statements);
$this->assertEquals([
'alter table "PREFIX_USERS" add ( "ID" number(10,0) not null )',
'alter table "PREFIX_USERS" add ( "EMAIL" varchar2(255) not null )',
], $statements);
}

public function testDropTable()
Expand Down Expand Up @@ -686,9 +699,8 @@ public function testAddingIncrementingID()
$blueprint->increments('id');
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "USERS" add ( "ID" number(10,0) not null, constraint users_id_pk primary key ( "ID" ) )',
$statements[0]);
$this->assertCount(1, $statements);
$this->assertEquals('alter table "USERS" add ( "ID" number(10,0) not null )', $statements[0]);
}

public function testAddingString()
Expand Down Expand Up @@ -716,8 +728,8 @@ public function testAddingString()

$blueprint = new Blueprint('users');
$blueprint->string('foo', 100)
->nullable()
->default(new Expression('CURRENT TIMESTAMP'));
->nullable()
->default(new Expression('CURRENT TIMESTAMP'));
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(1, count($statements));
Expand Down Expand Up @@ -785,9 +797,10 @@ public function testAddingBigInteger()
$blueprint->bigInteger('foo', true);
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "USERS" add ( "FOO" number(19,0) not null, constraint users_foo_pk primary key ( "FOO" ) )',
$statements[0]);
$this->assertCount(1, $statements);
$this->assertSame([
'alter table "USERS" add ( "FOO" number(19,0) not null )',
], $statements);
}

public function testAddingInteger()
Expand All @@ -803,9 +816,10 @@ public function testAddingInteger()
$blueprint->integer('foo', true);
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "USERS" add ( "FOO" number(10,0) not null, constraint users_foo_pk primary key ( "FOO" ) )',
$statements[0]);
$this->assertCount(1, $statements);
$this->assertSame([
'alter table "USERS" add ( "FOO" number(10,0) not null )',
], $statements);
}

public function testAddingMediumInteger()
Expand Down Expand Up @@ -979,9 +993,11 @@ public function testAddingNullableTimeStamps()
$blueprint->nullableTimestamps();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "USERS" add ( "CREATED_AT" timestamp null, "UPDATED_AT" timestamp null )',
$statements[0]);
$this->assertCount(2, $statements);
$this->assertSame([
'alter table "USERS" add ( "CREATED_AT" timestamp null )',
'alter table "USERS" add ( "UPDATED_AT" timestamp null )',
], $statements);
}

public function testAddingTimeStamps()
Expand All @@ -990,9 +1006,11 @@ public function testAddingTimeStamps()
$blueprint->timestamps();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "USERS" add ( "CREATED_AT" timestamp null, "UPDATED_AT" timestamp null )',
$statements[0]);
$this->assertCount(2, $statements);
$this->assertSame([
'alter table "USERS" add ( "CREATED_AT" timestamp null )',
'alter table "USERS" add ( "UPDATED_AT" timestamp null )',
], $statements);
}

public function testAddingTimeStampTzs()
Expand All @@ -1001,9 +1019,11 @@ public function testAddingTimeStampTzs()
$blueprint->timestampsTz();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertEquals(1, count($statements));
$this->assertEquals('alter table "USERS" add ( "CREATED_AT" timestamp with time zone null, "UPDATED_AT" timestamp with time zone null )',
$statements[0]);
$this->assertCount(2, $statements);
$this->assertEquals([
'alter table "USERS" add ( "CREATED_AT" timestamp with time zone null )',
'alter table "USERS" add ( "UPDATED_AT" timestamp with time zone null )',
], $statements);
}

public function testAddingUuid()
Expand Down

0 comments on commit 37fa50b

Please sign in to comment.