@@ -9,14 +9,14 @@ discard block |
||
9 | 9 | class MysqlSeriesRepositoryTest extends PHPUnit_Framework_TestCase |
10 | 10 | { |
11 | 11 | |
12 | - protected static $connection; |
|
12 | + protected static $connection; |
|
13 | 13 | |
14 | - public static function setUpBeforeClass() |
|
15 | - { |
|
16 | - $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
17 | - $extendedPdo->exec("ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`"); |
|
14 | + public static function setUpBeforeClass() |
|
15 | + { |
|
16 | + $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
17 | + $extendedPdo->exec("ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`"); |
|
18 | 18 | |
19 | - $extendedPdo->exec(" |
|
19 | + $extendedPdo->exec(" |
|
20 | 20 | CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`post` ( |
21 | 21 | `id` integer PRIMARY KEY AUTOINCREMENT, |
22 | 22 | `title` varchar(60) NOT NULL, |
@@ -26,201 +26,201 @@ discard block |
||
26 | 26 | `body` text, |
27 | 27 | `display` integer(1) NOT NULL |
28 | 28 | )" |
29 | - ); |
|
30 | - $extendedPdo->exec(" |
|
29 | + ); |
|
30 | + $extendedPdo->exec(" |
|
31 | 31 | CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`series` ( |
32 | 32 | `id` integer PRIMARY KEY AUTOINCREMENT, |
33 | 33 | `title` text NOT NULL, |
34 | 34 | `description` text NOT NULL |
35 | 35 | )" |
36 | - ); |
|
37 | - $extendedPdo->exec(" |
|
36 | + ); |
|
37 | + $extendedPdo->exec(" |
|
38 | 38 | CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`series_post` ( |
39 | 39 | `series` integer NOT NULL, |
40 | 40 | `post` integer NOT NULL, |
41 | 41 | `order` integer(1) NOT NULL |
42 | 42 | )" |
43 | - ); |
|
44 | - |
|
45 | - self::$connection = new ConnectionLocator(function () use ($extendedPdo) { |
|
46 | - return $extendedPdo; |
|
47 | - }); |
|
48 | - } |
|
49 | - |
|
50 | - public function testIsInstanceOfSeriesRepository() |
|
51 | - { |
|
52 | - $repository = new MysqlSeriesRepository(self::$connection); |
|
53 | - |
|
54 | - $this->assertInstanceOf( |
|
55 | - 'Jacobemerick\Web\Domain\Blog\Series\MysqlSeriesRepository', |
|
56 | - $repository |
|
57 | - ); |
|
58 | - } |
|
59 | - |
|
60 | - public function testImplementsSeriesInterface() |
|
61 | - { |
|
62 | - $repository = new MysqlSeriesRepository(self::$connection); |
|
63 | - |
|
64 | - $this->assertInstanceOf( |
|
65 | - 'Jacobemerick\Web\Domain\Blog\Series\SeriesRepositoryInterface', |
|
66 | - $repository |
|
67 | - ); |
|
68 | - } |
|
69 | - |
|
70 | - public function testConstructSetsConnections() |
|
71 | - { |
|
72 | - $respository = new MysqlSeriesRepository(self::$connection); |
|
73 | - |
|
74 | - $this->assertAttributeSame( |
|
75 | - self::$connection, |
|
76 | - 'connections', |
|
77 | - $respository |
|
78 | - ); |
|
79 | - } |
|
80 | - |
|
81 | - public function testGetSeriesForPost() |
|
82 | - { |
|
83 | - $testPostData = [ |
|
84 | - [ |
|
85 | - 'id' => rand(1, 100), |
|
86 | - 'title' => 'test one', |
|
87 | - 'category' => 'test category', |
|
88 | - 'path' => 'test-one', |
|
89 | - 'display' => 1, |
|
90 | - ], |
|
91 | - [ |
|
92 | - 'id' => rand(101, 200), |
|
93 | - 'title' => 'test two', |
|
94 | - 'category' => 'test category', |
|
95 | - 'path' => 'test-two', |
|
96 | - 'display' => 1, |
|
97 | - ], |
|
98 | - ]; |
|
99 | - |
|
100 | - $testSeriesData = [ |
|
101 | - [ |
|
102 | - 'id' => rand(1, 100), |
|
103 | - 'title' => 'test one', |
|
104 | - 'description' => 'test description', |
|
105 | - ], |
|
106 | - ]; |
|
107 | - |
|
108 | - $testSeriesPostData = [ |
|
109 | - [ |
|
110 | - 'series' => reset($testSeriesData)['id'], |
|
111 | - 'post' => $testPostData[0]['id'], |
|
112 | - 'order' => 1, |
|
113 | - ], |
|
114 | - [ |
|
115 | - 'series' => reset($testSeriesData)['id'], |
|
116 | - 'post' => $testPostData[1]['id'], |
|
117 | - 'order' => 2, |
|
118 | - ], |
|
119 | - ]; |
|
120 | - |
|
121 | - array_walk($testPostData, [$this, 'insertPostData']); |
|
122 | - array_walk($testSeriesData, [$this, 'insertSeriesData']); |
|
123 | - array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']); |
|
124 | - |
|
125 | - $repository = new MysqlSeriesRepository(self::$connection); |
|
126 | - $data = $repository->getSeriesForPost(reset($testPostData)['id']); |
|
127 | - |
|
128 | - $this->assertNotFalse($data); |
|
129 | - $this->assertInternalType('array', $data); |
|
130 | - foreach ($testPostData as $key => $testPostRow) { |
|
131 | - $this->assertInternalType('array', $data[$key]); |
|
132 | - $this->assertArrayHasKey('series_title', $data[$key]); |
|
133 | - $this->assertEquals(reset($testSeriesData)['title'], $data[$key]['series_title']); |
|
134 | - $this->assertArrayHasKey('series_description', $data[$key]); |
|
135 | - $this->assertEquals(reset($testSeriesData)['description'], $data[$key]['series_description']); |
|
136 | - $this->assertArrayHasKey('post', $data[$key]); |
|
137 | - $this->assertEquals($testPostRow['id'], $data[$key]['post']); |
|
138 | - $this->assertArrayHasKey('title', $data[$key]); |
|
139 | - $this->assertEquals($testPostRow['title'], $data[$key]['title']); |
|
140 | - $this->assertArrayHasKey('category', $data[$key]); |
|
141 | - $this->assertEquals($testPostRow['category'], $data[$key]['category']); |
|
142 | - $this->assertArrayHasKey('path', $data[$key]); |
|
143 | - $this->assertEquals($testPostRow['path'], $data[$key]['path']); |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - public function testGetSeriesForPostOrder() {} |
|
148 | - |
|
149 | - public function testGetSeriesForPostSeriesFilter() {} |
|
150 | - |
|
151 | - public function testGetSeriesForPostInactive() {} |
|
152 | - |
|
153 | - public function testGetSeriesForPostFailure() {} |
|
154 | - |
|
155 | - protected function tearDown() |
|
156 | - { |
|
157 | - self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series`"); |
|
158 | - } |
|
159 | - |
|
160 | - public static function tearDownAfterClass() |
|
161 | - { |
|
162 | - self::$connection->getDefault()->disconnect(); |
|
163 | - unlink('jpemeric_blog.db'); |
|
164 | - } |
|
165 | - |
|
166 | - protected function insertPostData(array $data) |
|
167 | - { |
|
168 | - $defaultData = [ |
|
169 | - 'id' => null, |
|
170 | - 'title' => '', |
|
171 | - 'path' => '', |
|
172 | - 'category' => '', |
|
173 | - 'date' => '', |
|
174 | - 'body' => '', |
|
175 | - 'display' => 0, |
|
176 | - ]; |
|
177 | - |
|
178 | - $data = array_merge($defaultData, $data); |
|
179 | - |
|
180 | - return self::$connection->getDefault()->perform(" |
|
43 | + ); |
|
44 | + |
|
45 | + self::$connection = new ConnectionLocator(function () use ($extendedPdo) { |
|
46 | + return $extendedPdo; |
|
47 | + }); |
|
48 | + } |
|
49 | + |
|
50 | + public function testIsInstanceOfSeriesRepository() |
|
51 | + { |
|
52 | + $repository = new MysqlSeriesRepository(self::$connection); |
|
53 | + |
|
54 | + $this->assertInstanceOf( |
|
55 | + 'Jacobemerick\Web\Domain\Blog\Series\MysqlSeriesRepository', |
|
56 | + $repository |
|
57 | + ); |
|
58 | + } |
|
59 | + |
|
60 | + public function testImplementsSeriesInterface() |
|
61 | + { |
|
62 | + $repository = new MysqlSeriesRepository(self::$connection); |
|
63 | + |
|
64 | + $this->assertInstanceOf( |
|
65 | + 'Jacobemerick\Web\Domain\Blog\Series\SeriesRepositoryInterface', |
|
66 | + $repository |
|
67 | + ); |
|
68 | + } |
|
69 | + |
|
70 | + public function testConstructSetsConnections() |
|
71 | + { |
|
72 | + $respository = new MysqlSeriesRepository(self::$connection); |
|
73 | + |
|
74 | + $this->assertAttributeSame( |
|
75 | + self::$connection, |
|
76 | + 'connections', |
|
77 | + $respository |
|
78 | + ); |
|
79 | + } |
|
80 | + |
|
81 | + public function testGetSeriesForPost() |
|
82 | + { |
|
83 | + $testPostData = [ |
|
84 | + [ |
|
85 | + 'id' => rand(1, 100), |
|
86 | + 'title' => 'test one', |
|
87 | + 'category' => 'test category', |
|
88 | + 'path' => 'test-one', |
|
89 | + 'display' => 1, |
|
90 | + ], |
|
91 | + [ |
|
92 | + 'id' => rand(101, 200), |
|
93 | + 'title' => 'test two', |
|
94 | + 'category' => 'test category', |
|
95 | + 'path' => 'test-two', |
|
96 | + 'display' => 1, |
|
97 | + ], |
|
98 | + ]; |
|
99 | + |
|
100 | + $testSeriesData = [ |
|
101 | + [ |
|
102 | + 'id' => rand(1, 100), |
|
103 | + 'title' => 'test one', |
|
104 | + 'description' => 'test description', |
|
105 | + ], |
|
106 | + ]; |
|
107 | + |
|
108 | + $testSeriesPostData = [ |
|
109 | + [ |
|
110 | + 'series' => reset($testSeriesData)['id'], |
|
111 | + 'post' => $testPostData[0]['id'], |
|
112 | + 'order' => 1, |
|
113 | + ], |
|
114 | + [ |
|
115 | + 'series' => reset($testSeriesData)['id'], |
|
116 | + 'post' => $testPostData[1]['id'], |
|
117 | + 'order' => 2, |
|
118 | + ], |
|
119 | + ]; |
|
120 | + |
|
121 | + array_walk($testPostData, [$this, 'insertPostData']); |
|
122 | + array_walk($testSeriesData, [$this, 'insertSeriesData']); |
|
123 | + array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']); |
|
124 | + |
|
125 | + $repository = new MysqlSeriesRepository(self::$connection); |
|
126 | + $data = $repository->getSeriesForPost(reset($testPostData)['id']); |
|
127 | + |
|
128 | + $this->assertNotFalse($data); |
|
129 | + $this->assertInternalType('array', $data); |
|
130 | + foreach ($testPostData as $key => $testPostRow) { |
|
131 | + $this->assertInternalType('array', $data[$key]); |
|
132 | + $this->assertArrayHasKey('series_title', $data[$key]); |
|
133 | + $this->assertEquals(reset($testSeriesData)['title'], $data[$key]['series_title']); |
|
134 | + $this->assertArrayHasKey('series_description', $data[$key]); |
|
135 | + $this->assertEquals(reset($testSeriesData)['description'], $data[$key]['series_description']); |
|
136 | + $this->assertArrayHasKey('post', $data[$key]); |
|
137 | + $this->assertEquals($testPostRow['id'], $data[$key]['post']); |
|
138 | + $this->assertArrayHasKey('title', $data[$key]); |
|
139 | + $this->assertEquals($testPostRow['title'], $data[$key]['title']); |
|
140 | + $this->assertArrayHasKey('category', $data[$key]); |
|
141 | + $this->assertEquals($testPostRow['category'], $data[$key]['category']); |
|
142 | + $this->assertArrayHasKey('path', $data[$key]); |
|
143 | + $this->assertEquals($testPostRow['path'], $data[$key]['path']); |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + public function testGetSeriesForPostOrder() {} |
|
148 | + |
|
149 | + public function testGetSeriesForPostSeriesFilter() {} |
|
150 | + |
|
151 | + public function testGetSeriesForPostInactive() {} |
|
152 | + |
|
153 | + public function testGetSeriesForPostFailure() {} |
|
154 | + |
|
155 | + protected function tearDown() |
|
156 | + { |
|
157 | + self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series`"); |
|
158 | + } |
|
159 | + |
|
160 | + public static function tearDownAfterClass() |
|
161 | + { |
|
162 | + self::$connection->getDefault()->disconnect(); |
|
163 | + unlink('jpemeric_blog.db'); |
|
164 | + } |
|
165 | + |
|
166 | + protected function insertPostData(array $data) |
|
167 | + { |
|
168 | + $defaultData = [ |
|
169 | + 'id' => null, |
|
170 | + 'title' => '', |
|
171 | + 'path' => '', |
|
172 | + 'category' => '', |
|
173 | + 'date' => '', |
|
174 | + 'body' => '', |
|
175 | + 'display' => 0, |
|
176 | + ]; |
|
177 | + |
|
178 | + $data = array_merge($defaultData, $data); |
|
179 | + |
|
180 | + return self::$connection->getDefault()->perform(" |
|
181 | 181 | INSERT INTO `jpemeric_blog`.`post` |
182 | 182 | (id, title, path, category, date, body, display) |
183 | 183 | VALUES |
184 | 184 | (:id, :title, :path, :category, :date, :body, :display)", |
185 | - $data |
|
186 | - ); |
|
187 | - } |
|
185 | + $data |
|
186 | + ); |
|
187 | + } |
|
188 | 188 | |
189 | - protected function insertSeriesData(array $data) |
|
190 | - { |
|
191 | - $defaultData = [ |
|
192 | - 'id' => null, |
|
193 | - 'title' => '', |
|
194 | - 'description' => '', |
|
195 | - ]; |
|
189 | + protected function insertSeriesData(array $data) |
|
190 | + { |
|
191 | + $defaultData = [ |
|
192 | + 'id' => null, |
|
193 | + 'title' => '', |
|
194 | + 'description' => '', |
|
195 | + ]; |
|
196 | 196 | |
197 | - $data = array_merge($defaultData, $data); |
|
197 | + $data = array_merge($defaultData, $data); |
|
198 | 198 | |
199 | - return self::$connection->getDefault()->perform(" |
|
199 | + return self::$connection->getDefault()->perform(" |
|
200 | 200 | INSERT INTO `jpemeric_blog`.`series` |
201 | 201 | (id, title, description) |
202 | 202 | VALUES |
203 | 203 | (:id, :title, :description)", |
204 | - $data |
|
205 | - ); |
|
206 | - } |
|
204 | + $data |
|
205 | + ); |
|
206 | + } |
|
207 | 207 | |
208 | - protected function insertSeriesPostData(array $data) |
|
209 | - { |
|
210 | - $defaultData = [ |
|
211 | - 'series' => '', |
|
212 | - 'post' => '', |
|
213 | - 'order' => 0, |
|
214 | - ]; |
|
208 | + protected function insertSeriesPostData(array $data) |
|
209 | + { |
|
210 | + $defaultData = [ |
|
211 | + 'series' => '', |
|
212 | + 'post' => '', |
|
213 | + 'order' => 0, |
|
214 | + ]; |
|
215 | 215 | |
216 | - $data = array_merge($defaultData, $data); |
|
216 | + $data = array_merge($defaultData, $data); |
|
217 | 217 | |
218 | - return self::$connection->getDefault()->perform(" |
|
218 | + return self::$connection->getDefault()->perform(" |
|
219 | 219 | INSERT INTO `jpemeric_blog`.`series_post` |
220 | 220 | (series, post, `order`) |
221 | 221 | VALUES |
222 | 222 | (:series, :post, :order)", |
223 | - $data |
|
224 | - ); |
|
225 | - } |
|
223 | + $data |
|
224 | + ); |
|
225 | + } |
|
226 | 226 | } |
@@ -9,14 +9,14 @@ discard block |
||
9 | 9 | class MysqlActivityRepositoryTest extends PHPUnit_Framework_TestCase |
10 | 10 | { |
11 | 11 | |
12 | - protected static $connection; |
|
12 | + protected static $connection; |
|
13 | 13 | |
14 | - public static function setUpBeforeClass() |
|
15 | - { |
|
16 | - $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
17 | - $extendedPdo->exec("ATTACH DATABASE `jpemeric_stream.db` AS `jpemeric_stream`"); |
|
14 | + public static function setUpBeforeClass() |
|
15 | + { |
|
16 | + $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
17 | + $extendedPdo->exec("ATTACH DATABASE `jpemeric_stream.db` AS `jpemeric_stream`"); |
|
18 | 18 | |
19 | - $extendedPdo->exec(" |
|
19 | + $extendedPdo->exec(" |
|
20 | 20 | CREATE TABLE IF NOT EXISTS `jpemeric_stream`.`activity` ( |
21 | 21 | `id` integer PRIMARY KEY AUTOINCREMENT, |
22 | 22 | `message` text NOT NULL, |
@@ -28,428 +28,428 @@ discard block |
||
28 | 28 | `created_at` datetime, |
29 | 29 | `updated_at` datetime |
30 | 30 | )" |
31 | - ); |
|
32 | - |
|
33 | - self::$connection = new ConnectionLocator(function () use ($extendedPdo) { |
|
34 | - return $extendedPdo; |
|
35 | - }); |
|
36 | - } |
|
37 | - |
|
38 | - public function testIsInstanceOfActivityRepository() |
|
39 | - { |
|
40 | - $repository = new MysqlActivityRepository(self::$connection); |
|
41 | - |
|
42 | - $this->assertInstanceOf( |
|
43 | - 'Jacobemerick\Web\Domain\Stream\Activity\MysqlActivityRepository', |
|
44 | - $repository |
|
45 | - ); |
|
46 | - } |
|
47 | - |
|
48 | - public function testImplementsActivityInterface() |
|
49 | - { |
|
50 | - $repository = new MysqlActivityRepository(self::$connection); |
|
51 | - |
|
52 | - $this->assertInstanceOf( |
|
53 | - 'Jacobemerick\Web\Domain\Stream\Activity\ActivityRepositoryInterface', |
|
54 | - $repository |
|
55 | - ); |
|
56 | - } |
|
57 | - |
|
58 | - public function testConstructSetsConnections() |
|
59 | - { |
|
60 | - $respository = new MysqlActivityRepository(self::$connection); |
|
61 | - |
|
62 | - $this->assertAttributeSame( |
|
63 | - self::$connection, |
|
64 | - 'connections', |
|
65 | - $respository |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - public function testGetActivityById() |
|
70 | - { |
|
71 | - $testData = [ |
|
72 | - 'id' => rand(1, 100), |
|
73 | - 'message' => 'test data', |
|
74 | - ]; |
|
75 | - |
|
76 | - $this->insertData($testData); |
|
77 | - |
|
78 | - $repository = new MysqlActivityRepository(self::$connection); |
|
79 | - $data = $repository->getActivityById($testData['id']); |
|
80 | - |
|
81 | - $this->assertNotFalse($data); |
|
82 | - $this->assertInternalType('array', $data); |
|
83 | - $this->assertArraySubset($testData, $data); |
|
84 | - } |
|
85 | - |
|
86 | - public function testGetActivityByIdFailure() |
|
87 | - { |
|
88 | - $testData = [ |
|
89 | - 'id' => rand(1, 100), |
|
90 | - 'message' => 'test data', |
|
91 | - ]; |
|
92 | - |
|
93 | - $this->insertData($testData); |
|
94 | - |
|
95 | - $repository = new MysqlActivityRepository(self::$connection); |
|
96 | - $data = $repository->getActivityById($testData['id'] + 1); |
|
97 | - |
|
98 | - $this->assertFalse($data); |
|
99 | - } |
|
100 | - |
|
101 | - public function testGetActivities() |
|
102 | - { |
|
103 | - $testData = [ |
|
104 | - [ |
|
105 | - 'id' => rand(1, 100), |
|
106 | - 'message' => 'test one', |
|
107 | - ], |
|
108 | - [ |
|
109 | - 'id' => rand(101, 200), |
|
110 | - 'message' => 'test two', |
|
111 | - ], |
|
112 | - ]; |
|
113 | - |
|
114 | - array_walk($testData, [$this, 'insertData']); |
|
115 | - |
|
116 | - $repository = new MysqlActivityRepository(self::$connection); |
|
117 | - $data = $repository->getActivities(); |
|
118 | - |
|
119 | - $this->assertNotFalse($data); |
|
120 | - $this->assertInternalType('array', $data); |
|
121 | - foreach ($testData as $key => $testRow) { |
|
122 | - $this->assertInternalType('array', $data[$key]); |
|
123 | - $this->assertArraySubset($testRow, $data[$key]); |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - public function testGetActivitiesFailure() |
|
128 | - { |
|
129 | - $repository = new MysqlActivityRepository(self::$connection); |
|
130 | - $data = $repository->getActivities(); |
|
131 | - |
|
132 | - $this->assertEmpty($data); |
|
133 | - $this->assertInternalType('array', $data); |
|
134 | - } |
|
135 | - |
|
136 | - public function testGetActivitiesRange() |
|
137 | - { |
|
138 | - $testData = [ |
|
139 | - [ |
|
140 | - 'id' => rand(1, 100), |
|
141 | - 'message' => 'test one', |
|
142 | - ], |
|
143 | - [ |
|
144 | - 'id' => rand(101, 200), |
|
145 | - 'message' => 'test two', |
|
146 | - ], |
|
147 | - [ |
|
148 | - 'id' => rand(201, 300), |
|
149 | - 'message' => 'test three', |
|
150 | - ], |
|
151 | - ]; |
|
152 | - |
|
153 | - array_walk($testData, [$this, 'insertData']); |
|
154 | - |
|
155 | - $repository = new MysqlActivityRepository(self::$connection); |
|
156 | - $data = $repository->getActivities(2, 1); |
|
157 | - |
|
158 | - $this->assertNotFalse($data); |
|
159 | - $this->assertInternalType('array', $data); |
|
160 | - $this->assertCount(2, $data); |
|
161 | - |
|
162 | - $testData = array_slice($testData, 1, 2); |
|
163 | - |
|
164 | - foreach ($testData as $key => $testRow) { |
|
165 | - $this->assertInternalType('array', $data[$key]); |
|
166 | - $this->assertArraySubset($testRow, $data[$key]); |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - public function testGetActivitiesRangeFailure() |
|
171 | - { |
|
172 | - $testData = [ |
|
173 | - [ |
|
174 | - 'id' => rand(1, 100), |
|
175 | - 'message' => 'test one', |
|
176 | - ], |
|
177 | - [ |
|
178 | - 'id' => rand(101, 200), |
|
179 | - 'message' => 'test two', |
|
180 | - ], |
|
181 | - ]; |
|
182 | - |
|
183 | - array_walk($testData, [$this, 'insertData']); |
|
184 | - |
|
185 | - $repository = new MysqlActivityRepository(self::$connection); |
|
186 | - $data = $repository->getActivities(1, 3); |
|
187 | - |
|
188 | - $this->assertEmpty($data); |
|
189 | - $this->assertInternalType('array', $data); |
|
190 | - } |
|
191 | - |
|
192 | - public function testGetActivitiesCount() |
|
193 | - { |
|
194 | - $testData = [ |
|
195 | - [ |
|
196 | - 'id' => rand(1, 100), |
|
197 | - 'message' => 'test one', |
|
198 | - ], |
|
199 | - [ |
|
200 | - 'id' => rand(101, 200), |
|
201 | - 'message' => 'test two', |
|
202 | - ], |
|
203 | - ]; |
|
204 | - |
|
205 | - array_walk($testData, [$this, 'insertData']); |
|
206 | - |
|
207 | - $repository = new MysqlActivityRepository(self::$connection); |
|
208 | - $data = $repository->getActivitiesCount(); |
|
209 | - |
|
210 | - $this->assertNotFalse($data); |
|
211 | - $this->assertStringMatchesFormat('%d', $data); |
|
212 | - $this->assertEquals(count($testData), $data); |
|
213 | - } |
|
214 | - |
|
215 | - public function testGetActivitiesCountEmpty() |
|
216 | - { |
|
217 | - $repository = new MysqlActivityRepository(self::$connection); |
|
218 | - $data = $repository->getActivitiesCount(); |
|
219 | - |
|
220 | - $this->assertNotFalse($data); |
|
221 | - $this->assertStringMatchesFormat('%d', $data); |
|
222 | - $this->assertEquals('0', $data); |
|
223 | - } |
|
224 | - |
|
225 | - public function testGetActivitiesByType() |
|
226 | - { |
|
227 | - $testData = [ |
|
228 | - [ |
|
229 | - 'id' => rand(1, 100), |
|
230 | - 'message' => 'test one', |
|
231 | - 'type' => 'type one', |
|
232 | - ], |
|
233 | - [ |
|
234 | - 'id' => rand(101, 200), |
|
235 | - 'message' => 'test two', |
|
236 | - 'type' => 'type two', |
|
237 | - ], |
|
238 | - [ |
|
239 | - 'id' => rand(201, 300), |
|
240 | - 'message' => 'test three', |
|
241 | - 'type' => 'type one', |
|
242 | - ], |
|
243 | - ]; |
|
244 | - |
|
245 | - array_walk($testData, [$this, 'insertData']); |
|
246 | - |
|
247 | - $repository = new MysqlActivityRepository(self::$connection); |
|
248 | - $data = $repository->getActivitiesByType('type one'); |
|
249 | - |
|
250 | - $this->assertNotFalse($data); |
|
251 | - $this->assertInternalType('array', $data); |
|
252 | - |
|
253 | - $testData = array_filter($testData, function ($row) { |
|
254 | - return ($row['type'] == 'type one'); |
|
255 | - }); |
|
256 | - $testData = array_values($testData); |
|
257 | - |
|
258 | - foreach ($testData as $key => $testRow) { |
|
259 | - $this->assertInternalType('array', $data[$key]); |
|
260 | - $this->assertArraySubset($testRow, $data[$key]); |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - public function testGetActivitiesByTypeFailure() |
|
265 | - { |
|
266 | - $testData = [ |
|
267 | - [ |
|
268 | - 'id' => rand(1, 100), |
|
269 | - 'message' => 'test one', |
|
270 | - 'type' => 'type one', |
|
271 | - ], |
|
272 | - [ |
|
273 | - 'id' => rand(101, 200), |
|
274 | - 'message' => 'test two', |
|
275 | - 'type' => 'type one', |
|
276 | - ], |
|
277 | - ]; |
|
278 | - |
|
279 | - array_walk($testData, [$this, 'insertData']); |
|
280 | - |
|
281 | - $repository = new MysqlActivityRepository(self::$connection); |
|
282 | - $data = $repository->getActivitiesByType('type two'); |
|
283 | - |
|
284 | - $this->assertEmpty($data); |
|
285 | - $this->assertInternalType('array', $data); |
|
286 | - } |
|
287 | - |
|
288 | - public function testGetActivitiesByTypeRange() |
|
289 | - { |
|
290 | - $testData = [ |
|
291 | - [ |
|
292 | - 'id' => rand(1, 100), |
|
293 | - 'message' => 'test one', |
|
294 | - 'type' => 'type one', |
|
295 | - ], |
|
296 | - [ |
|
297 | - 'id' => rand(101, 200), |
|
298 | - 'message' => 'test two', |
|
299 | - 'type' => 'type two', |
|
300 | - ], |
|
301 | - [ |
|
302 | - 'id' => rand(201, 300), |
|
303 | - 'message' => 'test three', |
|
304 | - 'type' => 'type one', |
|
305 | - ], |
|
306 | - [ |
|
307 | - 'id' => rand(301, 400), |
|
308 | - 'message' => 'test four', |
|
309 | - 'type' => 'type one', |
|
310 | - ], |
|
311 | - ]; |
|
312 | - |
|
313 | - array_walk($testData, [$this, 'insertData']); |
|
314 | - |
|
315 | - $repository = new MysqlActivityRepository(self::$connection); |
|
316 | - $data = $repository->getActivitiesByType('type one', 2, 1); |
|
317 | - |
|
318 | - $this->assertNotFalse($data); |
|
319 | - $this->assertInternalType('array', $data); |
|
320 | - $this->assertCount(2, $data); |
|
321 | - |
|
322 | - $testData = array_filter($testData, function ($row) { |
|
323 | - return ($row['type'] == 'type one'); |
|
324 | - }); |
|
325 | - $testData = array_values($testData); |
|
326 | - $testData = array_slice($testData, 1, 2); |
|
327 | - |
|
328 | - foreach ($testData as $key => $testRow) { |
|
329 | - $this->assertInternalType('array', $data[$key]); |
|
330 | - $this->assertArraySubset($testRow, $data[$key]); |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - public function testGetActivitiesByTypeRangeFailure() |
|
335 | - { |
|
336 | - $testData = [ |
|
337 | - [ |
|
338 | - 'id' => rand(1, 100), |
|
339 | - 'message' => 'test one', |
|
340 | - 'type' => 'type one', |
|
341 | - ], |
|
342 | - [ |
|
343 | - 'id' => rand(101, 200), |
|
344 | - 'message' => 'test two', |
|
345 | - 'type' => 'type one', |
|
346 | - ], |
|
347 | - [ |
|
348 | - 'id' => rand(201, 300), |
|
349 | - 'message' => 'test three', |
|
350 | - 'type' => 'type one', |
|
351 | - ], |
|
352 | - ]; |
|
353 | - |
|
354 | - array_walk($testData, [$this, 'insertData']); |
|
355 | - |
|
356 | - $repository = new MysqlActivityRepository(self::$connection); |
|
357 | - $data = $repository->getActivitiesByType('type two', 2, 1); |
|
358 | - |
|
359 | - $this->assertEmpty($data); |
|
360 | - $this->assertInternalType('array', $data); |
|
361 | - } |
|
362 | - |
|
363 | - public function testGetActivitiesByTypeCount() |
|
364 | - { |
|
365 | - $testData = [ |
|
366 | - [ |
|
367 | - 'id' => rand(1, 100), |
|
368 | - 'message' => 'test one', |
|
369 | - 'type' => 'type one', |
|
370 | - ], |
|
371 | - [ |
|
372 | - 'id' => rand(101, 200), |
|
373 | - 'message' => 'test two', |
|
374 | - 'type' => 'type two', |
|
375 | - ], |
|
376 | - [ |
|
377 | - 'id' => rand(201, 300), |
|
378 | - 'message' => 'test three', |
|
379 | - 'type' => 'type one', |
|
380 | - ], |
|
381 | - ]; |
|
382 | - |
|
383 | - array_walk($testData, [$this, 'insertData']); |
|
384 | - |
|
385 | - $repository = new MysqlActivityRepository(self::$connection); |
|
386 | - $data = $repository->getActivitiesByTypeCount('type one'); |
|
387 | - |
|
388 | - $testData = array_filter($testData, function ($row) { |
|
389 | - return ($row['type'] == 'type one'); |
|
390 | - }); |
|
391 | - |
|
392 | - $this->assertNotFalse($data); |
|
393 | - $this->assertStringMatchesFormat('%d', $data); |
|
394 | - $this->assertEquals(count($testData), $data); |
|
395 | - } |
|
396 | - |
|
397 | - public function testGetActivitiesByTypeCountEmpty() |
|
398 | - { |
|
399 | - $testData = [ |
|
400 | - [ |
|
401 | - 'id' => rand(1, 100), |
|
402 | - 'message' => 'test one', |
|
403 | - 'type' => 'type one', |
|
404 | - ], |
|
405 | - [ |
|
406 | - 'id' => rand(101, 200), |
|
407 | - 'message' => 'test two', |
|
408 | - 'type' => 'type one', |
|
409 | - ], |
|
410 | - ]; |
|
411 | - |
|
412 | - array_walk($testData, [$this, 'insertData']); |
|
413 | - |
|
414 | - $repository = new MysqlActivityRepository(self::$connection); |
|
415 | - $data = $repository->getActivitiesByTypeCount('type two'); |
|
416 | - |
|
417 | - $this->assertNotFalse($data); |
|
418 | - $this->assertStringMatchesFormat('%d', $data); |
|
419 | - $this->assertEquals('0', $data); |
|
420 | - } |
|
421 | - |
|
422 | - protected function tearDown() |
|
423 | - { |
|
424 | - self::$connection->getDefault()->perform("DELETE FROM `jpemeric_stream`.`activity`"); |
|
425 | - } |
|
426 | - |
|
427 | - public static function tearDownAfterClass() |
|
428 | - { |
|
429 | - self::$connection->getDefault()->disconnect(); |
|
430 | - unlink('jpemeric_stream.db'); |
|
431 | - } |
|
432 | - |
|
433 | - protected function insertData(array $data) |
|
434 | - { |
|
435 | - $defaultData = [ |
|
436 | - 'id' => null, |
|
437 | - 'message' => '', |
|
438 | - 'message_long' => '', |
|
439 | - 'datetime' => '', |
|
440 | - 'metadata' => '', |
|
441 | - 'type' => '', |
|
442 | - 'type_id' => '', |
|
443 | - ]; |
|
444 | - |
|
445 | - $data = array_merge($defaultData, $data); |
|
446 | - |
|
447 | - return self::$connection->getDefault()->perform(" |
|
31 | + ); |
|
32 | + |
|
33 | + self::$connection = new ConnectionLocator(function () use ($extendedPdo) { |
|
34 | + return $extendedPdo; |
|
35 | + }); |
|
36 | + } |
|
37 | + |
|
38 | + public function testIsInstanceOfActivityRepository() |
|
39 | + { |
|
40 | + $repository = new MysqlActivityRepository(self::$connection); |
|
41 | + |
|
42 | + $this->assertInstanceOf( |
|
43 | + 'Jacobemerick\Web\Domain\Stream\Activity\MysqlActivityRepository', |
|
44 | + $repository |
|
45 | + ); |
|
46 | + } |
|
47 | + |
|
48 | + public function testImplementsActivityInterface() |
|
49 | + { |
|
50 | + $repository = new MysqlActivityRepository(self::$connection); |
|
51 | + |
|
52 | + $this->assertInstanceOf( |
|
53 | + 'Jacobemerick\Web\Domain\Stream\Activity\ActivityRepositoryInterface', |
|
54 | + $repository |
|
55 | + ); |
|
56 | + } |
|
57 | + |
|
58 | + public function testConstructSetsConnections() |
|
59 | + { |
|
60 | + $respository = new MysqlActivityRepository(self::$connection); |
|
61 | + |
|
62 | + $this->assertAttributeSame( |
|
63 | + self::$connection, |
|
64 | + 'connections', |
|
65 | + $respository |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + public function testGetActivityById() |
|
70 | + { |
|
71 | + $testData = [ |
|
72 | + 'id' => rand(1, 100), |
|
73 | + 'message' => 'test data', |
|
74 | + ]; |
|
75 | + |
|
76 | + $this->insertData($testData); |
|
77 | + |
|
78 | + $repository = new MysqlActivityRepository(self::$connection); |
|
79 | + $data = $repository->getActivityById($testData['id']); |
|
80 | + |
|
81 | + $this->assertNotFalse($data); |
|
82 | + $this->assertInternalType('array', $data); |
|
83 | + $this->assertArraySubset($testData, $data); |
|
84 | + } |
|
85 | + |
|
86 | + public function testGetActivityByIdFailure() |
|
87 | + { |
|
88 | + $testData = [ |
|
89 | + 'id' => rand(1, 100), |
|
90 | + 'message' => 'test data', |
|
91 | + ]; |
|
92 | + |
|
93 | + $this->insertData($testData); |
|
94 | + |
|
95 | + $repository = new MysqlActivityRepository(self::$connection); |
|
96 | + $data = $repository->getActivityById($testData['id'] + 1); |
|
97 | + |
|
98 | + $this->assertFalse($data); |
|
99 | + } |
|
100 | + |
|
101 | + public function testGetActivities() |
|
102 | + { |
|
103 | + $testData = [ |
|
104 | + [ |
|
105 | + 'id' => rand(1, 100), |
|
106 | + 'message' => 'test one', |
|
107 | + ], |
|
108 | + [ |
|
109 | + 'id' => rand(101, 200), |
|
110 | + 'message' => 'test two', |
|
111 | + ], |
|
112 | + ]; |
|
113 | + |
|
114 | + array_walk($testData, [$this, 'insertData']); |
|
115 | + |
|
116 | + $repository = new MysqlActivityRepository(self::$connection); |
|
117 | + $data = $repository->getActivities(); |
|
118 | + |
|
119 | + $this->assertNotFalse($data); |
|
120 | + $this->assertInternalType('array', $data); |
|
121 | + foreach ($testData as $key => $testRow) { |
|
122 | + $this->assertInternalType('array', $data[$key]); |
|
123 | + $this->assertArraySubset($testRow, $data[$key]); |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + public function testGetActivitiesFailure() |
|
128 | + { |
|
129 | + $repository = new MysqlActivityRepository(self::$connection); |
|
130 | + $data = $repository->getActivities(); |
|
131 | + |
|
132 | + $this->assertEmpty($data); |
|
133 | + $this->assertInternalType('array', $data); |
|
134 | + } |
|
135 | + |
|
136 | + public function testGetActivitiesRange() |
|
137 | + { |
|
138 | + $testData = [ |
|
139 | + [ |
|
140 | + 'id' => rand(1, 100), |
|
141 | + 'message' => 'test one', |
|
142 | + ], |
|
143 | + [ |
|
144 | + 'id' => rand(101, 200), |
|
145 | + 'message' => 'test two', |
|
146 | + ], |
|
147 | + [ |
|
148 | + 'id' => rand(201, 300), |
|
149 | + 'message' => 'test three', |
|
150 | + ], |
|
151 | + ]; |
|
152 | + |
|
153 | + array_walk($testData, [$this, 'insertData']); |
|
154 | + |
|
155 | + $repository = new MysqlActivityRepository(self::$connection); |
|
156 | + $data = $repository->getActivities(2, 1); |
|
157 | + |
|
158 | + $this->assertNotFalse($data); |
|
159 | + $this->assertInternalType('array', $data); |
|
160 | + $this->assertCount(2, $data); |
|
161 | + |
|
162 | + $testData = array_slice($testData, 1, 2); |
|
163 | + |
|
164 | + foreach ($testData as $key => $testRow) { |
|
165 | + $this->assertInternalType('array', $data[$key]); |
|
166 | + $this->assertArraySubset($testRow, $data[$key]); |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + public function testGetActivitiesRangeFailure() |
|
171 | + { |
|
172 | + $testData = [ |
|
173 | + [ |
|
174 | + 'id' => rand(1, 100), |
|
175 | + 'message' => 'test one', |
|
176 | + ], |
|
177 | + [ |
|
178 | + 'id' => rand(101, 200), |
|
179 | + 'message' => 'test two', |
|
180 | + ], |
|
181 | + ]; |
|
182 | + |
|
183 | + array_walk($testData, [$this, 'insertData']); |
|
184 | + |
|
185 | + $repository = new MysqlActivityRepository(self::$connection); |
|
186 | + $data = $repository->getActivities(1, 3); |
|
187 | + |
|
188 | + $this->assertEmpty($data); |
|
189 | + $this->assertInternalType('array', $data); |
|
190 | + } |
|
191 | + |
|
192 | + public function testGetActivitiesCount() |
|
193 | + { |
|
194 | + $testData = [ |
|
195 | + [ |
|
196 | + 'id' => rand(1, 100), |
|
197 | + 'message' => 'test one', |
|
198 | + ], |
|
199 | + [ |
|
200 | + 'id' => rand(101, 200), |
|
201 | + 'message' => 'test two', |
|
202 | + ], |
|
203 | + ]; |
|
204 | + |
|
205 | + array_walk($testData, [$this, 'insertData']); |
|
206 | + |
|
207 | + $repository = new MysqlActivityRepository(self::$connection); |
|
208 | + $data = $repository->getActivitiesCount(); |
|
209 | + |
|
210 | + $this->assertNotFalse($data); |
|
211 | + $this->assertStringMatchesFormat('%d', $data); |
|
212 | + $this->assertEquals(count($testData), $data); |
|
213 | + } |
|
214 | + |
|
215 | + public function testGetActivitiesCountEmpty() |
|
216 | + { |
|
217 | + $repository = new MysqlActivityRepository(self::$connection); |
|
218 | + $data = $repository->getActivitiesCount(); |
|
219 | + |
|
220 | + $this->assertNotFalse($data); |
|
221 | + $this->assertStringMatchesFormat('%d', $data); |
|
222 | + $this->assertEquals('0', $data); |
|
223 | + } |
|
224 | + |
|
225 | + public function testGetActivitiesByType() |
|
226 | + { |
|
227 | + $testData = [ |
|
228 | + [ |
|
229 | + 'id' => rand(1, 100), |
|
230 | + 'message' => 'test one', |
|
231 | + 'type' => 'type one', |
|
232 | + ], |
|
233 | + [ |
|
234 | + 'id' => rand(101, 200), |
|
235 | + 'message' => 'test two', |
|
236 | + 'type' => 'type two', |
|
237 | + ], |
|
238 | + [ |
|
239 | + 'id' => rand(201, 300), |
|
240 | + 'message' => 'test three', |
|
241 | + 'type' => 'type one', |
|
242 | + ], |
|
243 | + ]; |
|
244 | + |
|
245 | + array_walk($testData, [$this, 'insertData']); |
|
246 | + |
|
247 | + $repository = new MysqlActivityRepository(self::$connection); |
|
248 | + $data = $repository->getActivitiesByType('type one'); |
|
249 | + |
|
250 | + $this->assertNotFalse($data); |
|
251 | + $this->assertInternalType('array', $data); |
|
252 | + |
|
253 | + $testData = array_filter($testData, function ($row) { |
|
254 | + return ($row['type'] == 'type one'); |
|
255 | + }); |
|
256 | + $testData = array_values($testData); |
|
257 | + |
|
258 | + foreach ($testData as $key => $testRow) { |
|
259 | + $this->assertInternalType('array', $data[$key]); |
|
260 | + $this->assertArraySubset($testRow, $data[$key]); |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + public function testGetActivitiesByTypeFailure() |
|
265 | + { |
|
266 | + $testData = [ |
|
267 | + [ |
|
268 | + 'id' => rand(1, 100), |
|
269 | + 'message' => 'test one', |
|
270 | + 'type' => 'type one', |
|
271 | + ], |
|
272 | + [ |
|
273 | + 'id' => rand(101, 200), |
|
274 | + 'message' => 'test two', |
|
275 | + 'type' => 'type one', |
|
276 | + ], |
|
277 | + ]; |
|
278 | + |
|
279 | + array_walk($testData, [$this, 'insertData']); |
|
280 | + |
|
281 | + $repository = new MysqlActivityRepository(self::$connection); |
|
282 | + $data = $repository->getActivitiesByType('type two'); |
|
283 | + |
|
284 | + $this->assertEmpty($data); |
|
285 | + $this->assertInternalType('array', $data); |
|
286 | + } |
|
287 | + |
|
288 | + public function testGetActivitiesByTypeRange() |
|
289 | + { |
|
290 | + $testData = [ |
|
291 | + [ |
|
292 | + 'id' => rand(1, 100), |
|
293 | + 'message' => 'test one', |
|
294 | + 'type' => 'type one', |
|
295 | + ], |
|
296 | + [ |
|
297 | + 'id' => rand(101, 200), |
|
298 | + 'message' => 'test two', |
|
299 | + 'type' => 'type two', |
|
300 | + ], |
|
301 | + [ |
|
302 | + 'id' => rand(201, 300), |
|
303 | + 'message' => 'test three', |
|
304 | + 'type' => 'type one', |
|
305 | + ], |
|
306 | + [ |
|
307 | + 'id' => rand(301, 400), |
|
308 | + 'message' => 'test four', |
|
309 | + 'type' => 'type one', |
|
310 | + ], |
|
311 | + ]; |
|
312 | + |
|
313 | + array_walk($testData, [$this, 'insertData']); |
|
314 | + |
|
315 | + $repository = new MysqlActivityRepository(self::$connection); |
|
316 | + $data = $repository->getActivitiesByType('type one', 2, 1); |
|
317 | + |
|
318 | + $this->assertNotFalse($data); |
|
319 | + $this->assertInternalType('array', $data); |
|
320 | + $this->assertCount(2, $data); |
|
321 | + |
|
322 | + $testData = array_filter($testData, function ($row) { |
|
323 | + return ($row['type'] == 'type one'); |
|
324 | + }); |
|
325 | + $testData = array_values($testData); |
|
326 | + $testData = array_slice($testData, 1, 2); |
|
327 | + |
|
328 | + foreach ($testData as $key => $testRow) { |
|
329 | + $this->assertInternalType('array', $data[$key]); |
|
330 | + $this->assertArraySubset($testRow, $data[$key]); |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + public function testGetActivitiesByTypeRangeFailure() |
|
335 | + { |
|
336 | + $testData = [ |
|
337 | + [ |
|
338 | + 'id' => rand(1, 100), |
|
339 | + 'message' => 'test one', |
|
340 | + 'type' => 'type one', |
|
341 | + ], |
|
342 | + [ |
|
343 | + 'id' => rand(101, 200), |
|
344 | + 'message' => 'test two', |
|
345 | + 'type' => 'type one', |
|
346 | + ], |
|
347 | + [ |
|
348 | + 'id' => rand(201, 300), |
|
349 | + 'message' => 'test three', |
|
350 | + 'type' => 'type one', |
|
351 | + ], |
|
352 | + ]; |
|
353 | + |
|
354 | + array_walk($testData, [$this, 'insertData']); |
|
355 | + |
|
356 | + $repository = new MysqlActivityRepository(self::$connection); |
|
357 | + $data = $repository->getActivitiesByType('type two', 2, 1); |
|
358 | + |
|
359 | + $this->assertEmpty($data); |
|
360 | + $this->assertInternalType('array', $data); |
|
361 | + } |
|
362 | + |
|
363 | + public function testGetActivitiesByTypeCount() |
|
364 | + { |
|
365 | + $testData = [ |
|
366 | + [ |
|
367 | + 'id' => rand(1, 100), |
|
368 | + 'message' => 'test one', |
|
369 | + 'type' => 'type one', |
|
370 | + ], |
|
371 | + [ |
|
372 | + 'id' => rand(101, 200), |
|
373 | + 'message' => 'test two', |
|
374 | + 'type' => 'type two', |
|
375 | + ], |
|
376 | + [ |
|
377 | + 'id' => rand(201, 300), |
|
378 | + 'message' => 'test three', |
|
379 | + 'type' => 'type one', |
|
380 | + ], |
|
381 | + ]; |
|
382 | + |
|
383 | + array_walk($testData, [$this, 'insertData']); |
|
384 | + |
|
385 | + $repository = new MysqlActivityRepository(self::$connection); |
|
386 | + $data = $repository->getActivitiesByTypeCount('type one'); |
|
387 | + |
|
388 | + $testData = array_filter($testData, function ($row) { |
|
389 | + return ($row['type'] == 'type one'); |
|
390 | + }); |
|
391 | + |
|
392 | + $this->assertNotFalse($data); |
|
393 | + $this->assertStringMatchesFormat('%d', $data); |
|
394 | + $this->assertEquals(count($testData), $data); |
|
395 | + } |
|
396 | + |
|
397 | + public function testGetActivitiesByTypeCountEmpty() |
|
398 | + { |
|
399 | + $testData = [ |
|
400 | + [ |
|
401 | + 'id' => rand(1, 100), |
|
402 | + 'message' => 'test one', |
|
403 | + 'type' => 'type one', |
|
404 | + ], |
|
405 | + [ |
|
406 | + 'id' => rand(101, 200), |
|
407 | + 'message' => 'test two', |
|
408 | + 'type' => 'type one', |
|
409 | + ], |
|
410 | + ]; |
|
411 | + |
|
412 | + array_walk($testData, [$this, 'insertData']); |
|
413 | + |
|
414 | + $repository = new MysqlActivityRepository(self::$connection); |
|
415 | + $data = $repository->getActivitiesByTypeCount('type two'); |
|
416 | + |
|
417 | + $this->assertNotFalse($data); |
|
418 | + $this->assertStringMatchesFormat('%d', $data); |
|
419 | + $this->assertEquals('0', $data); |
|
420 | + } |
|
421 | + |
|
422 | + protected function tearDown() |
|
423 | + { |
|
424 | + self::$connection->getDefault()->perform("DELETE FROM `jpemeric_stream`.`activity`"); |
|
425 | + } |
|
426 | + |
|
427 | + public static function tearDownAfterClass() |
|
428 | + { |
|
429 | + self::$connection->getDefault()->disconnect(); |
|
430 | + unlink('jpemeric_stream.db'); |
|
431 | + } |
|
432 | + |
|
433 | + protected function insertData(array $data) |
|
434 | + { |
|
435 | + $defaultData = [ |
|
436 | + 'id' => null, |
|
437 | + 'message' => '', |
|
438 | + 'message_long' => '', |
|
439 | + 'datetime' => '', |
|
440 | + 'metadata' => '', |
|
441 | + 'type' => '', |
|
442 | + 'type_id' => '', |
|
443 | + ]; |
|
444 | + |
|
445 | + $data = array_merge($defaultData, $data); |
|
446 | + |
|
447 | + return self::$connection->getDefault()->perform(" |
|
448 | 448 | INSERT INTO `jpemeric_stream`.`activity` |
449 | 449 | (id, message, message_long, datetime, metadata, type, type_id) |
450 | 450 | VALUES |
451 | 451 | (:id, :message, :message_long, :datetime, :metadata, :type, :type_id)", |
452 | - $data |
|
453 | - ); |
|
454 | - } |
|
452 | + $data |
|
453 | + ); |
|
454 | + } |
|
455 | 455 | } |
@@ -9,14 +9,14 @@ discard block |
||
9 | 9 | class MysqlChangelogRepositoryTest extends PHPUnit_Framework_TestCase |
10 | 10 | { |
11 | 11 | |
12 | - protected static $connection; |
|
12 | + protected static $connection; |
|
13 | 13 | |
14 | - public static function setUpBeforeClass() |
|
15 | - { |
|
16 | - $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
17 | - $extendedPdo->exec("ATTACH DATABASE `jpemeric_stream.db` AS `jpemeric_stream`"); |
|
14 | + public static function setUpBeforeClass() |
|
15 | + { |
|
16 | + $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
17 | + $extendedPdo->exec("ATTACH DATABASE `jpemeric_stream.db` AS `jpemeric_stream`"); |
|
18 | 18 | |
19 | - $extendedPdo->exec(" |
|
19 | + $extendedPdo->exec(" |
|
20 | 20 | CREATE TABLE IF NOT EXISTS `jpemeric_stream`.`changelog` ( |
21 | 21 | `id` integer PRIMARY KEY AUTOINCREMENT, |
22 | 22 | `hash` char(40) NOT NULL, |
@@ -28,171 +28,171 @@ discard block |
||
28 | 28 | `created_at` datetime, |
29 | 29 | `updated_at` datetime |
30 | 30 | )" |
31 | - ); |
|
32 | - |
|
33 | - self::$connection = new ConnectionLocator(function () use ($extendedPdo) { |
|
34 | - return $extendedPdo; |
|
35 | - }); |
|
36 | - } |
|
37 | - |
|
38 | - public function testIsInstanceOfChangelogRepository() |
|
39 | - { |
|
40 | - $repository = new MysqlChangelogRepository(self::$connection); |
|
41 | - |
|
42 | - $this->assertInstanceOf( |
|
43 | - 'Jacobemerick\Web\Domain\Stream\Changelog\MysqlChangelogRepository', |
|
44 | - $repository |
|
45 | - ); |
|
46 | - } |
|
47 | - |
|
48 | - public function testImplementsChangelogInterface() |
|
49 | - { |
|
50 | - $repository = new MysqlChangelogRepository(self::$connection); |
|
51 | - |
|
52 | - $this->assertInstanceOf( |
|
53 | - 'Jacobemerick\Web\Domain\Stream\Changelog\ChangelogRepositoryInterface', |
|
54 | - $repository |
|
55 | - ); |
|
56 | - } |
|
57 | - |
|
58 | - public function testConstructSetsConnections() |
|
59 | - { |
|
60 | - $respository = new MysqlChangelogRepository(self::$connection); |
|
61 | - |
|
62 | - $this->assertAttributeSame( |
|
63 | - self::$connection, |
|
64 | - 'connections', |
|
65 | - $respository |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - public function testGetChanges() |
|
70 | - { |
|
71 | - $testData = [ |
|
72 | - [ |
|
73 | - 'id' => rand(1, 100), |
|
74 | - 'message' => 'test one', |
|
75 | - ], |
|
76 | - [ |
|
77 | - 'id' => rand(101, 200), |
|
78 | - 'message' => 'test two', |
|
79 | - ], |
|
80 | - ]; |
|
81 | - |
|
82 | - array_walk($testData, [$this, 'insertData']); |
|
83 | - |
|
84 | - $repository = new MysqlChangelogRepository(self::$connection); |
|
85 | - $data = $repository->getChanges(); |
|
86 | - |
|
87 | - $this->assertNotFalse($data); |
|
88 | - $this->assertInternalType('array', $data); |
|
89 | - foreach ($testData as $key => $testRow) { |
|
90 | - $this->assertInternalType('array', $data[$key]); |
|
91 | - $this->assertArraySubset($testRow, $data[$key]); |
|
92 | - $this->assertArrayHasKey('id', $data[$key]); |
|
93 | - $this->assertArrayHasKey('message', $data[$key]); |
|
94 | - $this->assertArrayHasKey('message_short', $data[$key]); |
|
95 | - $this->assertArrayHasKey('datetime', $data[$key]); |
|
96 | - $this->assertArrayHasKey('commit_link', $data[$key]); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - public function testGetChangesFailure() |
|
101 | - { |
|
102 | - $repository = new MysqlChangelogRepository(self::$connection); |
|
103 | - $data = $repository->getChanges(); |
|
104 | - |
|
105 | - $this->assertEmpty($data); |
|
106 | - $this->assertInternalType('array', $data); |
|
107 | - } |
|
108 | - |
|
109 | - public function testGetChangesRange() |
|
110 | - { |
|
111 | - $testData = [ |
|
112 | - [ |
|
113 | - 'id' => rand(1, 100), |
|
114 | - 'message' => 'test one', |
|
115 | - ], |
|
116 | - [ |
|
117 | - 'id' => rand(101, 200), |
|
118 | - 'message' => 'test two', |
|
119 | - ], |
|
120 | - [ |
|
121 | - 'id' => rand(201, 300), |
|
122 | - 'message' => 'test three', |
|
123 | - ], |
|
124 | - ]; |
|
125 | - |
|
126 | - array_walk($testData, [$this, 'insertData']); |
|
127 | - |
|
128 | - $repository = new MysqlChangelogRepository(self::$connection); |
|
129 | - $data = $repository->getChanges(2, 1); |
|
130 | - |
|
131 | - $this->assertNotFalse($data); |
|
132 | - $this->assertInternalType('array', $data); |
|
133 | - $this->assertCount(2, $data); |
|
134 | - |
|
135 | - $testData = array_slice($testData, 1, 2); |
|
136 | - |
|
137 | - foreach ($testData as $key => $testRow) { |
|
138 | - $this->assertInternalType('array', $testRow); |
|
139 | - $this->assertArraySubset($testRow, $data[$key]); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - public function testGetChangesRangeFailure() |
|
144 | - { |
|
145 | - $testData = [ |
|
146 | - [ |
|
147 | - 'id' => rand(1, 100), |
|
148 | - 'message' => 'test one', |
|
149 | - ], |
|
150 | - [ |
|
151 | - 'id' => rand(101, 200), |
|
152 | - 'message' => 'test two', |
|
153 | - ], |
|
154 | - ]; |
|
155 | - |
|
156 | - array_walk($testData, [$this, 'insertData']); |
|
157 | - |
|
158 | - $repository = new MysqlChangelogRepository(self::$connection); |
|
159 | - $data = $repository->getChanges(1, 3); |
|
160 | - |
|
161 | - $this->assertEmpty($data); |
|
162 | - $this->assertInternalType('array', $data); |
|
163 | - } |
|
164 | - |
|
165 | - protected function tearDown() |
|
166 | - { |
|
167 | - self::$connection->getDefault()->perform("DELETE FROM `jpemeric_stream`.`changelog`"); |
|
168 | - } |
|
169 | - |
|
170 | - public static function tearDownAfterClass() |
|
171 | - { |
|
172 | - self::$connection->getDefault()->disconnect(); |
|
173 | - unlink('jpemeric_stream.db'); |
|
174 | - } |
|
175 | - |
|
176 | - protected function insertData(array $data) |
|
177 | - { |
|
178 | - $defaultData = [ |
|
179 | - 'id' => null, |
|
180 | - 'hash' => '', |
|
181 | - 'message' => null, |
|
182 | - 'message_short' => null, |
|
183 | - 'datetime' => '', |
|
184 | - 'author' => '', |
|
185 | - 'commit_link' => '', |
|
186 | - ]; |
|
187 | - |
|
188 | - $data = array_merge($defaultData, $data); |
|
189 | - |
|
190 | - return self::$connection->getDefault()->perform(" |
|
31 | + ); |
|
32 | + |
|
33 | + self::$connection = new ConnectionLocator(function () use ($extendedPdo) { |
|
34 | + return $extendedPdo; |
|
35 | + }); |
|
36 | + } |
|
37 | + |
|
38 | + public function testIsInstanceOfChangelogRepository() |
|
39 | + { |
|
40 | + $repository = new MysqlChangelogRepository(self::$connection); |
|
41 | + |
|
42 | + $this->assertInstanceOf( |
|
43 | + 'Jacobemerick\Web\Domain\Stream\Changelog\MysqlChangelogRepository', |
|
44 | + $repository |
|
45 | + ); |
|
46 | + } |
|
47 | + |
|
48 | + public function testImplementsChangelogInterface() |
|
49 | + { |
|
50 | + $repository = new MysqlChangelogRepository(self::$connection); |
|
51 | + |
|
52 | + $this->assertInstanceOf( |
|
53 | + 'Jacobemerick\Web\Domain\Stream\Changelog\ChangelogRepositoryInterface', |
|
54 | + $repository |
|
55 | + ); |
|
56 | + } |
|
57 | + |
|
58 | + public function testConstructSetsConnections() |
|
59 | + { |
|
60 | + $respository = new MysqlChangelogRepository(self::$connection); |
|
61 | + |
|
62 | + $this->assertAttributeSame( |
|
63 | + self::$connection, |
|
64 | + 'connections', |
|
65 | + $respository |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + public function testGetChanges() |
|
70 | + { |
|
71 | + $testData = [ |
|
72 | + [ |
|
73 | + 'id' => rand(1, 100), |
|
74 | + 'message' => 'test one', |
|
75 | + ], |
|
76 | + [ |
|
77 | + 'id' => rand(101, 200), |
|
78 | + 'message' => 'test two', |
|
79 | + ], |
|
80 | + ]; |
|
81 | + |
|
82 | + array_walk($testData, [$this, 'insertData']); |
|
83 | + |
|
84 | + $repository = new MysqlChangelogRepository(self::$connection); |
|
85 | + $data = $repository->getChanges(); |
|
86 | + |
|
87 | + $this->assertNotFalse($data); |
|
88 | + $this->assertInternalType('array', $data); |
|
89 | + foreach ($testData as $key => $testRow) { |
|
90 | + $this->assertInternalType('array', $data[$key]); |
|
91 | + $this->assertArraySubset($testRow, $data[$key]); |
|
92 | + $this->assertArrayHasKey('id', $data[$key]); |
|
93 | + $this->assertArrayHasKey('message', $data[$key]); |
|
94 | + $this->assertArrayHasKey('message_short', $data[$key]); |
|
95 | + $this->assertArrayHasKey('datetime', $data[$key]); |
|
96 | + $this->assertArrayHasKey('commit_link', $data[$key]); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + public function testGetChangesFailure() |
|
101 | + { |
|
102 | + $repository = new MysqlChangelogRepository(self::$connection); |
|
103 | + $data = $repository->getChanges(); |
|
104 | + |
|
105 | + $this->assertEmpty($data); |
|
106 | + $this->assertInternalType('array', $data); |
|
107 | + } |
|
108 | + |
|
109 | + public function testGetChangesRange() |
|
110 | + { |
|
111 | + $testData = [ |
|
112 | + [ |
|
113 | + 'id' => rand(1, 100), |
|
114 | + 'message' => 'test one', |
|
115 | + ], |
|
116 | + [ |
|
117 | + 'id' => rand(101, 200), |
|
118 | + 'message' => 'test two', |
|
119 | + ], |
|
120 | + [ |
|
121 | + 'id' => rand(201, 300), |
|
122 | + 'message' => 'test three', |
|
123 | + ], |
|
124 | + ]; |
|
125 | + |
|
126 | + array_walk($testData, [$this, 'insertData']); |
|
127 | + |
|
128 | + $repository = new MysqlChangelogRepository(self::$connection); |
|
129 | + $data = $repository->getChanges(2, 1); |
|
130 | + |
|
131 | + $this->assertNotFalse($data); |
|
132 | + $this->assertInternalType('array', $data); |
|
133 | + $this->assertCount(2, $data); |
|
134 | + |
|
135 | + $testData = array_slice($testData, 1, 2); |
|
136 | + |
|
137 | + foreach ($testData as $key => $testRow) { |
|
138 | + $this->assertInternalType('array', $testRow); |
|
139 | + $this->assertArraySubset($testRow, $data[$key]); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + public function testGetChangesRangeFailure() |
|
144 | + { |
|
145 | + $testData = [ |
|
146 | + [ |
|
147 | + 'id' => rand(1, 100), |
|
148 | + 'message' => 'test one', |
|
149 | + ], |
|
150 | + [ |
|
151 | + 'id' => rand(101, 200), |
|
152 | + 'message' => 'test two', |
|
153 | + ], |
|
154 | + ]; |
|
155 | + |
|
156 | + array_walk($testData, [$this, 'insertData']); |
|
157 | + |
|
158 | + $repository = new MysqlChangelogRepository(self::$connection); |
|
159 | + $data = $repository->getChanges(1, 3); |
|
160 | + |
|
161 | + $this->assertEmpty($data); |
|
162 | + $this->assertInternalType('array', $data); |
|
163 | + } |
|
164 | + |
|
165 | + protected function tearDown() |
|
166 | + { |
|
167 | + self::$connection->getDefault()->perform("DELETE FROM `jpemeric_stream`.`changelog`"); |
|
168 | + } |
|
169 | + |
|
170 | + public static function tearDownAfterClass() |
|
171 | + { |
|
172 | + self::$connection->getDefault()->disconnect(); |
|
173 | + unlink('jpemeric_stream.db'); |
|
174 | + } |
|
175 | + |
|
176 | + protected function insertData(array $data) |
|
177 | + { |
|
178 | + $defaultData = [ |
|
179 | + 'id' => null, |
|
180 | + 'hash' => '', |
|
181 | + 'message' => null, |
|
182 | + 'message_short' => null, |
|
183 | + 'datetime' => '', |
|
184 | + 'author' => '', |
|
185 | + 'commit_link' => '', |
|
186 | + ]; |
|
187 | + |
|
188 | + $data = array_merge($defaultData, $data); |
|
189 | + |
|
190 | + return self::$connection->getDefault()->perform(" |
|
191 | 191 | INSERT INTO `jpemeric_stream`.`changelog` |
192 | 192 | (id, hash, message, message_short, datetime, author, commit_link) |
193 | 193 | VALUES |
194 | 194 | (:id, :hash, :message, :message_short, :datetime, :author, :commit_link)", |
195 | - $data |
|
196 | - ); |
|
197 | - } |
|
195 | + $data |
|
196 | + ); |
|
197 | + } |
|
198 | 198 | } |