/** * @test */ public function delete() { $this->fixture->insert('item', ['title' => '1']); $this->fixture->insert('item', ['title' => '2']); $todelete = $this->fixture->insert('item', ['title' => '3']); $count = $this->fixture->count('item'); $this->fixture->delete('item', ['id' => $todelete]); $this->assertSame($count - 1, $this->fixture->count('item')); $this->fixture->delete('item'); $this->assertSame(0, $this->fixture->count('item')); }
/** * @test * @expectedException \AppZap\PHPFramework\Persistence\DatabaseMigratorException * @expectedExceptionCode 1415089456 */ public function rollbackOnError() { Configuration::set('phpframework', 'db.migrator.directory', $this->basePath . '/_migrator/_error/'); try { (new DatabaseMigrator())->migrate(); } catch (\Exception $e) { $this->assertSame(1, count($this->db->query("SHOW TABLES LIKE 'migrator_test_error'"))); $this->assertSame(1, $this->db->count('migrator_test_error', ['title' => 'test1'])); $this->assertSame(1, $this->db->count('migrator_test_error')); throw $e; } }
/** * @param int $version */ protected function setCurrentMigrationVersion($version) { if (count($this->db->query("SHOW TABLES LIKE 'migration_ver'")) < 1) { $sql = "CREATE TABLE IF NOT EXISTS `migration_ver` (`version` int(11) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;"; $this->db->execute($sql); } $data = ['version' => $version]; if ($this->db->count('migration_ver') < 1) { $this->db->insert('migration_ver', $data); } else { $this->db->update('migration_ver', $data, ['version!' => '0']); } }