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