From a491348d442ab8e6cd2fa403d4365cdad78e52ce Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 21 Jun 2018 14:13:41 -0700 Subject: Vendoring deprecated composer libs --- libs/picodb/tests/PostgresSchemaTest.php | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 libs/picodb/tests/PostgresSchemaTest.php (limited to 'libs/picodb/tests/PostgresSchemaTest.php') diff --git a/libs/picodb/tests/PostgresSchemaTest.php b/libs/picodb/tests/PostgresSchemaTest.php new file mode 100644 index 00000000..5ecf1cc5 --- /dev/null +++ b/libs/picodb/tests/PostgresSchemaTest.php @@ -0,0 +1,40 @@ +db = new PicoDb\Database(array('driver' => 'postgres', 'hostname' => 'localhost', 'username' => 'postgres', 'password' => 'postgres', 'database' => 'picodb')); + $this->db->getConnection()->exec('DROP TABLE IF EXISTS test1'); + $this->db->getConnection()->exec('DROP TABLE IF EXISTS test2'); + $this->db->getConnection()->exec('DROP TABLE IF EXISTS schema_version'); + } + + public function testMigrations() + { + $this->assertTrue($this->db->schema()->check(2)); + $this->assertEquals(2, $this->db->getDriver()->getSchemaVersion()); + } + + public function testFailedMigrations() + { + $this->assertEquals(0, $this->db->getDriver()->getSchemaVersion()); + $this->assertFalse($this->db->schema()->check(3)); + $this->assertEquals(2, $this->db->getDriver()->getSchemaVersion()); + + $logs = $this->db->getLogMessages(); + $this->assertNotEmpty($logs); + $this->assertEquals('Running migration \Schema\version_1', $logs[0]); + $this->assertEquals('Running migration \Schema\version_2', $logs[1]); + $this->assertEquals('Running migration \Schema\version_3', $logs[2]); + $this->assertStringStartsWith('SQLSTATE[42601]: Syntax error', $logs[3]); + } +} -- cgit v1.2.3