-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work on migration table functionality, update unit tests
- Loading branch information
1 parent
1e830fb
commit 4a3cfd5
Showing
9 changed files
with
117 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Pop\Db\Test\Sql; | ||
|
||
use Pop\Db\Db; | ||
use Pop\Db\Sql\Migrator; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class MigratorTableTest extends TestCase | ||
{ | ||
|
||
protected $db = null; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->db = Db::mysqlConnect([ | ||
'database' => $_ENV['MYSQL_DB'], | ||
'username' => $_ENV['MYSQL_USER'], | ||
'password' => $_ENV['MYSQL_PASS'], | ||
'host' => $_ENV['MYSQL_HOST'] | ||
]); | ||
\Pop\Db\Test\TestAsset\Migrations::setDb($this->db); | ||
} | ||
|
||
public function testConstructor() | ||
{ | ||
$migrator = new Migrator($this->db, __DIR__ . '/../tmp/migrations2'); | ||
$this->assertInstanceOf('Pop\Db\Sql\Migrator', $migrator); | ||
$this->assertInstanceOf('Pop\Db\Adapter\Mysql', $migrator->getDb()); | ||
$this->assertInstanceOf('Pop\Db\Adapter\Mysql', $migrator->db()); | ||
$this->assertEquals(__DIR__ . '/../tmp/migrations2', $migrator->getPath()); | ||
$this->assertNull($migrator->getCurrent()); | ||
$this->assertTrue($migrator->hasTable()); | ||
$this->assertEquals('Pop\Db\Test\TestAsset\Migrations', $migrator->getTable()); | ||
$this->db->disconnect(); | ||
} | ||
|
||
public function testRun() | ||
{ | ||
$migrator = new Migrator($this->db, __DIR__ . '/../tmp/migrations2'); | ||
$this->assertFalse($this->db->hasTable('test_users')); | ||
$migrator->runAll(); | ||
$this->assertTrue($this->db->hasTable('test_users')); | ||
$this->db->disconnect(); | ||
} | ||
|
||
public function testRollback() | ||
{ | ||
$migrator = new Migrator($this->db, __DIR__ . '/../tmp/migrations2'); | ||
$this->assertTrue($this->db->hasTable('test_users')); | ||
$migrator->rollbackAll(); | ||
$this->assertFalse($this->db->hasTable('test_users')); | ||
$this->db->disconnect(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Pop\Db\Test\TestAsset; | ||
|
||
use Pop\Db\Record; | ||
|
||
class Migrations extends Record | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Pop\Db\Test\TestAsset\Migrations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use Pop\Db\Sql\Migration\AbstractMigration; | ||
|
||
class TestMigration extends AbstractMigration | ||
{ | ||
|
||
public function up(): void | ||
{ | ||
$schema = $this->db->createSchema(); | ||
$schema->create('test_users') | ||
->int('id', 16) | ||
->varchar('username', 255) | ||
->varchar('password', 255) | ||
->primary('id'); | ||
|
||
$this->db->query($schema); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
$schema = $this->db->createSchema(); | ||
$schema->drop('test_users'); | ||
$this->db->query($schema); | ||
} | ||
|
||
} |