示例#1
0
 /**
  * @covers de\detert\sebastian\slimline\db\Model_Repository::getAllTables
  */
 public function testShouldReturnAllTables()
 {
     $sql = 'CREATE TABLE `foo` (
         `id` INT(20) AUTO_INCREMENT,
         `text` VARCHAR(100) COMMENT "just a text",
         PRIMARY KEY (`id`)
     )';
     $this->handler->query($sql);
     $sql = 'CREATE TABLE `misc` (
         `misc_id` TINYINT(3) UNSIGNED,
         `date` DATETIME NOT NULL DEFAULT 0
     )';
     $this->handler->query($sql);
     $actual = $this->repository->getAllTables();
     $id = new Model_Column();
     $id->data_type = 'int';
     $id->column_type = 'int(20)';
     $id->extra = 'auto_increment';
     $id->is_nullable = false;
     $id->column_comment = '';
     $id->character_maximum_length = null;
     $text = new Model_Column();
     $text->data_type = 'varchar';
     $text->column_type = 'varchar(100)';
     $text->extra = '';
     $text->is_nullable = true;
     $text->column_comment = 'just a text';
     $text->character_maximum_length = 100;
     $foo = new Model_Table();
     $foo->columns['id'] = $id;
     $foo->columns['text'] = $text;
     $miscId = new Model_Column();
     $miscId->data_type = 'tinyint';
     $miscId->column_type = 'tinyint(3) unsigned';
     $miscId->extra = '';
     $miscId->is_nullable = true;
     $miscId->column_comment = '';
     $miscId->character_maximum_length = null;
     $date = new Model_Column();
     $date->data_type = 'datetime';
     $date->column_type = 'datetime';
     $date->extra = '';
     $date->is_nullable = false;
     $date->column_comment = '';
     $date->character_maximum_length = null;
     $misc = new Model_Table();
     $misc->columns['misc_id'] = $miscId;
     $misc->columns['date'] = $date;
     $expected = array('foo' => $foo, 'misc' => $misc);
     foreach ($expected as $table => $columns) {
         $this->assertTrue(isset($actual[$table]), "expected {$table} in result");
         $this->assertEquals($expected[$table], $actual[$table]);
     }
 }
示例#2
0
 public function updateJob()
 {
     $job = new Job();
     $job->setWorker(0);
     $job->setName($this->name);
     $job->setStart($this->start->format('Y-m-d H:i:s'));
     $job->setCallback($this->class, $this->method, $this->params);
     $job->setUnique($this->unique);
     $this->db->saveModel($job);
 }
示例#3
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);
 }
示例#4
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);
 }
示例#5
0
文件: db.php 项目: thomblin/slimline
 /**
  * @param string $sessionId
  * @param string $sessionData
  *
  * @return bool
  */
 public function write($sessionId, $sessionData)
 {
     $sql = "INSERT INTO `" . $this->table . "`\n            (`id`, `created`, `updated`, `value`) VALUES\n            (:id, :now, :now, :value)\n            ON DUPLICATE KEY UPDATE `value`=:value, `updated`=:now";
     $this->db->query($sql, array(':id' => $sessionId, ':value' => $sessionData, ':now' => date('Y-m-d H:i:s')));
     return true;
 }
示例#6
0
 /**
  * testShouldGetFoundRows
  *
  * @param $debug
  *
  * @dataProvider getResponseDebugSql
  * @covers de\detert\sebastian\slimline\db\Handler::getAffectedRows
  */
 public function testShouldGetFoundRows(Response_Debug_Sql $debug = null)
 {
     $handler = new Handler($this->dbConfig);
     if (!is_null($debug)) {
         $handler->setDebugResponse($debug);
     }
     $sql = 'CREATE TABLE IF NOT EXISTS `foo` (`id` INT(20))';
     $this->handler->query($sql);
     $sql = 'INSERT INTO `foo` VALUES (?), (?)';
     $params = array(1, 2);
     $handler->query($sql, $params);
     $handler->query("SELECT SQL_CALC_FOUND_ROWS * FROM `foo` LIMIT 1");
     $this->assertEquals(2, $handler->getFoundRows());
 }
示例#7
0
 /**
  * @param Job $job
  */
 public function finishJob(Job $job)
 {
     $sql = "DELETE FROM `queue` WHERE `worker` = :worker";
     $this->db->query($sql, array('worker' => $job->getWorker()));
 }