예제 #1
0
 /**
  * @covers de\detert\sebastian\slimline\db\Handler::query
  * @covers de\detert\sebastian\slimline\db\Handler::prepareAndExecute
  * @covers de\detert\sebastian\slimline\db\Handler::fetchAll
  */
 public function testShouldExecuteQuery()
 {
     $sql = 'CREATE TABLE IF NOT EXISTS `foo` (`id` INT(20))';
     $this->handler->query($sql);
     $sql = 'INSERT INTO `foo` VALUES (?), (?)';
     $params = array(1, 2);
     $this->handler->query($sql, $params);
     $expected = array(0 => array('id' => 1), 1 => array('id' => 2));
     $this->assertEquals($expected, $this->handler->fetchAll("SELECT * from `foo`"));
 }
예제 #2
0
 /**
  * @covers de\detert\sebastian\slimline\db\Migration::__construct
  * @covers de\detert\sebastian\slimline\db\Migration::update
  * @covers de\detert\sebastian\slimline\db\Migration::doMigration
  * @covers de\detert\sebastian\slimline\db\Migration_Repository::getMigrationVersions
  * @covers de\detert\sebastian\slimline\db\Migration::getFilesForUpdate
  * @covers de\detert\sebastian\slimline\db\Migration::getMigrationClasses
  * @covers de\detert\sebastian\slimline\db\Migration::upAction
  * @covers de\detert\sebastian\slimline\db\Migration_Statement::__construct
  */
 public function testShouldNotPerformMigration1()
 {
     $actual = $this->handler->fetchAll("SHOW TABLES");
     $expected = array();
     $this->assertSame($expected, $actual);
     // create migration_version table
     $this->initMigrationClass(__DIR__ . DS . 'migration' . DS . 'empty');
     $this->migration->update();
     $sql = "INSERT INTO `migration_version` (`id`, `filename`) VALUES (NULL, ?)";
     $this->handler->query($sql, array('1_throw_exception'));
     // test starts here
     $this->initMigrationClass(__DIR__ . DS . 'migration' . DS . 'step2');
     $this->migration->update();
     $actual = $this->handler->fetchAll("SHOW TABLES");
     $expected = array(array('Tables_in_slimline_test' => 'migration_version'), array('Tables_in_slimline_test' => 'foo'));
     $this->assertEquals($expected, $actual, '', 0, 10, true);
     $sql = "SELECT * FROM `migration_version`";
     $actual = $this->handler->fetchAll($sql);
     $expected = array(array('id' => 1, 'filename' => '1_throw_exception'), array('id' => 2, 'filename' => '2_create_foo'));
     $this->assertEquals($expected, $actual);
 }
예제 #3
0
 /**
  * @covers de\detert\sebastian\slimline\session\Db::gc
  *
  * @runInSeparateProcess
  */
 public function testShouldDestroySession()
 {
     $handler = new Handler($this->dbConfig);
     $sql = 'DROP TABLE IF EXISTS `session`';
     $handler->query($sql);
     session_id(125);
     $session = new Db($handler);
     $session->createTable();
     $now = time() - 10;
     $date = date('Y-m-d H:i:s', $now);
     $sql = "INSERT INTO `session`\n            (`id`, `created`, `updated`, `value`) VALUES\n            (:id, :date, :date, :value)";
     $handler->query($sql, array('id' => 125, 'value' => 'unit_test|s:3:"abc";', 'date' => $date));
     $session->startSession();
     $session->gc(20);
     $sql = "SELECT * FROM `session` WHERE `id`=?";
     $actual = $handler->fetchAll($sql, array(125));
     $this->assertEquals(125, $actual[0]['id']);
     $this->assertEquals('unit_test|s:3:"abc";', $actual[0]['value']);
     $session->gc(9);
     $sql = "SELECT * FROM `session` WHERE `id`=?";
     $actual = $handler->fetchAll($sql, array(125));
     $this->assertEquals(array(), $actual);
 }