aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/HistoryTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/HistoryTest.php')
-rw-r--r--tests/HistoryTest.php25
1 files changed, 8 insertions, 17 deletions
diff --git a/tests/HistoryTest.php b/tests/HistoryTest.php
index 7189c3a9..e810104e 100644
--- a/tests/HistoryTest.php
+++ b/tests/HistoryTest.php
@@ -3,10 +3,9 @@
3namespace Shaarli; 3namespace Shaarli;
4 4
5use DateTime; 5use DateTime;
6use Exception;
7use Shaarli\Bookmark\Bookmark; 6use Shaarli\Bookmark\Bookmark;
8 7
9class HistoryTest extends \PHPUnit\Framework\TestCase 8class HistoryTest extends \Shaarli\TestCase
10{ 9{
11 /** 10 /**
12 * @var string History file path 11 * @var string History file path
@@ -16,7 +15,7 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
16 /** 15 /**
17 * Delete history file. 16 * Delete history file.
18 */ 17 */
19 public function setUp() 18 protected function setUp(): void
20 { 19 {
21 if (file_exists(self::$historyFilePath)) { 20 if (file_exists(self::$historyFilePath)) {
22 unlink(self::$historyFilePath); 21 unlink(self::$historyFilePath);
@@ -44,12 +43,12 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
44 43
45 /** 44 /**
46 * Not writable history file: raise an exception. 45 * Not writable history file: raise an exception.
47 *
48 * @expectedException Exception
49 * @expectedExceptionMessage History file isn't readable or writable
50 */ 46 */
51 public function testConstructNotWritable() 47 public function testConstructNotWritable()
52 { 48 {
49 $this->expectException(\Exception::class);
50 $this->expectExceptionMessage('History file isn\'t readable or writable');
51
53 touch(self::$historyFilePath); 52 touch(self::$historyFilePath);
54 chmod(self::$historyFilePath, 0440); 53 chmod(self::$historyFilePath, 0440);
55 $history = new History(self::$historyFilePath); 54 $history = new History(self::$historyFilePath);
@@ -58,12 +57,12 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
58 57
59 /** 58 /**
60 * Not parsable history file: raise an exception. 59 * Not parsable history file: raise an exception.
61 *
62 * @expectedException Exception
63 * @expectedExceptionMessageRegExp /Could not parse history file/
64 */ 60 */
65 public function testConstructNotParsable() 61 public function testConstructNotParsable()
66 { 62 {
63 $this->expectException(\Exception::class);
64 $this->expectExceptionMessageRegExp('/Could not parse history file/');
65
67 file_put_contents(self::$historyFilePath, 'not parsable'); 66 file_put_contents(self::$historyFilePath, 'not parsable');
68 $history = new History(self::$historyFilePath); 67 $history = new History(self::$historyFilePath);
69 // gzinflate generates a warning 68 // gzinflate generates a warning
@@ -90,14 +89,6 @@ class HistoryTest extends \PHPUnit\Framework\TestCase
90 $this->assertEquals(History::CREATED, $actual['event']); 89 $this->assertEquals(History::CREATED, $actual['event']);
91 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']); 90 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']);
92 $this->assertEquals(1, $actual['id']); 91 $this->assertEquals(1, $actual['id']);
93
94 $history = new History(self::$historyFilePath);
95 $bookmark = (new Bookmark())->setId('str');
96 $history->addLink($bookmark);
97 $actual = $history->getHistory()[0];
98 $this->assertEquals(History::CREATED, $actual['event']);
99 $this->assertTrue(new DateTime('-2 seconds') < $actual['datetime']);
100 $this->assertEquals('str', $actual['id']);
101 } 92 }
102 93
103// /** 94// /**