]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/utils/ReferenceHistory.php
namespacing: \Shaarli\FileUtils
[github/shaarli/Shaarli.git] / tests / utils / ReferenceHistory.php
1 <?php
2
3 use Shaarli\FileUtils;
4 use Shaarli\History;
5
6 /**
7 * Populates a reference history
8 */
9 class ReferenceHistory
10 {
11 private $count;
12
13 private $history = [];
14
15 /**
16 * Populates the test DB with reference data
17 */
18 public function __construct()
19 {
20 $this->addEntry(
21 History::DELETED,
22 DateTime::createFromFormat('Ymd_His', '20170303_121216'),
23 124
24 );
25
26 $this->addEntry(
27 History::SETTINGS,
28 DateTime::createFromFormat('Ymd_His', '20170302_121215')
29 );
30
31 $this->addEntry(
32 History::UPDATED,
33 DateTime::createFromFormat('Ymd_His', '20170301_121214'),
34 123
35 );
36
37 $this->addEntry(
38 History::CREATED,
39 DateTime::createFromFormat('Ymd_His', '20170201_121214'),
40 124
41 );
42
43 $this->addEntry(
44 History::CREATED,
45 DateTime::createFromFormat('Ymd_His', '20170101_121212'),
46 123
47 );
48 }
49
50 /**
51 * Adds a new history entry
52 *
53 * @param string $event Event identifier
54 * @param DateTime $datetime creation date
55 * @param int $id optional: related link ID
56 */
57 protected function addEntry($event, $datetime, $id = null)
58 {
59 $link = [
60 'event' => $event,
61 'datetime' => $datetime,
62 'id' => $id,
63 ];
64 $this->history[] = $link;
65 $this->count++;
66 }
67
68 /**
69 * Writes data to the datastore
70 *
71 * @param string $filename write history content to.
72 */
73 public function write($filename)
74 {
75 FileUtils::writeFlatDB($filename, $this->history);
76 }
77
78 /**
79 * Returns the number of links in the reference data
80 */
81 public function count()
82 {
83 return $this->count;
84 }
85 }