/**
  * @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;
     }
 }
Esempio n. 2
0
 /**
  * @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']);
     }
 }
 /**
  * @test
  */
 public function truncate()
 {
     $this->fixture->query('TRUNCATE item');
 }