_path = tempnam(sys_get_temp_dir() . 'tmp', 'history'); $this->_history = new History($this->_path); } public function testConstructor() { $this->assertTrue(is_dir($this->getHistoryDir()), "__constructor() creates unique directory for file history"); } public function testAppendAndRestore() { $time = $this->_history->append($this->_path); $this->assertTrue(file_exists($this->_history->getFileByTimestamp($time)), '->append() creates history file'); $this->assertEquals($this->_history->restoreByTimestamp( $time ), $time, '->restoreByTimestamp() returns correct timestamp'); } public function testUndoRestore() { $this->_history->undoRestore(); $this->assertFalse(file_exists($this->_path), '->undoRestore removes file'); } public function testPositioning() { $other_file = tempnam(sys_get_temp_dir() . 'tmp', 'history'); $el1 = $this->_history->append($other_file); $el2 = $this->_history->append($other_file); $el3 = $this->_history->append($other_file); $this->assertEquals(3, $this->_history->getCount()); $this->assertEquals($el3, $this->_history->getFirst()); $this->assertEquals($el1, $this->_history->getLast()); $this->assertEquals($el2, $this->_history->getNth(1)); $this->assertEquals($el1, $this->_history->getNext()); $this->assertFalse($this->_history->getNext()); unlink($other_file); } private function getHistoryDir() { return dirname($this->_path); } }