Completed
Pull Request — master (#5)
by Jacob
03:16
created
src/Domain/Stream/Changelog/MysqlChangelogRepository.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -7,37 +7,37 @@
 block discarded – undo
7 7
 class MysqlChangelogRepository implements ChangelogRepositoryInterface
8 8
 {
9 9
 
10
-    /** @var  ConnectionLocator */
11
-    protected $connections;
10
+	/** @var  ConnectionLocator */
11
+	protected $connections;
12 12
 
13
-    /**
14
-     * @param ConnectonLocator $connections
15
-     */
16
-    public function __construct(ConnectionLocator $connections)
17
-    {
18
-        $this->connections = $connections;
19
-    }
13
+	/**
14
+	 * @param ConnectonLocator $connections
15
+	 */
16
+	public function __construct(ConnectionLocator $connections)
17
+	{
18
+		$this->connections = $connections;
19
+	}
20 20
 
21
-    /**
22
-     * @param integer $limit
23
-     * @param integer $offset
24
-     *
25
-     * @return array|false
26
-     */
27
-    public function getChanges($limit = null, $offset = 0)
28
-    {
29
-        $query = "
21
+	/**
22
+	 * @param integer $limit
23
+	 * @param integer $offset
24
+	 *
25
+	 * @return array|false
26
+	 */
27
+	public function getChanges($limit = null, $offset = 0)
28
+	{
29
+		$query = "
30 30
             SELECT `message`, `message_short`, `datetime`, `commit_link`
31 31
             FROM `jpemeric_stream`.`changelog`
32 32
             ORDER BY `datetime` DESC";
33
-        if (!is_null($limit)) {
34
-            $query .= "
33
+		if (!is_null($limit)) {
34
+			$query .= "
35 35
             LIMIT {$offset}, {$limit}";
36
-        }
36
+		}
37 37
 
38
-        return $this
39
-            ->connections
40
-            ->getRead()
41
-            ->fetchAll($query);
42
-    }
38
+		return $this
39
+			->connections
40
+			->getRead()
41
+			->fetchAll($query);
42
+	}
43 43
 }
Please login to merge, or discard this patch.
tests/unit/Domain/Stream/Activity/MysqlActivityRepositoryTest.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
             )"
30 30
         );
31 31
 
32
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
32
+        self::$connection = new ConnectionLocator(function() use ($extendedPdo) {
33 33
             return $extendedPdo;
34 34
         });
35 35
     }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
         $this->assertNotFalse($data);
250 250
         $this->assertInternalType('array', $data);
251 251
 
252
-        $testData = array_filter($testData, function ($row) {
252
+        $testData = array_filter($testData, function($row) {
253 253
             return ($row['type'] == 'type one');
254 254
         });
255 255
         $testData = array_values($testData);
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
         $this->assertInternalType('array', $data);
319 319
         $this->assertCount(2, $data);
320 320
 
321
-        $testData = array_filter($testData, function ($row) {
321
+        $testData = array_filter($testData, function($row) {
322 322
             return ($row['type'] == 'type one');
323 323
         });
324 324
         $testData = array_values($testData);
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
         $repository = new MysqlActivityRepository(self::$connection);
385 385
         $data = $repository->getActivitiesByTypeCount('type one');
386 386
 
387
-        $testData = array_filter($testData, function ($row) {
387
+        $testData = array_filter($testData, function($row) {
388 388
             return ($row['type'] == 'type one');
389 389
         });
390 390
 
Please login to merge, or discard this patch.
Indentation   +426 added lines, -426 removed lines patch added patch discarded remove patch
@@ -9,14 +9,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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 insertData(array $data)
423
-    {
424
-        $defaultData = [
425
-            'id' => null,
426
-            'message' => '',
427
-            'message_long' => '',
428
-            'datetime' => '',
429
-            'metadata' => '',
430
-            'type' => '',
431
-            'type_id' => '',
432
-        ];
433
-
434
-        $data = array_merge($defaultData, $data);
435
-
436
-        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 insertData(array $data)
423
+	{
424
+		$defaultData = [
425
+			'id' => null,
426
+			'message' => '',
427
+			'message_long' => '',
428
+			'datetime' => '',
429
+			'metadata' => '',
430
+			'type' => '',
431
+			'type_id' => '',
432
+		];
433
+
434
+		$data = array_merge($defaultData, $data);
435
+
436
+		return self::$connection->getDefault()->perform("
437 437
             INSERT INTO `jpemeric_stream`.`activity`
438 438
                 (id, message, message_long, datetime, metadata, type, type_id)
439 439
             VALUES
440 440
                 (:id, :message, :message_long, :datetime, :metadata, :type, :type_id)",
441
-            $data
442
-        );
443
-    }
444
-
445
-    protected function tearDown()
446
-    {
447
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_stream`.`activity`");
448
-    }
449
-
450
-    public static function tearDownAfterClass()
451
-    {
452
-        self::$connection->getDefault()->disconnect();
453
-        unlink('jpemeric_stream.db');
454
-    }
441
+			$data
442
+		);
443
+	}
444
+
445
+	protected function tearDown()
446
+	{
447
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_stream`.`activity`");
448
+	}
449
+
450
+	public static function tearDownAfterClass()
451
+	{
452
+		self::$connection->getDefault()->disconnect();
453
+		unlink('jpemeric_stream.db');
454
+	}
455 455
 }
Please login to merge, or discard this patch.
tests/unit/Domain/Stream/Changelog/MysqlChangelogRepositoryTest.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
             )"
30 30
         );
31 31
 
32
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
32
+        self::$connection = new ConnectionLocator(function() use ($extendedPdo) {
33 33
             return $extendedPdo;
34 34
         });
35 35
     }
Please login to merge, or discard this patch.
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -9,14 +9,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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 insertData(array $data)
166
-    {
167
-        $defaultData = [
168
-            'id' => null,
169
-            'hash' => '',
170
-            'message' => null,
171
-            'message_short' => null,
172
-            'datetime' => '',
173
-            'author' => '',
174
-            'commit_link' => '',
175
-        ];
176
-
177
-        $data = array_merge($defaultData, $data);
178
-
179
-        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 insertData(array $data)
166
+	{
167
+		$defaultData = [
168
+			'id' => null,
169
+			'hash' => '',
170
+			'message' => null,
171
+			'message_short' => null,
172
+			'datetime' => '',
173
+			'author' => '',
174
+			'commit_link' => '',
175
+		];
176
+
177
+		$data = array_merge($defaultData, $data);
178
+
179
+		return self::$connection->getDefault()->perform("
180 180
             INSERT INTO `jpemeric_stream`.`changelog`
181 181
                 (id, hash, message, message_short, datetime, author, commit_link)
182 182
             VALUES
183 183
                 (:id, :hash, :message, :message_short, :datetime, :author, :commit_link)",
184
-            $data
185
-        );
186
-    }
187
-
188
-    protected function tearDown()
189
-    {
190
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_stream`.`changelog`");
191
-    }
192
-
193
-    public static function tearDownAfterClass()
194
-    {
195
-        self::$connection->getDefault()->disconnect();
196
-        unlink('jpemeric_stream.db');
197
-    }
184
+			$data
185
+		);
186
+	}
187
+
188
+	protected function tearDown()
189
+	{
190
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_stream`.`changelog`");
191
+	}
192
+
193
+	public static function tearDownAfterClass()
194
+	{
195
+		self::$connection->getDefault()->disconnect();
196
+		unlink('jpemeric_stream.db');
197
+	}
198 198
 }
Please login to merge, or discard this patch.
tests/unit/Domain/Blog/Series/MysqlSeriesRepositoryTest.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
             )"
43 43
         );
44 44
 
45
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
45
+        self::$connection = new ConnectionLocator(function() use ($extendedPdo) {
46 46
             return $extendedPdo;
47 47
         });
48 48
     }
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
         $repository = new MysqlSeriesRepository(self::$connection);
181 181
         $data = $repository->getSeriesForPost(reset($testPostData)['id']);
182 182
 
183
-        usort($testPostData, function ($rowA, $rowB) use ($testSeriesPostData) {
184
-            $seriesA = array_filter($testSeriesPostData, function ($row) use ($rowA) {
183
+        usort($testPostData, function($rowA, $rowB) use ($testSeriesPostData) {
184
+            $seriesA = array_filter($testSeriesPostData, function($row) use ($rowA) {
185 185
                 return ($rowA['id'] == $row['post']);
186 186
             });
187
-            $seriesB = array_filter($testSeriesPostData, function ($row) use ($rowB) {
187
+            $seriesB = array_filter($testSeriesPostData, function($row) use ($rowB) {
188 188
                 return ($rowB['id'] == $row['post']);
189 189
             });
190 190
 
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
         $this->assertNotFalse($data);
309 309
         $this->assertInternalType('array', $data);
310 310
 
311
-        $testPostData = array_filter($testPostData, function ($row) {
311
+        $testPostData = array_filter($testPostData, function($row) {
312 312
             return ($row['display'] == 1);
313 313
         });
314 314
         $testPosts = array_column($testPostData, 'id');
Please login to merge, or discard this patch.
Indentation   +352 added lines, -352 removed lines patch added patch discarded remove patch
@@ -9,14 +9,14 @@  discard block
 block discarded – undo
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,380 +26,380 @@  discard block
 block discarded – undo
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
-        foreach ($testPostData as $testPostDataRow) {
110
-            array_push($testSeriesPostData, [
111
-                'series' => reset($testSeriesData)['id'],
112
-                'post' => $testPostDataRow['id'],
113
-            ]);
114
-        }
115
-
116
-        array_walk($testPostData, [$this, 'insertPostData']);
117
-        array_walk($testSeriesData, [$this, 'insertSeriesData']);
118
-        array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
119
-
120
-        $repository = new MysqlSeriesRepository(self::$connection);
121
-        $data = $repository->getSeriesForPost(reset($testPostData)['id']);
122
-
123
-        $this->assertNotFalse($data);
124
-        $this->assertInternalType('array', $data);
125
-        foreach ($testPostData as $key => $testPostRow) {
126
-            $this->assertInternalType('array', $data[$key]);
127
-            $this->assertArrayHasKey('series_title', $data[$key]);
128
-            $this->assertEquals(reset($testSeriesData)['title'], $data[$key]['series_title']);
129
-            $this->assertArrayHasKey('series_description', $data[$key]);
130
-            $this->assertEquals(reset($testSeriesData)['description'], $data[$key]['series_description']);
131
-            $this->assertArrayHasKey('post', $data[$key]);
132
-            $this->assertEquals($testPostRow['id'], $data[$key]['post']);
133
-            $this->assertArrayHasKey('title', $data[$key]);
134
-            $this->assertEquals($testPostRow['title'], $data[$key]['title']);
135
-            $this->assertArrayHasKey('category', $data[$key]);
136
-            $this->assertEquals($testPostRow['category'], $data[$key]['category']);
137
-            $this->assertArrayHasKey('path', $data[$key]);
138
-            $this->assertEquals($testPostRow['path'], $data[$key]['path']);
139
-        }
140
-    }
141
-
142
-    public function testGetSeriesForPostOrder()
143
-    {
144
-        $testPostData = [
145
-            [
146
-                'id' => rand(1, 100),
147
-                'display' => 1,
148
-            ],
149
-            [
150
-                'id' => rand(101, 200),
151
-                'display' => 1,
152
-            ],
153
-            [
154
-                'id' => rand(201, 300),
155
-                'display' => 1,
156
-            ],
157
-        ];
158
-
159
-        $testSeriesData = [
160
-            [
161
-                'id' => rand(1, 100),
162
-            ],
163
-        ];
164
-
165
-        $order = [1, 2, 3];
166
-        shuffle($order);
167
-        $testSeriesPostData = [];
168
-        foreach ($testPostData as $key => $testPostDataRow) {
169
-            array_push($testSeriesPostData, [
170
-                'series' => reset($testSeriesData)['id'],
171
-                'post' => $testPostDataRow['id'],
172
-                'order' => $order[$key],
173
-            ]);
174
-        }
175
-
176
-        array_walk($testPostData, [$this, 'insertPostData']);
177
-        array_walk($testSeriesData, [$this, 'insertSeriesData']);
178
-        array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
179
-
180
-        $repository = new MysqlSeriesRepository(self::$connection);
181
-        $data = $repository->getSeriesForPost(reset($testPostData)['id']);
182
-
183
-        usort($testPostData, function ($rowA, $rowB) use ($testSeriesPostData) {
184
-            $seriesA = array_filter($testSeriesPostData, function ($row) use ($rowA) {
185
-                return ($rowA['id'] == $row['post']);
186
-            });
187
-            $seriesB = array_filter($testSeriesPostData, function ($row) use ($rowB) {
188
-                return ($rowB['id'] == $row['post']);
189
-            });
190
-
191
-            return (reset($seriesA)['order'] > reset($seriesB)['order']);
192
-        });
193
-
194
-        $this->assertNotFalse($data);
195
-        $this->assertInternalType('array', $data);
196
-        foreach ($testPostData as $key => $testPostRow) {
197
-            $this->assertInternalType('array', $data[$key]);
198
-            $this->assertArrayHasKey('post', $data[$key]);
199
-            $this->assertEquals($testPostRow['id'], $data[$key]['post']);
200
-        }
201
-    }
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
+		foreach ($testPostData as $testPostDataRow) {
110
+			array_push($testSeriesPostData, [
111
+				'series' => reset($testSeriesData)['id'],
112
+				'post' => $testPostDataRow['id'],
113
+			]);
114
+		}
115
+
116
+		array_walk($testPostData, [$this, 'insertPostData']);
117
+		array_walk($testSeriesData, [$this, 'insertSeriesData']);
118
+		array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
119
+
120
+		$repository = new MysqlSeriesRepository(self::$connection);
121
+		$data = $repository->getSeriesForPost(reset($testPostData)['id']);
122
+
123
+		$this->assertNotFalse($data);
124
+		$this->assertInternalType('array', $data);
125
+		foreach ($testPostData as $key => $testPostRow) {
126
+			$this->assertInternalType('array', $data[$key]);
127
+			$this->assertArrayHasKey('series_title', $data[$key]);
128
+			$this->assertEquals(reset($testSeriesData)['title'], $data[$key]['series_title']);
129
+			$this->assertArrayHasKey('series_description', $data[$key]);
130
+			$this->assertEquals(reset($testSeriesData)['description'], $data[$key]['series_description']);
131
+			$this->assertArrayHasKey('post', $data[$key]);
132
+			$this->assertEquals($testPostRow['id'], $data[$key]['post']);
133
+			$this->assertArrayHasKey('title', $data[$key]);
134
+			$this->assertEquals($testPostRow['title'], $data[$key]['title']);
135
+			$this->assertArrayHasKey('category', $data[$key]);
136
+			$this->assertEquals($testPostRow['category'], $data[$key]['category']);
137
+			$this->assertArrayHasKey('path', $data[$key]);
138
+			$this->assertEquals($testPostRow['path'], $data[$key]['path']);
139
+		}
140
+	}
141
+
142
+	public function testGetSeriesForPostOrder()
143
+	{
144
+		$testPostData = [
145
+			[
146
+				'id' => rand(1, 100),
147
+				'display' => 1,
148
+			],
149
+			[
150
+				'id' => rand(101, 200),
151
+				'display' => 1,
152
+			],
153
+			[
154
+				'id' => rand(201, 300),
155
+				'display' => 1,
156
+			],
157
+		];
158
+
159
+		$testSeriesData = [
160
+			[
161
+				'id' => rand(1, 100),
162
+			],
163
+		];
164
+
165
+		$order = [1, 2, 3];
166
+		shuffle($order);
167
+		$testSeriesPostData = [];
168
+		foreach ($testPostData as $key => $testPostDataRow) {
169
+			array_push($testSeriesPostData, [
170
+				'series' => reset($testSeriesData)['id'],
171
+				'post' => $testPostDataRow['id'],
172
+				'order' => $order[$key],
173
+			]);
174
+		}
175
+
176
+		array_walk($testPostData, [$this, 'insertPostData']);
177
+		array_walk($testSeriesData, [$this, 'insertSeriesData']);
178
+		array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
179
+
180
+		$repository = new MysqlSeriesRepository(self::$connection);
181
+		$data = $repository->getSeriesForPost(reset($testPostData)['id']);
182
+
183
+		usort($testPostData, function ($rowA, $rowB) use ($testSeriesPostData) {
184
+			$seriesA = array_filter($testSeriesPostData, function ($row) use ($rowA) {
185
+				return ($rowA['id'] == $row['post']);
186
+			});
187
+			$seriesB = array_filter($testSeriesPostData, function ($row) use ($rowB) {
188
+				return ($rowB['id'] == $row['post']);
189
+			});
190
+
191
+			return (reset($seriesA)['order'] > reset($seriesB)['order']);
192
+		});
193
+
194
+		$this->assertNotFalse($data);
195
+		$this->assertInternalType('array', $data);
196
+		foreach ($testPostData as $key => $testPostRow) {
197
+			$this->assertInternalType('array', $data[$key]);
198
+			$this->assertArrayHasKey('post', $data[$key]);
199
+			$this->assertEquals($testPostRow['id'], $data[$key]['post']);
200
+		}
201
+	}
202 202
  
203
-    public function testGetSeriesForPostSeriesFilter()
204
-    {
205
-        $testPostAData = [
206
-            [
207
-                'id' => rand(1, 100),
208
-                'display' => 1,
209
-            ],
210
-            [
211
-                'id' => rand(101, 200),
212
-                'display' => 1,
213
-            ],
214
-        ];
215
-
216
-        $testPostBData = [
217
-            [
218
-                'id' => rand(501, 600),
219
-                'display' => 1,
220
-            ],
221
-            [
222
-                'id' => rand(601, 700),
223
-                'display' => 1,
224
-            ],
225
-        ];
226
-
227
-        $testSeriesData = [
228
-            [
229
-                'id' => rand(1, 100),
230
-            ],
231
-            [
232
-                'id' => rand(101, 200),
233
-            ],
234
-        ];
235
-
236
-        $testSeriesPostData = [];
237
-        foreach ($testPostAData as $testPostDataRow) {
238
-            array_push($testSeriesPostData, [
239
-                'series' => $testSeriesData[0]['id'],
240
-                'post' => $testPostDataRow['id'],
241
-            ]);
242
-        }
243
-        foreach ($testPostBData as $testPostDataRow) {
244
-            array_push($testSeriesPostData, [
245
-                'series' => $testSeriesData[1]['id'],
246
-                'post' => $testPostDataRow['id'],
247
-            ]);
248
-        }
249
-
250
-        $testPostData = array_merge($testPostAData, $testPostBData);
251
-        array_walk($testPostData, [$this, 'insertPostData']);
252
-        array_walk($testSeriesData, [$this, 'insertSeriesData']);
253
-        array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
254
-
255
-        $repository = new MysqlSeriesRepository(self::$connection);
256
-        $data = $repository->getSeriesForPost(reset($testPostAData)['id']);
257
-
258
-        $this->assertNotFalse($data);
259
-        $this->assertInternalType('array', $data);
260
-
261
-        $testPosts = array_column($testPostAData, 'id');
262
-        $dataPosts = array_column($data, 'post');
263
-
264
-        $this->assertEmpty(array_merge(
265
-            array_diff($testPosts, $dataPosts),
266
-            array_diff($dataPosts, $testPosts)
267
-        ));
268
-    }
203
+	public function testGetSeriesForPostSeriesFilter()
204
+	{
205
+		$testPostAData = [
206
+			[
207
+				'id' => rand(1, 100),
208
+				'display' => 1,
209
+			],
210
+			[
211
+				'id' => rand(101, 200),
212
+				'display' => 1,
213
+			],
214
+		];
215
+
216
+		$testPostBData = [
217
+			[
218
+				'id' => rand(501, 600),
219
+				'display' => 1,
220
+			],
221
+			[
222
+				'id' => rand(601, 700),
223
+				'display' => 1,
224
+			],
225
+		];
226
+
227
+		$testSeriesData = [
228
+			[
229
+				'id' => rand(1, 100),
230
+			],
231
+			[
232
+				'id' => rand(101, 200),
233
+			],
234
+		];
235
+
236
+		$testSeriesPostData = [];
237
+		foreach ($testPostAData as $testPostDataRow) {
238
+			array_push($testSeriesPostData, [
239
+				'series' => $testSeriesData[0]['id'],
240
+				'post' => $testPostDataRow['id'],
241
+			]);
242
+		}
243
+		foreach ($testPostBData as $testPostDataRow) {
244
+			array_push($testSeriesPostData, [
245
+				'series' => $testSeriesData[1]['id'],
246
+				'post' => $testPostDataRow['id'],
247
+			]);
248
+		}
249
+
250
+		$testPostData = array_merge($testPostAData, $testPostBData);
251
+		array_walk($testPostData, [$this, 'insertPostData']);
252
+		array_walk($testSeriesData, [$this, 'insertSeriesData']);
253
+		array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
254
+
255
+		$repository = new MysqlSeriesRepository(self::$connection);
256
+		$data = $repository->getSeriesForPost(reset($testPostAData)['id']);
257
+
258
+		$this->assertNotFalse($data);
259
+		$this->assertInternalType('array', $data);
260
+
261
+		$testPosts = array_column($testPostAData, 'id');
262
+		$dataPosts = array_column($data, 'post');
263
+
264
+		$this->assertEmpty(array_merge(
265
+			array_diff($testPosts, $dataPosts),
266
+			array_diff($dataPosts, $testPosts)
267
+		));
268
+	}
269 269
  
270
-    public function testGetSeriesForPostInactive()
271
-    {
272
-        $testPostData = [
273
-            [
274
-                'id' => rand(1, 100),
275
-                'display' => 1,
276
-            ],
277
-            [
278
-                'id' => rand(101, 200),
279
-                'display' => 0,
280
-            ],
281
-            [
282
-                'id' => rand(201, 300),
283
-                'display' => 0,
284
-            ],
285
-        ];
286
-
287
-        $testSeriesData = [
288
-            [
289
-                'id' => rand(1, 100),
290
-            ],
291
-        ];
292
-
293
-        $testSeriesPostData = [];
294
-        foreach ($testPostData as $testPostDataRow) {
295
-            array_push($testSeriesPostData, [
296
-                'series' => reset($testSeriesData)['id'],
297
-                'post' => $testPostDataRow['id'],
298
-            ]);
299
-        }
300
-
301
-        array_walk($testPostData, [$this, 'insertPostData']);
302
-        array_walk($testSeriesData, [$this, 'insertSeriesData']);
303
-        array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
304
-
305
-        $repository = new MysqlSeriesRepository(self::$connection);
306
-        $data = $repository->getSeriesForPost(reset($testPostData)['id']);
307
-
308
-        $this->assertNotFalse($data);
309
-        $this->assertInternalType('array', $data);
310
-
311
-        $testPostData = array_filter($testPostData, function ($row) {
312
-            return ($row['display'] == 1);
313
-        });
314
-        $testPosts = array_column($testPostData, 'id');
315
-        $dataPosts = array_column($data, 'post');
316
-
317
-        $this->assertEmpty(array_merge(
318
-            array_diff($testPosts, $dataPosts),
319
-            array_diff($dataPosts, $testPosts)
320
-        ));
321
-    }
322
-
323
-    public function testGetSeriesForPostFailure()
324
-    {
325
-        $repository = new MysqlSeriesRepository(self::$connection);
326
-        $data = $repository->getSeriesForPost(rand(1, 100));
327
-
328
-        $this->assertEmpty($data);
329
-        $this->assertInternalType('array', $data);
330
-    }
331
-
332
-    protected function insertPostData(array $data)
333
-    {
334
-        $defaultData = [
335
-            'id' => null,
336
-            'title' => '',
337
-            'path' => '',
338
-            'category' => '',
339
-            'date' => '',
340
-            'body' => '',
341
-            'display' => 0,
342
-        ];
343
-
344
-        $data = array_merge($defaultData, $data);
345
-
346
-        return self::$connection->getDefault()->perform("
270
+	public function testGetSeriesForPostInactive()
271
+	{
272
+		$testPostData = [
273
+			[
274
+				'id' => rand(1, 100),
275
+				'display' => 1,
276
+			],
277
+			[
278
+				'id' => rand(101, 200),
279
+				'display' => 0,
280
+			],
281
+			[
282
+				'id' => rand(201, 300),
283
+				'display' => 0,
284
+			],
285
+		];
286
+
287
+		$testSeriesData = [
288
+			[
289
+				'id' => rand(1, 100),
290
+			],
291
+		];
292
+
293
+		$testSeriesPostData = [];
294
+		foreach ($testPostData as $testPostDataRow) {
295
+			array_push($testSeriesPostData, [
296
+				'series' => reset($testSeriesData)['id'],
297
+				'post' => $testPostDataRow['id'],
298
+			]);
299
+		}
300
+
301
+		array_walk($testPostData, [$this, 'insertPostData']);
302
+		array_walk($testSeriesData, [$this, 'insertSeriesData']);
303
+		array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
304
+
305
+		$repository = new MysqlSeriesRepository(self::$connection);
306
+		$data = $repository->getSeriesForPost(reset($testPostData)['id']);
307
+
308
+		$this->assertNotFalse($data);
309
+		$this->assertInternalType('array', $data);
310
+
311
+		$testPostData = array_filter($testPostData, function ($row) {
312
+			return ($row['display'] == 1);
313
+		});
314
+		$testPosts = array_column($testPostData, 'id');
315
+		$dataPosts = array_column($data, 'post');
316
+
317
+		$this->assertEmpty(array_merge(
318
+			array_diff($testPosts, $dataPosts),
319
+			array_diff($dataPosts, $testPosts)
320
+		));
321
+	}
322
+
323
+	public function testGetSeriesForPostFailure()
324
+	{
325
+		$repository = new MysqlSeriesRepository(self::$connection);
326
+		$data = $repository->getSeriesForPost(rand(1, 100));
327
+
328
+		$this->assertEmpty($data);
329
+		$this->assertInternalType('array', $data);
330
+	}
331
+
332
+	protected function insertPostData(array $data)
333
+	{
334
+		$defaultData = [
335
+			'id' => null,
336
+			'title' => '',
337
+			'path' => '',
338
+			'category' => '',
339
+			'date' => '',
340
+			'body' => '',
341
+			'display' => 0,
342
+		];
343
+
344
+		$data = array_merge($defaultData, $data);
345
+
346
+		return self::$connection->getDefault()->perform("
347 347
             INSERT INTO `jpemeric_blog`.`post`
348 348
                 (id, title, path, category, date, body, display)
349 349
             VALUES
350 350
                 (:id, :title, :path, :category, :date, :body, :display)",
351
-            $data
352
-        );
353
-    }
351
+			$data
352
+		);
353
+	}
354 354
 
355
-    protected function insertSeriesData(array $data)
356
-    {
357
-        $defaultData = [
358
-            'id' => null,
359
-            'title' => '',
360
-            'description' => '',
361
-        ];
355
+	protected function insertSeriesData(array $data)
356
+	{
357
+		$defaultData = [
358
+			'id' => null,
359
+			'title' => '',
360
+			'description' => '',
361
+		];
362 362
 
363
-        $data = array_merge($defaultData, $data);
363
+		$data = array_merge($defaultData, $data);
364 364
 
365
-        return self::$connection->getDefault()->perform("
365
+		return self::$connection->getDefault()->perform("
366 366
             INSERT INTO `jpemeric_blog`.`series`
367 367
                 (id, title, description)
368 368
             VALUES
369 369
                 (:id, :title, :description)",
370
-            $data
371
-        );
372
-    }
370
+			$data
371
+		);
372
+	}
373 373
 
374
-    protected function insertSeriesPostData(array $data)
375
-    {
376
-        $defaultData = [
377
-            'series' => '',
378
-            'post' => '',
379
-            'order' => 0,
380
-        ];
374
+	protected function insertSeriesPostData(array $data)
375
+	{
376
+		$defaultData = [
377
+			'series' => '',
378
+			'post' => '',
379
+			'order' => 0,
380
+		];
381 381
 
382
-        $data = array_merge($defaultData, $data);
382
+		$data = array_merge($defaultData, $data);
383 383
 
384
-        return self::$connection->getDefault()->perform("
384
+		return self::$connection->getDefault()->perform("
385 385
             INSERT INTO `jpemeric_blog`.`series_post`
386 386
                 (series, post, `order`)
387 387
             VALUES
388 388
                 (:series, :post, :order)",
389
-            $data
390
-        );
391
-    }
392
-
393
-    protected function tearDown()
394
-    {
395
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`post`");
396
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series`");
397
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series_post`");
398
-    }
399
-
400
-    public static function tearDownAfterClass()
401
-    {
402
-        self::$connection->getDefault()->disconnect();
403
-        unlink('jpemeric_blog.db');
404
-    }
389
+			$data
390
+		);
391
+	}
392
+
393
+	protected function tearDown()
394
+	{
395
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`post`");
396
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series`");
397
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series_post`");
398
+	}
399
+
400
+	public static function tearDownAfterClass()
401
+	{
402
+		self::$connection->getDefault()->disconnect();
403
+		unlink('jpemeric_blog.db');
404
+	}
405 405
 }
Please login to merge, or discard this patch.
tests/unit/Domain/Blog/Introduction/MysqlIntroductionRepositoryTest.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
             )"
30 30
         );
31 31
 
32
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
32
+        self::$connection = new ConnectionLocator(function() use ($extendedPdo) {
33 33
             return $extendedPdo;
34 34
         });
35 35
     }
Please login to merge, or discard this patch.
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -9,14 +9,14 @@  discard block
 block discarded – undo
9 9
 class MysqlIntroductionRepositoryTest 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`.`introduction` (
21 21
                 `id` integer PRIMARY KEY AUTOINCREMENT,
22 22
                 `type` varchar(10) NOT NULL,
@@ -25,134 +25,134 @@  discard block
 block discarded – undo
25 25
                 `content` text NOT NULL,
26 26
                 `image` image
27 27
             )"
28
-        );
29
-
30
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
31
-            return $extendedPdo;
32
-        });
33
-    }
34
-
35
-    public function testIsInstanceOfIntroductionRepository()
36
-    {
37
-        $repository = new MysqlIntroductionRepository(self::$connection);
38
-
39
-        $this->assertInstanceOf(
40
-            'Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository',
41
-            $repository
42
-        );
43
-    }
44
-
45
-    public function testImplementsIntroductionInterface()
46
-    {
47
-        $repository = new MysqlIntroductionRepository(self::$connection);
48
-
49
-        $this->assertInstanceOf(
50
-            'Jacobemerick\Web\Domain\Blog\Introduction\IntroductionRepositoryInterface',
51
-            $repository
52
-        );
53
-    }
54
-
55
-    public function testConstructSetsConnections()
56
-    {
57
-        $respository = new MysqlIntroductionRepository(self::$connection);
58
-
59
-        $this->assertAttributeSame(
60
-            self::$connection,
61
-            'connections',
62
-            $respository
63
-        );
64
-    }
65
-
66
-    public function testFindByType()
67
-    {
68
-        $testData = [
69
-            'id' => rand(1, 100),
70
-            'type' => 'test',
71
-            'title' => 'test title',
72
-            'content' => 'test content',
73
-            'image' => rand(1, 100),
74
-        ];
75
-
76
-        $this->insertData($testData);
77
-
78
-        $repository = new MysqlIntroductionRepository(self::$connection);
79
-        $data = $repository->findByType('test');
80
-
81
-        $this->assertNotFalse($data);
82
-        $this->assertInternalType('array', $data);
83
-        $this->assertArrayHasKey('title', $data);
84
-        $this->assertEquals($testData['title'], $data['title']);
85
-        $this->assertArrayHasKey('content', $data);
86
-        $this->assertEquals($testData['content'], $data['content']);
87
-        $this->assertArrayHasKey('image', $data);
88
-        $this->assertEquals($testData['image'], $data['image']);
89
-    }
90
-
91
-    public function testFindByTypeFilterValue()
92
-    {
93
-        $testData = [
94
-            [
95
-                'id' => rand(1, 100),
96
-                'type' => 'test',
97
-                'title' => 'title a',
98
-                'value' => 'value a',
99
-            ],
100
-            [
101
-                'id' => rand(101, 200),
102
-                'type' => 'test',
103
-                'title' => 'title b',
104
-                'value' => 'value b',
105
-            ],
106
-        ];
107
-
108
-        array_walk($testData, [$this, 'insertData']);
109
-
110
-        $repository = new MysqlIntroductionRepository(self::$connection);
111
-        $data = $repository->findByType('test', reset($testData)['value']);
112
-
113
-        $this->assertNotFalse($data);
114
-        $this->assertInternalType('array', $data);
115
-        $this->assertEquals(reset($testData)['title'], $data['title']);
116
-    }
28
+		);
29
+
30
+		self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
31
+			return $extendedPdo;
32
+		});
33
+	}
34
+
35
+	public function testIsInstanceOfIntroductionRepository()
36
+	{
37
+		$repository = new MysqlIntroductionRepository(self::$connection);
38
+
39
+		$this->assertInstanceOf(
40
+			'Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository',
41
+			$repository
42
+		);
43
+	}
44
+
45
+	public function testImplementsIntroductionInterface()
46
+	{
47
+		$repository = new MysqlIntroductionRepository(self::$connection);
48
+
49
+		$this->assertInstanceOf(
50
+			'Jacobemerick\Web\Domain\Blog\Introduction\IntroductionRepositoryInterface',
51
+			$repository
52
+		);
53
+	}
54
+
55
+	public function testConstructSetsConnections()
56
+	{
57
+		$respository = new MysqlIntroductionRepository(self::$connection);
58
+
59
+		$this->assertAttributeSame(
60
+			self::$connection,
61
+			'connections',
62
+			$respository
63
+		);
64
+	}
65
+
66
+	public function testFindByType()
67
+	{
68
+		$testData = [
69
+			'id' => rand(1, 100),
70
+			'type' => 'test',
71
+			'title' => 'test title',
72
+			'content' => 'test content',
73
+			'image' => rand(1, 100),
74
+		];
75
+
76
+		$this->insertData($testData);
77
+
78
+		$repository = new MysqlIntroductionRepository(self::$connection);
79
+		$data = $repository->findByType('test');
80
+
81
+		$this->assertNotFalse($data);
82
+		$this->assertInternalType('array', $data);
83
+		$this->assertArrayHasKey('title', $data);
84
+		$this->assertEquals($testData['title'], $data['title']);
85
+		$this->assertArrayHasKey('content', $data);
86
+		$this->assertEquals($testData['content'], $data['content']);
87
+		$this->assertArrayHasKey('image', $data);
88
+		$this->assertEquals($testData['image'], $data['image']);
89
+	}
90
+
91
+	public function testFindByTypeFilterValue()
92
+	{
93
+		$testData = [
94
+			[
95
+				'id' => rand(1, 100),
96
+				'type' => 'test',
97
+				'title' => 'title a',
98
+				'value' => 'value a',
99
+			],
100
+			[
101
+				'id' => rand(101, 200),
102
+				'type' => 'test',
103
+				'title' => 'title b',
104
+				'value' => 'value b',
105
+			],
106
+		];
107
+
108
+		array_walk($testData, [$this, 'insertData']);
109
+
110
+		$repository = new MysqlIntroductionRepository(self::$connection);
111
+		$data = $repository->findByType('test', reset($testData)['value']);
112
+
113
+		$this->assertNotFalse($data);
114
+		$this->assertInternalType('array', $data);
115
+		$this->assertEquals(reset($testData)['title'], $data['title']);
116
+	}
117 117
  
118
-    public function testFindByTypeFailure()
119
-    {
120
-        $repository = new MysqlIntroductionRepository(self::$connection);
121
-        $data = $repository->findByType('empty type');
122
-
123
-        $this->assertFalse($data);
124
-    }
125
-
126
-    protected function insertData(array $data)
127
-    {
128
-        $defaultData = [
129
-            'id' => null,
130
-            'type' => '',
131
-            'value' => '',
132
-            'title' => '',
133
-            'content' => '',
134
-            'image' => null,
135
-        ];
136
-
137
-        $data = array_merge($defaultData, $data);
138
-
139
-        return self::$connection->getDefault()->perform("
118
+	public function testFindByTypeFailure()
119
+	{
120
+		$repository = new MysqlIntroductionRepository(self::$connection);
121
+		$data = $repository->findByType('empty type');
122
+
123
+		$this->assertFalse($data);
124
+	}
125
+
126
+	protected function insertData(array $data)
127
+	{
128
+		$defaultData = [
129
+			'id' => null,
130
+			'type' => '',
131
+			'value' => '',
132
+			'title' => '',
133
+			'content' => '',
134
+			'image' => null,
135
+		];
136
+
137
+		$data = array_merge($defaultData, $data);
138
+
139
+		return self::$connection->getDefault()->perform("
140 140
             INSERT INTO `jpemeric_blog`.`introduction`
141 141
                 (id, type, value, title, content, image)
142 142
             VALUES
143 143
                 (:id, :type, :value, :title, :content, :image)",
144
-            $data
145
-        );
146
-    }
147
-
148
-    protected function tearDown()
149
-    {
150
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`introduction`");
151
-    }
152
-
153
-    public static function tearDownAfterClass()
154
-    {
155
-        self::$connection->getDefault()->disconnect();
156
-        unlink('jpemeric_blog.db');
157
-    }
144
+			$data
145
+		);
146
+	}
147
+
148
+	protected function tearDown()
149
+	{
150
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`introduction`");
151
+	}
152
+
153
+	public static function tearDownAfterClass()
154
+	{
155
+		self::$connection->getDefault()->disconnect();
156
+		unlink('jpemeric_blog.db');
157
+	}
158 158
 }
Please login to merge, or discard this patch.
tests/unit/Domain/Blog/Tag/MysqlTagRepositoryTest.php 2 patches
Indentation   +470 added lines, -470 removed lines patch added patch discarded remove patch
@@ -9,14 +9,14 @@  discard block
 block discarded – undo
9 9
 class MysqlTagRepositoryTest 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,497 +26,497 @@  discard block
 block discarded – undo
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`.`ptlink` (
32 32
                 `post_id` integer NOT NULL,
33 33
                 `tag_id` integer NOT NULL
34 34
             )"
35
-        );
36
-        $extendedPdo->exec("
35
+		);
36
+		$extendedPdo->exec("
37 37
             CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`tag` (
38 38
                 `id` integer PRIMARY KEY AUTOINCREMENT,
39 39
                 `tag` varchar(25) NOT NULL
40 40
             )"
41
-        );
42
-
43
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
44
-            return $extendedPdo;
45
-        });
46
-    }
47
-
48
-    public function testIsInstanceOfTagRepository()
49
-    {
50
-        $repository = new MysqlTagRepository(self::$connection);
51
-
52
-        $this->assertInstanceOf(
53
-            'Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository',
54
-            $repository
55
-        );
56
-    }
57
-
58
-    public function testImplementsTagInterface()
59
-    {
60
-        $repository = new MysqlTagRepository(self::$connection);
61
-
62
-        $this->assertInstanceOf(
63
-            'Jacobemerick\Web\Domain\Blog\Tag\TagRepositoryInterface',
64
-            $repository
65
-        );
66
-    }
67
-
68
-    public function testConstructSetsConnections()
69
-    {
70
-        $respository = new MysqlTagRepository(self::$connection);
71
-
72
-        $this->assertAttributeSame(
73
-            self::$connection,
74
-            'connections',
75
-            $respository
76
-        );
77
-    }
78
-
79
-    public function testFindTagByTitle()
80
-    {
81
-        $testData = [
82
-            [
83
-                'id' => rand(1, 100),
84
-                'tag' => 'test one',
85
-            ],
86
-            [
87
-                'id' => rand(101, 200),
88
-                'tag' => 'test two',
89
-            ],
90
-        ];
91
-
92
-        array_walk($testData, [$this, 'insertTagData']);
93
-
94
-        shuffle($testData);
95
-
96
-        $repository = new MysqlTagRepository(self::$connection);
97
-        $data = $repository->findTagByTitle(reset($testData)['tag']);
98
-
99
-        $this->assertNotFalse($data);
100
-        $this->assertInternalType('array', $data);
101
-        $this->assertArrayHasKey('id', $data);
102
-        $this->assertEquals(reset($testData)['id'], $data['id']);
103
-        $this->assertArrayHasKey('tag', $data);
104
-        $this->assertEquals(reset($testData)['tag'], $data['tag']);
105
-    }
106
-
107
-    public function testFindTagByTitleFailure()
108
-    {
109
-        $repository = new MysqlTagRepository(self::$connection);
110
-        $data = $repository->findTagByTitle('empty tag');
111
-
112
-        $this->assertFalse($data);
113
-    }
114
-
115
-    public function testGetAllTags()
116
-    {
117
-        $testData = [
118
-            [
119
-                'id' => rand(1, 100),
120
-                'tag' => 'test one',
121
-            ],
122
-            [
123
-                'id' => rand(101, 200),
124
-                'tag' => 'test two',
125
-            ],
126
-        ];
127
-
128
-        array_walk($testData, [$this, 'insertTagData']);
129
-
130
-        $repository = new MysqlTagRepository(self::$connection);
131
-        $data = $repository->getAllTags();
132
-
133
-        $this->assertNotFalse($data);
134
-        $this->assertInternalType('array', $data);
135
-        $this->assertCount(count($testData), $data);
136
-        foreach ($testData as $key => $testDataRow) {
137
-            $this->assertArrayHasKey('id', $data[$key]);
138
-            $this->assertEquals($testDataRow['id'], $data[$key]['id']);
139
-            $this->assertArrayHasKey('tag', $data[$key]);
140
-            $this->assertEquals($testDataRow['tag'], $data[$key]['tag']);
141
-        }
142
-    }
41
+		);
42
+
43
+		self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
44
+			return $extendedPdo;
45
+		});
46
+	}
47
+
48
+	public function testIsInstanceOfTagRepository()
49
+	{
50
+		$repository = new MysqlTagRepository(self::$connection);
51
+
52
+		$this->assertInstanceOf(
53
+			'Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository',
54
+			$repository
55
+		);
56
+	}
57
+
58
+	public function testImplementsTagInterface()
59
+	{
60
+		$repository = new MysqlTagRepository(self::$connection);
61
+
62
+		$this->assertInstanceOf(
63
+			'Jacobemerick\Web\Domain\Blog\Tag\TagRepositoryInterface',
64
+			$repository
65
+		);
66
+	}
67
+
68
+	public function testConstructSetsConnections()
69
+	{
70
+		$respository = new MysqlTagRepository(self::$connection);
71
+
72
+		$this->assertAttributeSame(
73
+			self::$connection,
74
+			'connections',
75
+			$respository
76
+		);
77
+	}
78
+
79
+	public function testFindTagByTitle()
80
+	{
81
+		$testData = [
82
+			[
83
+				'id' => rand(1, 100),
84
+				'tag' => 'test one',
85
+			],
86
+			[
87
+				'id' => rand(101, 200),
88
+				'tag' => 'test two',
89
+			],
90
+		];
91
+
92
+		array_walk($testData, [$this, 'insertTagData']);
93
+
94
+		shuffle($testData);
95
+
96
+		$repository = new MysqlTagRepository(self::$connection);
97
+		$data = $repository->findTagByTitle(reset($testData)['tag']);
98
+
99
+		$this->assertNotFalse($data);
100
+		$this->assertInternalType('array', $data);
101
+		$this->assertArrayHasKey('id', $data);
102
+		$this->assertEquals(reset($testData)['id'], $data['id']);
103
+		$this->assertArrayHasKey('tag', $data);
104
+		$this->assertEquals(reset($testData)['tag'], $data['tag']);
105
+	}
106
+
107
+	public function testFindTagByTitleFailure()
108
+	{
109
+		$repository = new MysqlTagRepository(self::$connection);
110
+		$data = $repository->findTagByTitle('empty tag');
111
+
112
+		$this->assertFalse($data);
113
+	}
114
+
115
+	public function testGetAllTags()
116
+	{
117
+		$testData = [
118
+			[
119
+				'id' => rand(1, 100),
120
+				'tag' => 'test one',
121
+			],
122
+			[
123
+				'id' => rand(101, 200),
124
+				'tag' => 'test two',
125
+			],
126
+		];
127
+
128
+		array_walk($testData, [$this, 'insertTagData']);
129
+
130
+		$repository = new MysqlTagRepository(self::$connection);
131
+		$data = $repository->getAllTags();
132
+
133
+		$this->assertNotFalse($data);
134
+		$this->assertInternalType('array', $data);
135
+		$this->assertCount(count($testData), $data);
136
+		foreach ($testData as $key => $testDataRow) {
137
+			$this->assertArrayHasKey('id', $data[$key]);
138
+			$this->assertEquals($testDataRow['id'], $data[$key]['id']);
139
+			$this->assertArrayHasKey('tag', $data[$key]);
140
+			$this->assertEquals($testDataRow['tag'], $data[$key]['tag']);
141
+		}
142
+	}
143 143
  
144
-    public function testGetAllTagsFailure()
145
-    {
146
-        $repository = new MysqlTagRepository(self::$connection);
147
-        $data = $repository->getAllTags();
148
-
149
-        $this->assertEmpty($data);
150
-        $this->assertInternalType('array', $data);
151
-    }
152
-
153
-    public function testGetTagCloud()
154
-    {
155
-        $testPostData = [
156
-            [
157
-                'id' => rand(1, 100),
158
-                'display' => 1,
159
-            ],
160
-            [
161
-                'id' => rand(101, 200),
162
-                'display' => 1,
163
-            ],
164
-        ];
165
-
166
-        $testTagData = [
167
-            [
168
-                'id' => rand(1, 100),
169
-                'tag' => 'test one',
170
-            ],
171
-            [
172
-                'id' => rand(101, 200),
173
-                'tag' => 'test two',
174
-            ],
175
-            [
176
-                'id' => rand(201, 300),
177
-                'tag' => 'test three',
178
-            ],
179
-        ];
180
-
181
-        $testPTLinkData = [];
182
-        foreach ($testPostData as $testPostRow) {
183
-            $tempTagData = $testTagData;
184
-            shuffle($tempTagData);
185
-            for ($i = 0; $i < 2; $i++) {
186
-                array_push($testPTLinkData, [
187
-                    'post_id' => $testPostRow['id'],
188
-                    'tag_id' => $tempTagData[$i]['id'],
189
-                ]);
190
-            }
191
-        }
192
-
193
-        array_walk($testPostData, [$this, 'insertPostData']);
194
-        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
195
-        array_walk($testTagData, [$this, 'insertTagData']);
196
-
197
-        $repository = new MysqlTagRepository(self::$connection);
198
-        $data = $repository->getTagCloud();
199
-
200
-        $this->assertNotFalse($data);
201
-        $this->assertInternalType('array', $data);
202
-
203
-        $tagCountData = array_map(function ($row) use ($testTagData) {
204
-            $tag = $row['tag_id'];
205
-            $tag = array_filter($testTagData, function ($row) use ($tag) {
206
-                return ($tag == $row['id']);
207
-            });
208
-            $tag = current($tag)['tag'];
209
-            return $tag;
210
-        }, $testPTLinkData);
211
-
212
-        $testCountData = [];
213
-        foreach ($tagCountData as $tagCountRow) {
214
-            $incremented = false;
215
-            foreach ($testCountData as $key => $testCountRow) {
216
-                if ($tagCountRow == $testCountRow['tag']) {
217
-                    $testCountData[$key]['count']++;
218
-                    $incremented = true;
219
-                    break;
220
-                }
221
-            }
222
-            if (!$incremented) {
223
-                array_push($testCountData, [
224
-                    'count' => 1,
225
-                    'tag' => $tagCountRow,
226
-                ]);
227
-            }
228
-        }
229
-
230
-        $this->assertCount(count($testCountData), $data);
231
-
232
-        usort($testCountData, function ($rowA, $rowB) {
233
-            return ($rowA['tag'] > $rowB['tag']);
234
-        });
235
-        usort($data, function ($rowA, $rowB) {
236
-            return ($rowA['tag'] > $rowB['tag']);
237
-        });
238
-
239
-        foreach ($testCountData as $key => $testCountRow) {
240
-            $this->assertArrayHasKey('count', $data[$key]);
241
-            $this->assertEquals($testCountRow['count'], $data[$key]['count']);
242
-            $this->assertArrayHasKey('tag', $data[$key]);
243
-            $this->assertEquals($testCountRow['tag'], $data[$key]['tag']);
244
-        }
245
-    }
246
-
247
-    public function testGetTagCloudInactive()
248
-    {
249
-        $testPostData = [
250
-            [
251
-                'id' => rand(1, 100),
252
-                'display' => 1,
253
-            ],
254
-            [
255
-                'id' => rand(101, 200),
256
-                'display' => 1,
257
-            ],
258
-            [
259
-                'id' => rand(201, 300),
260
-                'display' => 0,
261
-            ],
262
-        ];
263
-
264
-        $testTagData = [
265
-            [
266
-                'id' => rand(1, 100),
267
-                'tag' => 'test one',
268
-            ],
269
-            [
270
-                'id' => rand(101, 200),
271
-                'tag' => 'test two',
272
-            ],
273
-            [
274
-                'id' => rand(201, 300),
275
-                'tag' => 'test three',
276
-            ],
277
-        ];
278
-
279
-        $testPTLinkData = [];
280
-        foreach ($testPostData as $testPostRow) {
281
-            $tempTagData = $testTagData;
282
-            shuffle($tempTagData);
283
-            for ($i = 0; $i < 2; $i++) {
284
-                array_push($testPTLinkData, [
285
-                    'post_id' => $testPostRow['id'],
286
-                    'tag_id' => $tempTagData[$i]['id'],
287
-                ]);
288
-            }
289
-        }
290
-
291
-        array_walk($testPostData, [$this, 'insertPostData']);
292
-        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
293
-        array_walk($testTagData, [$this, 'insertTagData']);
294
-
295
-        $repository = new MysqlTagRepository(self::$connection);
296
-        $data = $repository->getTagCloud();
297
-
298
-        $this->assertNotFalse($data);
299
-        $this->assertInternalType('array', $data);
300
-
301
-        $testPTLinkData = array_filter($testPTLinkData, function ($row) use ($testPostData) {
302
-            $post = $row['post_id'];
303
-            $post = array_filter($testPostData, function ($row) use ($post) {
304
-                return ($post == $row['id']);
305
-            });
306
-            $post = current($post);
307
-            return ($post['display'] == 1);
308
-        });
309
-
310
-        $tagCountData = array_map(function ($row) use ($testTagData) {
311
-            $tag = $row['tag_id'];
312
-            $tag = array_filter($testTagData, function ($row) use ($tag) {
313
-                return ($tag == $row['id']);
314
-            });
315
-            $tag = current($tag)['tag'];
316
-            return $tag;
317
-        }, $testPTLinkData);
318
-
319
-        $testCountData = [];
320
-        foreach ($tagCountData as $tagCountRow) {
321
-            $incremented = false;
322
-            foreach ($testCountData as $key => $testCountRow) {
323
-                if ($tagCountRow == $testCountRow['tag']) {
324
-                    $testCountData[$key]['count']++;
325
-                    $incremented = true;
326
-                    break;
327
-                }
328
-            }
329
-            if (!$incremented) {
330
-                array_push($testCountData, [
331
-                    'count' => 1,
332
-                    'tag' => $tagCountRow,
333
-                ]);
334
-            }
335
-        }
336
-
337
-        $this->assertCount(count($testCountData), $data);
338
-
339
-        usort($testCountData, function ($rowA, $rowB) {
340
-            return ($rowA['tag'] > $rowB['tag']);
341
-        });
342
-        usort($data, function ($rowA, $rowB) {
343
-            return ($rowA['tag'] > $rowB['tag']);
344
-        });
345
-
346
-        foreach ($testCountData as $key => $testCountRow) {
347
-            $this->assertArrayHasKey('count', $data[$key]);
348
-            $this->assertEquals($testCountRow['count'], $data[$key]['count']);
349
-            $this->assertArrayHasKey('tag', $data[$key]);
350
-            $this->assertEquals($testCountRow['tag'], $data[$key]['tag']);
351
-        }
352
-    }
353
-
354
-    public function testGetTagCloudFailure()
355
-    {
356
-        $testData = [
357
-            [
358
-                'id' => rand(1, 100),
359
-                'tag' => 'test one',
360
-            ],
361
-            [
362
-                'id' => rand(101, 200),
363
-                'tag' => 'test two',
364
-            ],
365
-        ];
366
-
367
-        array_walk($testData, [$this, 'insertTagData']);
368
-
369
-        $repository = new MysqlTagRepository(self::$connection);
370
-        $data = $repository->getTagCloud();
371
-
372
-        $this->assertEmpty($data);
373
-        $this->assertInternalType('array', $data);
374
-    }
144
+	public function testGetAllTagsFailure()
145
+	{
146
+		$repository = new MysqlTagRepository(self::$connection);
147
+		$data = $repository->getAllTags();
148
+
149
+		$this->assertEmpty($data);
150
+		$this->assertInternalType('array', $data);
151
+	}
152
+
153
+	public function testGetTagCloud()
154
+	{
155
+		$testPostData = [
156
+			[
157
+				'id' => rand(1, 100),
158
+				'display' => 1,
159
+			],
160
+			[
161
+				'id' => rand(101, 200),
162
+				'display' => 1,
163
+			],
164
+		];
165
+
166
+		$testTagData = [
167
+			[
168
+				'id' => rand(1, 100),
169
+				'tag' => 'test one',
170
+			],
171
+			[
172
+				'id' => rand(101, 200),
173
+				'tag' => 'test two',
174
+			],
175
+			[
176
+				'id' => rand(201, 300),
177
+				'tag' => 'test three',
178
+			],
179
+		];
180
+
181
+		$testPTLinkData = [];
182
+		foreach ($testPostData as $testPostRow) {
183
+			$tempTagData = $testTagData;
184
+			shuffle($tempTagData);
185
+			for ($i = 0; $i < 2; $i++) {
186
+				array_push($testPTLinkData, [
187
+					'post_id' => $testPostRow['id'],
188
+					'tag_id' => $tempTagData[$i]['id'],
189
+				]);
190
+			}
191
+		}
192
+
193
+		array_walk($testPostData, [$this, 'insertPostData']);
194
+		array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
195
+		array_walk($testTagData, [$this, 'insertTagData']);
196
+
197
+		$repository = new MysqlTagRepository(self::$connection);
198
+		$data = $repository->getTagCloud();
199
+
200
+		$this->assertNotFalse($data);
201
+		$this->assertInternalType('array', $data);
202
+
203
+		$tagCountData = array_map(function ($row) use ($testTagData) {
204
+			$tag = $row['tag_id'];
205
+			$tag = array_filter($testTagData, function ($row) use ($tag) {
206
+				return ($tag == $row['id']);
207
+			});
208
+			$tag = current($tag)['tag'];
209
+			return $tag;
210
+		}, $testPTLinkData);
211
+
212
+		$testCountData = [];
213
+		foreach ($tagCountData as $tagCountRow) {
214
+			$incremented = false;
215
+			foreach ($testCountData as $key => $testCountRow) {
216
+				if ($tagCountRow == $testCountRow['tag']) {
217
+					$testCountData[$key]['count']++;
218
+					$incremented = true;
219
+					break;
220
+				}
221
+			}
222
+			if (!$incremented) {
223
+				array_push($testCountData, [
224
+					'count' => 1,
225
+					'tag' => $tagCountRow,
226
+				]);
227
+			}
228
+		}
229
+
230
+		$this->assertCount(count($testCountData), $data);
231
+
232
+		usort($testCountData, function ($rowA, $rowB) {
233
+			return ($rowA['tag'] > $rowB['tag']);
234
+		});
235
+		usort($data, function ($rowA, $rowB) {
236
+			return ($rowA['tag'] > $rowB['tag']);
237
+		});
238
+
239
+		foreach ($testCountData as $key => $testCountRow) {
240
+			$this->assertArrayHasKey('count', $data[$key]);
241
+			$this->assertEquals($testCountRow['count'], $data[$key]['count']);
242
+			$this->assertArrayHasKey('tag', $data[$key]);
243
+			$this->assertEquals($testCountRow['tag'], $data[$key]['tag']);
244
+		}
245
+	}
246
+
247
+	public function testGetTagCloudInactive()
248
+	{
249
+		$testPostData = [
250
+			[
251
+				'id' => rand(1, 100),
252
+				'display' => 1,
253
+			],
254
+			[
255
+				'id' => rand(101, 200),
256
+				'display' => 1,
257
+			],
258
+			[
259
+				'id' => rand(201, 300),
260
+				'display' => 0,
261
+			],
262
+		];
263
+
264
+		$testTagData = [
265
+			[
266
+				'id' => rand(1, 100),
267
+				'tag' => 'test one',
268
+			],
269
+			[
270
+				'id' => rand(101, 200),
271
+				'tag' => 'test two',
272
+			],
273
+			[
274
+				'id' => rand(201, 300),
275
+				'tag' => 'test three',
276
+			],
277
+		];
278
+
279
+		$testPTLinkData = [];
280
+		foreach ($testPostData as $testPostRow) {
281
+			$tempTagData = $testTagData;
282
+			shuffle($tempTagData);
283
+			for ($i = 0; $i < 2; $i++) {
284
+				array_push($testPTLinkData, [
285
+					'post_id' => $testPostRow['id'],
286
+					'tag_id' => $tempTagData[$i]['id'],
287
+				]);
288
+			}
289
+		}
290
+
291
+		array_walk($testPostData, [$this, 'insertPostData']);
292
+		array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
293
+		array_walk($testTagData, [$this, 'insertTagData']);
294
+
295
+		$repository = new MysqlTagRepository(self::$connection);
296
+		$data = $repository->getTagCloud();
297
+
298
+		$this->assertNotFalse($data);
299
+		$this->assertInternalType('array', $data);
300
+
301
+		$testPTLinkData = array_filter($testPTLinkData, function ($row) use ($testPostData) {
302
+			$post = $row['post_id'];
303
+			$post = array_filter($testPostData, function ($row) use ($post) {
304
+				return ($post == $row['id']);
305
+			});
306
+			$post = current($post);
307
+			return ($post['display'] == 1);
308
+		});
309
+
310
+		$tagCountData = array_map(function ($row) use ($testTagData) {
311
+			$tag = $row['tag_id'];
312
+			$tag = array_filter($testTagData, function ($row) use ($tag) {
313
+				return ($tag == $row['id']);
314
+			});
315
+			$tag = current($tag)['tag'];
316
+			return $tag;
317
+		}, $testPTLinkData);
318
+
319
+		$testCountData = [];
320
+		foreach ($tagCountData as $tagCountRow) {
321
+			$incremented = false;
322
+			foreach ($testCountData as $key => $testCountRow) {
323
+				if ($tagCountRow == $testCountRow['tag']) {
324
+					$testCountData[$key]['count']++;
325
+					$incremented = true;
326
+					break;
327
+				}
328
+			}
329
+			if (!$incremented) {
330
+				array_push($testCountData, [
331
+					'count' => 1,
332
+					'tag' => $tagCountRow,
333
+				]);
334
+			}
335
+		}
336
+
337
+		$this->assertCount(count($testCountData), $data);
338
+
339
+		usort($testCountData, function ($rowA, $rowB) {
340
+			return ($rowA['tag'] > $rowB['tag']);
341
+		});
342
+		usort($data, function ($rowA, $rowB) {
343
+			return ($rowA['tag'] > $rowB['tag']);
344
+		});
345
+
346
+		foreach ($testCountData as $key => $testCountRow) {
347
+			$this->assertArrayHasKey('count', $data[$key]);
348
+			$this->assertEquals($testCountRow['count'], $data[$key]['count']);
349
+			$this->assertArrayHasKey('tag', $data[$key]);
350
+			$this->assertEquals($testCountRow['tag'], $data[$key]['tag']);
351
+		}
352
+	}
353
+
354
+	public function testGetTagCloudFailure()
355
+	{
356
+		$testData = [
357
+			[
358
+				'id' => rand(1, 100),
359
+				'tag' => 'test one',
360
+			],
361
+			[
362
+				'id' => rand(101, 200),
363
+				'tag' => 'test two',
364
+			],
365
+		];
366
+
367
+		array_walk($testData, [$this, 'insertTagData']);
368
+
369
+		$repository = new MysqlTagRepository(self::$connection);
370
+		$data = $repository->getTagCloud();
371
+
372
+		$this->assertEmpty($data);
373
+		$this->assertInternalType('array', $data);
374
+	}
375 375
  
376
-    public function testGetTagsForPost()
377
-    {
378
-        $testPostData = [
379
-            'id' => rand(1, 100),
380
-            'display' => 1,
381
-        ];
382
-
383
-        $testTagData = [
384
-            [
385
-                'id' => rand(1, 100),
386
-                'tag' => 'test one',
387
-            ],
388
-            [
389
-                'id' => rand(101, 200),
390
-                'tag' => 'test two',
391
-            ],
392
-            [
393
-                'id' => rand(201, 300),
394
-                'tag' => 'test three',
395
-            ],
396
-        ];
397
-
398
-        $testPTLinkData = [];
399
-        foreach ($testTagData as $testTagRow) {
400
-            array_push($testPTLinkData, [
401
-                'post_id' => $testPostData['id'],
402
-                'tag_id' => $testTagRow['id'],
403
-            ]);
404
-        }
405
-
406
-        $this->insertPostData($testPostData);
407
-        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
408
-        array_walk($testTagData, [$this, 'insertTagData']);
409
-
410
-        $repository = new MysqlTagRepository(self::$connection);
411
-        $data = $repository->getTagsForPost($testPostData['id']);
412
-
413
-        $this->assertNotFalse($data);
414
-        $this->assertInternalType('array', $data);
415
-        $this->assertCount(count($testTagData), $data);
416
-
417
-        usort($testTagData, function ($rowA, $rowB) {
418
-            return ($rowA['tag'] > $rowB['tag']);
419
-        });
420
-
421
-        foreach ($testTagData as $key => $testTagRow) {
422
-            $this->assertArrayHasKey('id', $data[$key]);
423
-            $this->assertEquals($testTagRow['id'], $data[$key]['id']);
424
-            $this->assertArrayHasKey('tag', $data[$key]);
425
-            $this->assertEquals($testTagRow['tag'], $data[$key]['tag']);
426
-        }
427
-    }
376
+	public function testGetTagsForPost()
377
+	{
378
+		$testPostData = [
379
+			'id' => rand(1, 100),
380
+			'display' => 1,
381
+		];
382
+
383
+		$testTagData = [
384
+			[
385
+				'id' => rand(1, 100),
386
+				'tag' => 'test one',
387
+			],
388
+			[
389
+				'id' => rand(101, 200),
390
+				'tag' => 'test two',
391
+			],
392
+			[
393
+				'id' => rand(201, 300),
394
+				'tag' => 'test three',
395
+			],
396
+		];
397
+
398
+		$testPTLinkData = [];
399
+		foreach ($testTagData as $testTagRow) {
400
+			array_push($testPTLinkData, [
401
+				'post_id' => $testPostData['id'],
402
+				'tag_id' => $testTagRow['id'],
403
+			]);
404
+		}
405
+
406
+		$this->insertPostData($testPostData);
407
+		array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
408
+		array_walk($testTagData, [$this, 'insertTagData']);
409
+
410
+		$repository = new MysqlTagRepository(self::$connection);
411
+		$data = $repository->getTagsForPost($testPostData['id']);
412
+
413
+		$this->assertNotFalse($data);
414
+		$this->assertInternalType('array', $data);
415
+		$this->assertCount(count($testTagData), $data);
416
+
417
+		usort($testTagData, function ($rowA, $rowB) {
418
+			return ($rowA['tag'] > $rowB['tag']);
419
+		});
420
+
421
+		foreach ($testTagData as $key => $testTagRow) {
422
+			$this->assertArrayHasKey('id', $data[$key]);
423
+			$this->assertEquals($testTagRow['id'], $data[$key]['id']);
424
+			$this->assertArrayHasKey('tag', $data[$key]);
425
+			$this->assertEquals($testTagRow['tag'], $data[$key]['tag']);
426
+		}
427
+	}
428 428
  
429
-    public function testGetTagsForPostFailure()
430
-    {
431
-        $testData = [
432
-            [
433
-                'id' => rand(1, 100),
434
-                'tag' => 'test one',
435
-            ],
436
-            [
437
-                'id' => rand(101, 200),
438
-                'tag' => 'test two',
439
-            ],
440
-        ];
441
-
442
-        array_walk($testData, [$this, 'insertTagData']);
443
-
444
-        $repository = new MysqlTagRepository(self::$connection);
445
-        $data = $repository->getTagsForPost(rand(1, 10));
446
-
447
-        $this->assertEmpty($data);
448
-        $this->assertInternalType('array', $data);
449
-    }
450
-
451
-    protected function insertPostData(array $data)
452
-    {
453
-        $defaultData = [
454
-            'id' => null,
455
-            'title' => '',
456
-            'path' => '',
457
-            'category' => '',
458
-            'date' => '',
459
-            'body' => '',
460
-            'display' => 0,
461
-        ];
462
-
463
-        $data = array_merge($defaultData, $data);
464
-
465
-        return self::$connection->getDefault()->perform("
429
+	public function testGetTagsForPostFailure()
430
+	{
431
+		$testData = [
432
+			[
433
+				'id' => rand(1, 100),
434
+				'tag' => 'test one',
435
+			],
436
+			[
437
+				'id' => rand(101, 200),
438
+				'tag' => 'test two',
439
+			],
440
+		];
441
+
442
+		array_walk($testData, [$this, 'insertTagData']);
443
+
444
+		$repository = new MysqlTagRepository(self::$connection);
445
+		$data = $repository->getTagsForPost(rand(1, 10));
446
+
447
+		$this->assertEmpty($data);
448
+		$this->assertInternalType('array', $data);
449
+	}
450
+
451
+	protected function insertPostData(array $data)
452
+	{
453
+		$defaultData = [
454
+			'id' => null,
455
+			'title' => '',
456
+			'path' => '',
457
+			'category' => '',
458
+			'date' => '',
459
+			'body' => '',
460
+			'display' => 0,
461
+		];
462
+
463
+		$data = array_merge($defaultData, $data);
464
+
465
+		return self::$connection->getDefault()->perform("
466 466
             INSERT INTO `jpemeric_blog`.`post`
467 467
                 (id, title, path, category, date, body, display)
468 468
             VALUES
469 469
                 (:id, :title, :path, :category, :date, :body, :display)",
470
-            $data
471
-        );
472
-    }
470
+			$data
471
+		);
472
+	}
473 473
 
474
-    protected function insertPTLinkData(array $data)
475
-    {
476
-        $defaultData = [
477
-            'post' => null,
478
-            'tag' => null,
479
-        ];
474
+	protected function insertPTLinkData(array $data)
475
+	{
476
+		$defaultData = [
477
+			'post' => null,
478
+			'tag' => null,
479
+		];
480 480
 
481
-        $data = array_merge($defaultData, $data);
481
+		$data = array_merge($defaultData, $data);
482 482
 
483
-        return self::$connection->getDefault()->perform("
483
+		return self::$connection->getDefault()->perform("
484 484
             INSERT INTO `jpemeric_blog`.`ptlink`
485 485
                 (post_id, tag_id)
486 486
             VALUES
487 487
                 (:post_id, :tag_id)",
488
-            $data
489
-        );
490
-    }
488
+			$data
489
+		);
490
+	}
491 491
 
492
-    protected function insertTagData(array $data)
493
-    {
494
-        $defaultData = [
495
-            'id' => null,
496
-            'tag' => '',
497
-        ];
492
+	protected function insertTagData(array $data)
493
+	{
494
+		$defaultData = [
495
+			'id' => null,
496
+			'tag' => '',
497
+		];
498 498
 
499
-        $data = array_merge($defaultData, $data);
499
+		$data = array_merge($defaultData, $data);
500 500
 
501
-        return self::$connection->getDefault()->perform("
501
+		return self::$connection->getDefault()->perform("
502 502
             INSERT INTO `jpemeric_blog`.`tag`
503 503
                 (id, tag)
504 504
             VALUES
505 505
                 (:id, :tag)",
506
-            $data
507
-        );
508
-    }
509
-
510
-    protected function tearDown()
511
-    {
512
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`post`");
513
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`ptlink`");
514
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`tag`");
515
-    }
516
-
517
-    public static function tearDownAfterClass()
518
-    {
519
-        self::$connection->getDefault()->disconnect();
520
-        unlink('jpemeric_blog.db');
521
-    }
506
+			$data
507
+		);
508
+	}
509
+
510
+	protected function tearDown()
511
+	{
512
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`post`");
513
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`ptlink`");
514
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`tag`");
515
+	}
516
+
517
+	public static function tearDownAfterClass()
518
+	{
519
+		self::$connection->getDefault()->disconnect();
520
+		unlink('jpemeric_blog.db');
521
+	}
522 522
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
             )"
41 41
         );
42 42
 
43
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
43
+        self::$connection = new ConnectionLocator(function() use ($extendedPdo) {
44 44
             return $extendedPdo;
45 45
         });
46 46
     }
@@ -200,9 +200,9 @@  discard block
 block discarded – undo
200 200
         $this->assertNotFalse($data);
201 201
         $this->assertInternalType('array', $data);
202 202
 
203
-        $tagCountData = array_map(function ($row) use ($testTagData) {
203
+        $tagCountData = array_map(function($row) use ($testTagData) {
204 204
             $tag = $row['tag_id'];
205
-            $tag = array_filter($testTagData, function ($row) use ($tag) {
205
+            $tag = array_filter($testTagData, function($row) use ($tag) {
206 206
                 return ($tag == $row['id']);
207 207
             });
208 208
             $tag = current($tag)['tag'];
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
 
230 230
         $this->assertCount(count($testCountData), $data);
231 231
 
232
-        usort($testCountData, function ($rowA, $rowB) {
232
+        usort($testCountData, function($rowA, $rowB) {
233 233
             return ($rowA['tag'] > $rowB['tag']);
234 234
         });
235
-        usort($data, function ($rowA, $rowB) {
235
+        usort($data, function($rowA, $rowB) {
236 236
             return ($rowA['tag'] > $rowB['tag']);
237 237
         });
238 238
 
@@ -298,18 +298,18 @@  discard block
 block discarded – undo
298 298
         $this->assertNotFalse($data);
299 299
         $this->assertInternalType('array', $data);
300 300
 
301
-        $testPTLinkData = array_filter($testPTLinkData, function ($row) use ($testPostData) {
301
+        $testPTLinkData = array_filter($testPTLinkData, function($row) use ($testPostData) {
302 302
             $post = $row['post_id'];
303
-            $post = array_filter($testPostData, function ($row) use ($post) {
303
+            $post = array_filter($testPostData, function($row) use ($post) {
304 304
                 return ($post == $row['id']);
305 305
             });
306 306
             $post = current($post);
307 307
             return ($post['display'] == 1);
308 308
         });
309 309
 
310
-        $tagCountData = array_map(function ($row) use ($testTagData) {
310
+        $tagCountData = array_map(function($row) use ($testTagData) {
311 311
             $tag = $row['tag_id'];
312
-            $tag = array_filter($testTagData, function ($row) use ($tag) {
312
+            $tag = array_filter($testTagData, function($row) use ($tag) {
313 313
                 return ($tag == $row['id']);
314 314
             });
315 315
             $tag = current($tag)['tag'];
@@ -336,10 +336,10 @@  discard block
 block discarded – undo
336 336
 
337 337
         $this->assertCount(count($testCountData), $data);
338 338
 
339
-        usort($testCountData, function ($rowA, $rowB) {
339
+        usort($testCountData, function($rowA, $rowB) {
340 340
             return ($rowA['tag'] > $rowB['tag']);
341 341
         });
342
-        usort($data, function ($rowA, $rowB) {
342
+        usort($data, function($rowA, $rowB) {
343 343
             return ($rowA['tag'] > $rowB['tag']);
344 344
         });
345 345
 
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
         $this->assertInternalType('array', $data);
415 415
         $this->assertCount(count($testTagData), $data);
416 416
 
417
-        usort($testTagData, function ($rowA, $rowB) {
417
+        usort($testTagData, function($rowA, $rowB) {
418 418
             return ($rowA['tag'] > $rowB['tag']);
419 419
         });
420 420
 
Please login to merge, or discard this patch.
tests/unit/Domain/Blog/Post/MysqlPostRepositoryTest.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
             )"
49 49
         );
50 50
 
51
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
51
+        self::$connection = new ConnectionLocator(function() use ($extendedPdo) {
52 52
             return $extendedPdo;
53 53
         });
54 54
     }
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
         $this->assertInternalType('array', $data);
175 175
         $this->assertCount(count($testData), $data);
176 176
 
177
-        usort($testData, function ($rowA, $rowB) {
177
+        usort($testData, function($rowA, $rowB) {
178 178
             return ((new DateTime($rowA['date'])) < (new DateTime($rowB['date'])));
179 179
         });
180 180
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
         $this->assertNotFalse($data);
220 220
         $this->assertInternalType('array', $data);
221 221
 
222
-        $testData = array_filter($testData, function ($row) {
222
+        $testData = array_filter($testData, function($row) {
223 223
             return ($row['display'] == 1);
224 224
         });
225 225
 
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
         $this->assertNotFalse($data);
355 355
         $this->assertStringMatchesFormat('%d', $data);
356 356
 
357
-        $testData = array_filter($testData, function ($row) {
357
+        $testData = array_filter($testData, function($row) {
358 358
             return ($row['display'] == 1);
359 359
         });
360 360
 
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
         $this->assertNotFalse($data);
472 472
         $this->assertInternalType('array', $data);
473 473
 
474
-        $testPostData = array_filter($testPostData, function ($row) {
474
+        $testPostData = array_filter($testPostData, function($row) {
475 475
             return ($row['display'] == 1);
476 476
         });
477 477
 
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
         $this->assertNotFalse($data);
672 672
         $this->assertStringMatchesFormat('%d', $data);
673 673
 
674
-        $testPostData = array_filter($testPostData, function ($row) {
674
+        $testPostData = array_filter($testPostData, function($row) {
675 675
             return ($row['display'] == 1);
676 676
         });
677 677
 
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
         $this->assertNotFalse($data);
770 770
         $this->assertInternalType('array', $data);
771 771
 
772
-        $testData = array_filter($testData, function ($row) {
772
+        $testData = array_filter($testData, function($row) {
773 773
             return ($row['display'] == 1);
774 774
         });
775 775
 
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
         $this->assertNotFalse($data);
922 922
         $this->assertStringMatchesFormat('%d', $data);
923 923
 
924
-        $testData = array_filter($testData, function ($row) {
924
+        $testData = array_filter($testData, function($row) {
925 925
             return ($row['display'] == 1);
926 926
         });
927 927
 
@@ -1109,7 +1109,7 @@  discard block
 block discarded – undo
1109 1109
         $this->assertInternalType('array', $data);
1110 1110
 
1111 1111
         array_shift($testPostData);
1112
-        $testPostData = array_filter($testPostData, function ($row) {
1112
+        $testPostData = array_filter($testPostData, function($row) {
1113 1113
             return ($row['display'] == 1);
1114 1114
         });
1115 1115
 
@@ -1181,7 +1181,7 @@  discard block
 block discarded – undo
1181 1181
         $this->assertInternalType('array', $data);
1182 1182
 
1183 1183
         array_shift($testPostData);
1184
-        $testPostData = array_filter($testPostData, function ($row) use ($testSeriesPostData) {
1184
+        $testPostData = array_filter($testPostData, function($row) use ($testSeriesPostData) {
1185 1185
             return (!in_array($row['id'], array_column($testSeriesPostData, 'post')));
1186 1186
         });
1187 1187
 
Please login to merge, or discard this patch.
Indentation   +1225 added lines, -1225 removed lines patch added patch discarded remove patch
@@ -10,14 +10,14 @@  discard block
 block discarded – undo
10 10
 class MysqlPostRepositoryTest extends PHPUnit_Framework_TestCase
11 11
 {
12 12
 
13
-    protected static $connection;
13
+	protected static $connection;
14 14
 
15
-    public static function setUpBeforeClass()
16
-    {
17
-        $extendedPdo = new ExtendedPdo('sqlite::memory:');
18
-        $extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`');
15
+	public static function setUpBeforeClass()
16
+	{
17
+		$extendedPdo = new ExtendedPdo('sqlite::memory:');
18
+		$extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`');
19 19
 
20
-        $extendedPdo->exec("
20
+		$extendedPdo->exec("
21 21
             CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`post` (
22 22
                 `id` integer PRIMARY KEY AUTOINCREMENT,
23 23
                 `title` varchar(60) NOT NULL,
@@ -27,1272 +27,1272 @@  discard block
 block discarded – undo
27 27
                 `body` text,
28 28
                 `display` integer(1) NOT NULL
29 29
             )"
30
-        );
31
-        $extendedPdo->exec("
30
+		);
31
+		$extendedPdo->exec("
32 32
             CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`ptlink` (
33 33
                 `post_id` integer NOT NULL,
34 34
                 `tag_id` integer 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
-        $extendedPdo->exec("
43
+		);
44
+		$extendedPdo->exec("
45 45
             CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`tag` (
46 46
                 `id` integer PRIMARY KEY AUTOINCREMENT,
47 47
                 `tag` varchar(25) NOT NULL
48 48
             )"
49
-        );
50
-
51
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
52
-            return $extendedPdo;
53
-        });
54
-    }
55
-
56
-    public function testIsInstanceOfPostRepository()
57
-    {
58
-        $repository = new MysqlPostRepository(self::$connection);
59
-
60
-        $this->assertInstanceOf(
61
-            'Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository',
62
-            $repository
63
-        );
64
-    }
65
-
66
-    public function testImplementsPostInterface()
67
-    {
68
-        $repository = new MysqlPostRepository(self::$connection);
69
-
70
-        $this->assertInstanceOf(
71
-            'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface',
72
-            $repository
73
-        );
74
-    }
75
-
76
-    public function testConstructSetsConnections()
77
-    {
78
-        $respository = new MysqlPostRepository(self::$connection);
79
-
80
-        $this->assertAttributeSame(
81
-            self::$connection,
82
-            'connections',
83
-            $respository
84
-        );
85
-    }
86
-
87
-    public function testFindPostByPath()
88
-    {
89
-        $testData = [
90
-            'id'       => rand(1, 100),
91
-            'title'    => 'test title',
92
-            'path'     => 'test-path',
93
-            'category' => 'test category',
94
-            'date'     => (new DateTime())->format('Y-m-d H:i:s'),
95
-            'body'     => 'test body',
96
-            'display'  => 1
97
-        ];
98
-
99
-        $this->insertPostData($testData);
100
-
101
-        $repository = new MysqlPostRepository(self::$connection);
102
-        $data = $repository->findPostByPath($testData['path']);
103
-
104
-        $this->assertNotFalse($data);
105
-        $this->assertInternalType('array', $data);
106
-        $this->assertArrayHasKey('id', $data);
107
-        $this->assertEquals($testData['id'], $data['id']);
108
-        $this->assertArrayHasKey('title', $data);
109
-        $this->assertEquals($testData['title'], $data['title']);
110
-        $this->assertArrayHasKey('path', $data);
111
-        $this->assertEquals($testData['path'], $data['path']);
112
-        $this->assertArrayHasKey('date', $data);
113
-        $this->assertEquals($testData['date'], $data['date']);
114
-        $this->assertArrayHasKey('body', $data);
115
-        $this->assertEquals($testData['body'], $data['body']);
116
-        $this->assertArrayHasKey('category', $data);
117
-        $this->assertEquals($testData['category'], $data['category']);
118
-    }
119
-
120
-    public function testFindPostByPathInactive()
121
-    {
122
-        $testData = [
123
-            'id'       => rand(1, 100),
124
-            'path'     => 'test-path',
125
-            'display'  => 0
126
-        ];
127
-
128
-        $this->insertPostData($testData);
129
-
130
-        $repository = new MysqlPostRepository(self::$connection);
131
-        $data = $repository->findPostByPath($testData['path']);
132
-
133
-        $this->assertFalse($data);
134
-    }
135
-
136
-    public function testFindPostByPathFailure()
137
-    {
138
-        $repository = new MysqlPostRepository(self::$connection);
139
-        $data = $repository->findPostByPath('');
140
-
141
-        $this->assertFalse($data);
142
-    }
143
-
144
-    public function testGetActivePosts()
145
-    {
146
-        $testData = [
147
-            [
148
-                'id'       => rand(1, 100),
149
-                'title'    => 'title one',
150
-                'path'     => 'path-one',
151
-                'category' => 'test category',
152
-                'date'     => (new DateTime('-1 day'))->format('Y-m-d H:i:s'),
153
-                'body'     => 'body one',
154
-                'display'  => 1,
155
-            ],
156
-            [
157
-                'id'       => rand(101, 200),
158
-                'title'    => 'title two',
159
-                'path'     => 'path-two',
160
-                'category' => 'test category',
161
-                'date'     => (new DateTime())->format('Y-m-d H:i:s'),
162
-                'body'     => 'body one',
163
-                'display'  => 1,
164
-            ],
165
-        ];
166
-
167
-        array_walk($testData, [$this, 'insertPostData']);
168
-
169
-        $repository = new MysqlPostRepository(self::$connection);
170
-        $data = $repository->getActivePosts();
171
-
172
-        $this->assertNotFalse($data);
173
-        $this->assertInternalType('array', $data);
174
-        $this->assertCount(count($testData), $data);
175
-
176
-        usort($testData, function ($rowA, $rowB) {
177
-            return ((new DateTime($rowA['date'])) < (new DateTime($rowB['date'])));
178
-        });
179
-
180
-        foreach ($testData as $key => $testRow) {
181
-            $this->assertArrayHasKey('id', $data[$key]);
182
-            $this->assertEquals($testRow['id'], $data[$key]['id']);
183
-            $this->assertArrayHasKey('title', $data[$key]);
184
-            $this->assertEquals($testRow['title'], $data[$key]['title']);
185
-            $this->assertArrayHasKey('path', $data[$key]);
186
-            $this->assertEquals($testRow['path'], $data[$key]['path']);
187
-            $this->assertArrayHasKey('date', $data[$key]);
188
-            $this->assertEquals($testRow['date'], $data[$key]['date']);
189
-            $this->assertArrayHasKey('body', $data[$key]);
190
-            $this->assertEquals($testRow['body'], $data[$key]['body']);
191
-            $this->assertArrayHasKey('category', $data[$key]);
192
-            $this->assertEquals($testRow['category'], $data[$key]['category']);
193
-        }
194
-    }
49
+		);
50
+
51
+		self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
52
+			return $extendedPdo;
53
+		});
54
+	}
55
+
56
+	public function testIsInstanceOfPostRepository()
57
+	{
58
+		$repository = new MysqlPostRepository(self::$connection);
59
+
60
+		$this->assertInstanceOf(
61
+			'Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository',
62
+			$repository
63
+		);
64
+	}
65
+
66
+	public function testImplementsPostInterface()
67
+	{
68
+		$repository = new MysqlPostRepository(self::$connection);
69
+
70
+		$this->assertInstanceOf(
71
+			'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface',
72
+			$repository
73
+		);
74
+	}
75
+
76
+	public function testConstructSetsConnections()
77
+	{
78
+		$respository = new MysqlPostRepository(self::$connection);
79
+
80
+		$this->assertAttributeSame(
81
+			self::$connection,
82
+			'connections',
83
+			$respository
84
+		);
85
+	}
86
+
87
+	public function testFindPostByPath()
88
+	{
89
+		$testData = [
90
+			'id'       => rand(1, 100),
91
+			'title'    => 'test title',
92
+			'path'     => 'test-path',
93
+			'category' => 'test category',
94
+			'date'     => (new DateTime())->format('Y-m-d H:i:s'),
95
+			'body'     => 'test body',
96
+			'display'  => 1
97
+		];
98
+
99
+		$this->insertPostData($testData);
100
+
101
+		$repository = new MysqlPostRepository(self::$connection);
102
+		$data = $repository->findPostByPath($testData['path']);
103
+
104
+		$this->assertNotFalse($data);
105
+		$this->assertInternalType('array', $data);
106
+		$this->assertArrayHasKey('id', $data);
107
+		$this->assertEquals($testData['id'], $data['id']);
108
+		$this->assertArrayHasKey('title', $data);
109
+		$this->assertEquals($testData['title'], $data['title']);
110
+		$this->assertArrayHasKey('path', $data);
111
+		$this->assertEquals($testData['path'], $data['path']);
112
+		$this->assertArrayHasKey('date', $data);
113
+		$this->assertEquals($testData['date'], $data['date']);
114
+		$this->assertArrayHasKey('body', $data);
115
+		$this->assertEquals($testData['body'], $data['body']);
116
+		$this->assertArrayHasKey('category', $data);
117
+		$this->assertEquals($testData['category'], $data['category']);
118
+	}
119
+
120
+	public function testFindPostByPathInactive()
121
+	{
122
+		$testData = [
123
+			'id'       => rand(1, 100),
124
+			'path'     => 'test-path',
125
+			'display'  => 0
126
+		];
127
+
128
+		$this->insertPostData($testData);
129
+
130
+		$repository = new MysqlPostRepository(self::$connection);
131
+		$data = $repository->findPostByPath($testData['path']);
132
+
133
+		$this->assertFalse($data);
134
+	}
135
+
136
+	public function testFindPostByPathFailure()
137
+	{
138
+		$repository = new MysqlPostRepository(self::$connection);
139
+		$data = $repository->findPostByPath('');
140
+
141
+		$this->assertFalse($data);
142
+	}
143
+
144
+	public function testGetActivePosts()
145
+	{
146
+		$testData = [
147
+			[
148
+				'id'       => rand(1, 100),
149
+				'title'    => 'title one',
150
+				'path'     => 'path-one',
151
+				'category' => 'test category',
152
+				'date'     => (new DateTime('-1 day'))->format('Y-m-d H:i:s'),
153
+				'body'     => 'body one',
154
+				'display'  => 1,
155
+			],
156
+			[
157
+				'id'       => rand(101, 200),
158
+				'title'    => 'title two',
159
+				'path'     => 'path-two',
160
+				'category' => 'test category',
161
+				'date'     => (new DateTime())->format('Y-m-d H:i:s'),
162
+				'body'     => 'body one',
163
+				'display'  => 1,
164
+			],
165
+		];
166
+
167
+		array_walk($testData, [$this, 'insertPostData']);
168
+
169
+		$repository = new MysqlPostRepository(self::$connection);
170
+		$data = $repository->getActivePosts();
171
+
172
+		$this->assertNotFalse($data);
173
+		$this->assertInternalType('array', $data);
174
+		$this->assertCount(count($testData), $data);
175
+
176
+		usort($testData, function ($rowA, $rowB) {
177
+			return ((new DateTime($rowA['date'])) < (new DateTime($rowB['date'])));
178
+		});
179
+
180
+		foreach ($testData as $key => $testRow) {
181
+			$this->assertArrayHasKey('id', $data[$key]);
182
+			$this->assertEquals($testRow['id'], $data[$key]['id']);
183
+			$this->assertArrayHasKey('title', $data[$key]);
184
+			$this->assertEquals($testRow['title'], $data[$key]['title']);
185
+			$this->assertArrayHasKey('path', $data[$key]);
186
+			$this->assertEquals($testRow['path'], $data[$key]['path']);
187
+			$this->assertArrayHasKey('date', $data[$key]);
188
+			$this->assertEquals($testRow['date'], $data[$key]['date']);
189
+			$this->assertArrayHasKey('body', $data[$key]);
190
+			$this->assertEquals($testRow['body'], $data[$key]['body']);
191
+			$this->assertArrayHasKey('category', $data[$key]);
192
+			$this->assertEquals($testRow['category'], $data[$key]['category']);
193
+		}
194
+	}
195 195
  
196
-    public function testGetActivePostsInactive()
197
-    {
198
-        $testData = [
199
-            [
200
-                'id'      => rand(1, 100),
201
-                'display' => 1,
202
-            ],
203
-            [
204
-                'id'      => rand(101, 200),
205
-                'display' => 0,
206
-            ],
207
-            [
208
-                'id'      => rand(201, 300),
209
-                'display' => 1,
210
-            ],
211
-        ];
212
-
213
-        array_walk($testData, [$this, 'insertPostData']);
214
-
215
-        $repository = new MysqlPostRepository(self::$connection);
216
-        $data = $repository->getActivePosts();
217
-
218
-        $this->assertNotFalse($data);
219
-        $this->assertInternalType('array', $data);
220
-
221
-        $testData = array_filter($testData, function ($row) {
222
-            return ($row['display'] == 1);
223
-        });
224
-
225
-        $this->assertCount(count($testData), $data);
226
-
227
-        $testIds = array_column($testData, 'ids');
228
-        $dataIds = array_column($data, 'ids');
229
-
230
-        $this->assertEmpty(array_merge(
231
-            array_diff($testIds, $dataIds),
232
-            array_diff($dataIds, $testIds)
233
-        ));
234
-    }
196
+	public function testGetActivePostsInactive()
197
+	{
198
+		$testData = [
199
+			[
200
+				'id'      => rand(1, 100),
201
+				'display' => 1,
202
+			],
203
+			[
204
+				'id'      => rand(101, 200),
205
+				'display' => 0,
206
+			],
207
+			[
208
+				'id'      => rand(201, 300),
209
+				'display' => 1,
210
+			],
211
+		];
212
+
213
+		array_walk($testData, [$this, 'insertPostData']);
214
+
215
+		$repository = new MysqlPostRepository(self::$connection);
216
+		$data = $repository->getActivePosts();
217
+
218
+		$this->assertNotFalse($data);
219
+		$this->assertInternalType('array', $data);
220
+
221
+		$testData = array_filter($testData, function ($row) {
222
+			return ($row['display'] == 1);
223
+		});
224
+
225
+		$this->assertCount(count($testData), $data);
226
+
227
+		$testIds = array_column($testData, 'ids');
228
+		$dataIds = array_column($data, 'ids');
229
+
230
+		$this->assertEmpty(array_merge(
231
+			array_diff($testIds, $dataIds),
232
+			array_diff($dataIds, $testIds)
233
+		));
234
+	}
235 235
  
236
-    public function testGetActivePostsFailure()
237
-    {
238
-        $repository = new MysqlPostRepository(self::$connection);
239
-        $data = $repository->getActivePosts();
240
-
241
-        $this->assertEmpty($data);
242
-        $this->assertInternalType('array', $data);
243
-    }
244
-
245
-    public function testGetActivePostsRange()
246
-    {
247
-        $testData = [
248
-            [
249
-                'id'      => rand(1, 100),
250
-                'display' => 1,
251
-            ],
252
-            [
253
-                'id'      => rand(101, 200),
254
-                'display' => 1,
255
-            ],
256
-            [
257
-                'id'      => rand(201, 300),
258
-                'display' => 1,
259
-            ],
260
-        ];
261
-
262
-        array_walk($testData, [$this, 'insertPostData']);
263
-
264
-        $repository = new MysqlPostRepository(self::$connection);
265
-        $data = $repository->getActivePosts(2, 1);
266
-
267
-        $this->assertNotFalse($data);
268
-        $this->assertInternalType('array', $data);
269
-        $this->assertCount(2, $data);
270
-
271
-        $testData = array_slice($testData, 2, 1);
272
-
273
-        $testIds = array_column($testData, 'ids');
274
-        $dataIds = array_column($data, 'ids');
275
-
276
-        $this->assertEmpty(array_merge(
277
-            array_diff($testIds, $dataIds),
278
-            array_diff($dataIds, $testIds)
279
-        ));
280
-    }
281
-
282
-    public function testGetActivePostsRangeFailure()
283
-    {
284
-        $testData = [
285
-            [
286
-                'id'      => rand(1, 100),
287
-                'display' => 1,
288
-            ],
289
-            [
290
-                'id'      => rand(101, 200),
291
-                'display' => 1,
292
-            ],
293
-            [
294
-                'id'      => rand(201, 300),
295
-                'display' => 1,
296
-            ],
297
-        ];
298
-
299
-        array_walk($testData, [$this, 'insertPostData']);
300
-
301
-        $repository = new MysqlPostRepository(self::$connection);
302
-        $data = $repository->getActivePosts(1, 3);
303
-
304
-        $this->assertEmpty($data);
305
-        $this->assertInternalType('array', $data);
306
-    }
307
-
308
-    public function testGetActivePostsCount()
309
-    {
310
-        $testData = [
311
-            [
312
-                'id'      => rand(1, 100),
313
-                'display' => 1,
314
-            ],
315
-            [
316
-                'id'      => rand(101, 200),
317
-                'display' => 1,
318
-            ],
319
-        ];
320
-
321
-        array_walk($testData, [$this, 'insertPostData']);
322
-
323
-        $repository = new MysqlPostRepository(self::$connection);
324
-        $data = $repository->getActivePostsCount();
325
-
326
-        $this->assertNotFalse($data);
327
-        $this->assertStringMatchesFormat('%d', $data);
328
-        $this->assertEquals(count($testData), $data);
329
-    }
330
-
331
-    public function testGetActivePostsCountInactive()
332
-    {
333
-        $testData = [
334
-            [
335
-                'id'      => rand(1, 100),
336
-                'display' => 1,
337
-            ],
338
-            [
339
-                'id'      => rand(101, 200),
340
-                'display' => 1,
341
-            ],
342
-            [
343
-                'id'      => rand(201, 300),
344
-                'display' => 0,
345
-            ],
346
-        ];
347
-
348
-        array_walk($testData, [$this, 'insertPostData']);
349
-
350
-        $repository = new MysqlPostRepository(self::$connection);
351
-        $data = $repository->getActivePostsCount();
352
-
353
-        $this->assertNotFalse($data);
354
-        $this->assertStringMatchesFormat('%d', $data);
355
-
356
-        $testData = array_filter($testData, function ($row) {
357
-            return ($row['display'] == 1);
358
-        });
359
-
360
-        $this->assertEquals(count($testData), $data);
361
-    }
362
-
363
-    public function testGetActivePostsCountFailure()
364
-    {
365
-        $repository = new MysqlPostRepository(self::$connection);
366
-        $data = $repository->getActivePostsCount();
367
-
368
-        $this->assertNotFalse($data);
369
-        $this->assertStringMatchesFormat('%d', $data);
370
-        $this->assertEquals('0', $data);
371
-    }
372
-
373
-    public function testGetActivePostsByTag()
374
-    {
375
-        $testPostData = [
376
-            [
377
-                'id'       => rand(1, 100),
378
-                'title'    => 'title one',
379
-                'path'     => 'path-one',
380
-                'category' => 'test category',
381
-                'date'     => (new DateTime('-1 day'))->format('Y-m-d H:i:s'),
382
-                'body'     => 'body one',
383
-                'display'  => 1,
384
-            ],
385
-            [
386
-                'id'       => rand(101, 200),
387
-                'title'    => 'title two',
388
-                'path'     => 'path-two',
389
-                'category' => 'test category',
390
-                'date'     => (new DateTime())->format('Y-m-d H:i:s'),
391
-                'body'     => 'body one',
392
-                'display'  => 1,
393
-            ],
394
-        ];
395
-
396
-        $testTagData = [
397
-            'id' => rand(1, 100),
398
-        ];
399
-
400
-        $testPTLinkData = [];
401
-        foreach ($testPostData as $testPostRow) {
402
-            array_push($testPTLinkData, [
403
-                'post_id' => $testPostRow['id'],
404
-                'tag_id' => $testTagData['id'],
405
-            ]);
406
-        }
407
-
408
-        array_walk($testPostData, [$this, 'insertPostData']);
409
-        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
410
-        $this->insertTagData($testTagData);
411
-
412
-        $repository = new MysqlPostRepository(self::$connection);
413
-        $data = $repository->getActivePostsByTag($testTagData['id']);
414
-
415
-        $this->assertNotFalse($data);
416
-        $this->assertInternalType('array', $data);
417
-        $this->assertCount(count($testPostData), $data);
418
-        foreach ($testPostData as $key => $testPostRow) {
419
-            $this->assertArrayHasKey('id', $data[$key]);
420
-            $this->assertEquals($testPostRow['id'], $data[$key]['id']);
421
-            $this->assertArrayHasKey('title', $data[$key]);
422
-            $this->assertEquals($testPostRow['title'], $data[$key]['title']);
423
-            $this->assertArrayHasKey('path', $data[$key]);
424
-            $this->assertEquals($testPostRow['path'], $data[$key]['path']);
425
-            $this->assertArrayHasKey('date', $data[$key]);
426
-            $this->assertEquals($testPostRow['date'], $data[$key]['date']);
427
-            $this->assertArrayHasKey('body', $data[$key]);
428
-            $this->assertEquals($testPostRow['body'], $data[$key]['body']);
429
-            $this->assertArrayHasKey('category', $data[$key]);
430
-            $this->assertEquals($testPostRow['category'], $data[$key]['category']);
431
-        }
432
-    }
433
-
434
-    public function testGetActivePostsByTagInactive()
435
-    {
436
-        $testPostData = [
437
-            [
438
-                'id'      => rand(1, 100),
439
-                'display' => 1,
440
-            ],
441
-            [
442
-                'id'      => rand(101, 200),
443
-                'display' => 0,
444
-            ],
445
-            [
446
-                'id'      => rand(201, 300),
447
-                'display' => 1,
448
-            ],
449
-        ];
450
-
451
-        $testTagData = [
452
-            'id' => rand(1, 100),
453
-        ];
454
-
455
-        $testPTLinkData = [];
456
-        foreach ($testPostData as $testPostRow) {
457
-            array_push($testPTLinkData, [
458
-                'post_id' => $testPostRow['id'],
459
-                'tag_id' => $testTagData['id'],
460
-            ]);
461
-        }
462
-
463
-        array_walk($testPostData, [$this, 'insertPostData']);
464
-        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
465
-        $this->insertTagData($testTagData);
466
-
467
-        $repository = new MysqlPostRepository(self::$connection);
468
-        $data = $repository->getActivePostsByTag($testTagData['id']);
469
-
470
-        $this->assertNotFalse($data);
471
-        $this->assertInternalType('array', $data);
472
-
473
-        $testPostData = array_filter($testPostData, function ($row) {
474
-            return ($row['display'] == 1);
475
-        });
476
-
477
-        $this->assertCount(count($testPostData), $data);
478
-
479
-        $testIds = array_column($testPostData, 'ids');
480
-        $dataIds = array_column($data, 'ids');
481
-
482
-        $this->assertEmpty(array_merge(
483
-            array_diff($testIds, $dataIds),
484
-            array_diff($dataIds, $testIds)
485
-        ));
486
-    }
236
+	public function testGetActivePostsFailure()
237
+	{
238
+		$repository = new MysqlPostRepository(self::$connection);
239
+		$data = $repository->getActivePosts();
240
+
241
+		$this->assertEmpty($data);
242
+		$this->assertInternalType('array', $data);
243
+	}
244
+
245
+	public function testGetActivePostsRange()
246
+	{
247
+		$testData = [
248
+			[
249
+				'id'      => rand(1, 100),
250
+				'display' => 1,
251
+			],
252
+			[
253
+				'id'      => rand(101, 200),
254
+				'display' => 1,
255
+			],
256
+			[
257
+				'id'      => rand(201, 300),
258
+				'display' => 1,
259
+			],
260
+		];
261
+
262
+		array_walk($testData, [$this, 'insertPostData']);
263
+
264
+		$repository = new MysqlPostRepository(self::$connection);
265
+		$data = $repository->getActivePosts(2, 1);
266
+
267
+		$this->assertNotFalse($data);
268
+		$this->assertInternalType('array', $data);
269
+		$this->assertCount(2, $data);
270
+
271
+		$testData = array_slice($testData, 2, 1);
272
+
273
+		$testIds = array_column($testData, 'ids');
274
+		$dataIds = array_column($data, 'ids');
275
+
276
+		$this->assertEmpty(array_merge(
277
+			array_diff($testIds, $dataIds),
278
+			array_diff($dataIds, $testIds)
279
+		));
280
+	}
281
+
282
+	public function testGetActivePostsRangeFailure()
283
+	{
284
+		$testData = [
285
+			[
286
+				'id'      => rand(1, 100),
287
+				'display' => 1,
288
+			],
289
+			[
290
+				'id'      => rand(101, 200),
291
+				'display' => 1,
292
+			],
293
+			[
294
+				'id'      => rand(201, 300),
295
+				'display' => 1,
296
+			],
297
+		];
298
+
299
+		array_walk($testData, [$this, 'insertPostData']);
300
+
301
+		$repository = new MysqlPostRepository(self::$connection);
302
+		$data = $repository->getActivePosts(1, 3);
303
+
304
+		$this->assertEmpty($data);
305
+		$this->assertInternalType('array', $data);
306
+	}
307
+
308
+	public function testGetActivePostsCount()
309
+	{
310
+		$testData = [
311
+			[
312
+				'id'      => rand(1, 100),
313
+				'display' => 1,
314
+			],
315
+			[
316
+				'id'      => rand(101, 200),
317
+				'display' => 1,
318
+			],
319
+		];
320
+
321
+		array_walk($testData, [$this, 'insertPostData']);
322
+
323
+		$repository = new MysqlPostRepository(self::$connection);
324
+		$data = $repository->getActivePostsCount();
325
+
326
+		$this->assertNotFalse($data);
327
+		$this->assertStringMatchesFormat('%d', $data);
328
+		$this->assertEquals(count($testData), $data);
329
+	}
330
+
331
+	public function testGetActivePostsCountInactive()
332
+	{
333
+		$testData = [
334
+			[
335
+				'id'      => rand(1, 100),
336
+				'display' => 1,
337
+			],
338
+			[
339
+				'id'      => rand(101, 200),
340
+				'display' => 1,
341
+			],
342
+			[
343
+				'id'      => rand(201, 300),
344
+				'display' => 0,
345
+			],
346
+		];
347
+
348
+		array_walk($testData, [$this, 'insertPostData']);
349
+
350
+		$repository = new MysqlPostRepository(self::$connection);
351
+		$data = $repository->getActivePostsCount();
352
+
353
+		$this->assertNotFalse($data);
354
+		$this->assertStringMatchesFormat('%d', $data);
355
+
356
+		$testData = array_filter($testData, function ($row) {
357
+			return ($row['display'] == 1);
358
+		});
359
+
360
+		$this->assertEquals(count($testData), $data);
361
+	}
362
+
363
+	public function testGetActivePostsCountFailure()
364
+	{
365
+		$repository = new MysqlPostRepository(self::$connection);
366
+		$data = $repository->getActivePostsCount();
367
+
368
+		$this->assertNotFalse($data);
369
+		$this->assertStringMatchesFormat('%d', $data);
370
+		$this->assertEquals('0', $data);
371
+	}
372
+
373
+	public function testGetActivePostsByTag()
374
+	{
375
+		$testPostData = [
376
+			[
377
+				'id'       => rand(1, 100),
378
+				'title'    => 'title one',
379
+				'path'     => 'path-one',
380
+				'category' => 'test category',
381
+				'date'     => (new DateTime('-1 day'))->format('Y-m-d H:i:s'),
382
+				'body'     => 'body one',
383
+				'display'  => 1,
384
+			],
385
+			[
386
+				'id'       => rand(101, 200),
387
+				'title'    => 'title two',
388
+				'path'     => 'path-two',
389
+				'category' => 'test category',
390
+				'date'     => (new DateTime())->format('Y-m-d H:i:s'),
391
+				'body'     => 'body one',
392
+				'display'  => 1,
393
+			],
394
+		];
395
+
396
+		$testTagData = [
397
+			'id' => rand(1, 100),
398
+		];
399
+
400
+		$testPTLinkData = [];
401
+		foreach ($testPostData as $testPostRow) {
402
+			array_push($testPTLinkData, [
403
+				'post_id' => $testPostRow['id'],
404
+				'tag_id' => $testTagData['id'],
405
+			]);
406
+		}
407
+
408
+		array_walk($testPostData, [$this, 'insertPostData']);
409
+		array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
410
+		$this->insertTagData($testTagData);
411
+
412
+		$repository = new MysqlPostRepository(self::$connection);
413
+		$data = $repository->getActivePostsByTag($testTagData['id']);
414
+
415
+		$this->assertNotFalse($data);
416
+		$this->assertInternalType('array', $data);
417
+		$this->assertCount(count($testPostData), $data);
418
+		foreach ($testPostData as $key => $testPostRow) {
419
+			$this->assertArrayHasKey('id', $data[$key]);
420
+			$this->assertEquals($testPostRow['id'], $data[$key]['id']);
421
+			$this->assertArrayHasKey('title', $data[$key]);
422
+			$this->assertEquals($testPostRow['title'], $data[$key]['title']);
423
+			$this->assertArrayHasKey('path', $data[$key]);
424
+			$this->assertEquals($testPostRow['path'], $data[$key]['path']);
425
+			$this->assertArrayHasKey('date', $data[$key]);
426
+			$this->assertEquals($testPostRow['date'], $data[$key]['date']);
427
+			$this->assertArrayHasKey('body', $data[$key]);
428
+			$this->assertEquals($testPostRow['body'], $data[$key]['body']);
429
+			$this->assertArrayHasKey('category', $data[$key]);
430
+			$this->assertEquals($testPostRow['category'], $data[$key]['category']);
431
+		}
432
+	}
433
+
434
+	public function testGetActivePostsByTagInactive()
435
+	{
436
+		$testPostData = [
437
+			[
438
+				'id'      => rand(1, 100),
439
+				'display' => 1,
440
+			],
441
+			[
442
+				'id'      => rand(101, 200),
443
+				'display' => 0,
444
+			],
445
+			[
446
+				'id'      => rand(201, 300),
447
+				'display' => 1,
448
+			],
449
+		];
450
+
451
+		$testTagData = [
452
+			'id' => rand(1, 100),
453
+		];
454
+
455
+		$testPTLinkData = [];
456
+		foreach ($testPostData as $testPostRow) {
457
+			array_push($testPTLinkData, [
458
+				'post_id' => $testPostRow['id'],
459
+				'tag_id' => $testTagData['id'],
460
+			]);
461
+		}
462
+
463
+		array_walk($testPostData, [$this, 'insertPostData']);
464
+		array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
465
+		$this->insertTagData($testTagData);
466
+
467
+		$repository = new MysqlPostRepository(self::$connection);
468
+		$data = $repository->getActivePostsByTag($testTagData['id']);
469
+
470
+		$this->assertNotFalse($data);
471
+		$this->assertInternalType('array', $data);
472
+
473
+		$testPostData = array_filter($testPostData, function ($row) {
474
+			return ($row['display'] == 1);
475
+		});
476
+
477
+		$this->assertCount(count($testPostData), $data);
478
+
479
+		$testIds = array_column($testPostData, 'ids');
480
+		$dataIds = array_column($data, 'ids');
481
+
482
+		$this->assertEmpty(array_merge(
483
+			array_diff($testIds, $dataIds),
484
+			array_diff($dataIds, $testIds)
485
+		));
486
+	}
487 487
  
488
-    public function testGetActivePostsByTagFailure()
489
-    {
490
-        $testTagData = [
491
-            'id' => rand(1, 100),
492
-        ];
493
-
494
-        $repository = new MysqlPostRepository(self::$connection);
495
-        $data = $repository->getActivePostsByTag($testTagData['id']);
496
-
497
-        $this->assertEmpty($data);
498
-        $this->assertInternalType('array', $data);
499
-    }
500
-
501
-    public function testGetActivePostsByTagRange()
502
-    {
503
-        $testPostData = [
504
-            [
505
-                'id'      => rand(1, 100),
506
-                'display' => 1,
507
-            ],
508
-            [
509
-                'id'      => rand(101, 200),
510
-                'display' => 1,
511
-            ],
512
-            [
513
-                'id'      => rand(201, 300),
514
-                'display' => 1,
515
-            ],
516
-        ];
517
-
518
-        $testTagData = [
519
-            'id' => rand(1, 100),
520
-        ];
521
-
522
-        $testPTLinkData = [];
523
-        foreach ($testPostData as $testPostRow) {
524
-            array_push($testPTLinkData, [
525
-                'post_id' => $testPostRow['id'],
526
-                'tag_id' => $testTagData['id'],
527
-            ]);
528
-        }
529
-
530
-        array_walk($testPostData, [$this, 'insertPostData']);
531
-        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
532
-        $this->insertTagData($testTagData);
533
-
534
-        $repository = new MysqlPostRepository(self::$connection);
535
-        $data = $repository->getActivePostsByTag($testTagData['id'], 2, 1);
536
-
537
-        $this->assertNotFalse($data);
538
-        $this->assertInternalType('array', $data);
539
-
540
-        $testPostData = array_slice($testPostData, 1, 2);
541
-
542
-        $this->assertCount(count($testPostData), $data);
543
-
544
-        $testIds = array_column($testPostData, 'ids');
545
-        $dataIds = array_column($data, 'ids');
546
-
547
-        $this->assertEmpty(array_merge(
548
-            array_diff($testIds, $dataIds),
549
-            array_diff($dataIds, $testIds)
550
-        ));
551
-    }
552
-
553
-    public function testGetActivePostsByTagRangeFailure()
554
-    {
555
-        $testPostData = [
556
-            [
557
-                'id'      => rand(1, 100),
558
-                'display' => 1,
559
-            ],
560
-            [
561
-                'id'      => rand(101, 200),
562
-                'display' => 1,
563
-            ],
564
-            [
565
-                'id'      => rand(201, 300),
566
-                'display' => 1,
567
-            ],
568
-        ];
569
-
570
-        $testTagData = [
571
-            'id' => rand(1, 100),
572
-        ];
573
-
574
-        $testPTLinkData = [];
575
-        foreach ($testPostData as $testPostRow) {
576
-            array_push($testPTLinkData, [
577
-                'post_id' => $testPostRow['id'],
578
-                'tag_id' => $testTagData['id'],
579
-            ]);
580
-        }
581
-
582
-        array_walk($testPostData, [$this, 'insertPostData']);
583
-        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
584
-        $this->insertTagData($testTagData);
585
-
586
-        $repository = new MysqlPostRepository(self::$connection);
587
-        $data = $repository->getActivePostsByTag($testTagData['id'], 1, 3);
588
-
589
-        $this->assertEmpty($data);
590
-        $this->assertInternalType('array', $data);
591
-    }
592
-
593
-    public function testGetActivePostsCountByTag()
594
-    {
595
-        $testPostData = [
596
-            [
597
-                'id'      => rand(1, 100),
598
-                'display' => 1,
599
-            ],
600
-            [
601
-                'id'      => rand(101, 200),
602
-                'display' => 1,
603
-            ],
604
-            [
605
-                'id'      => rand(201, 300),
606
-                'display' => 1,
607
-            ],
608
-        ];
609
-
610
-        $testTagData = [
611
-            'id' => rand(1, 100),
612
-        ];
613
-
614
-        $testPTLinkData = [];
615
-        foreach ($testPostData as $testPostRow) {
616
-            array_push($testPTLinkData, [
617
-                'post_id' => $testPostRow['id'],
618
-                'tag_id' => $testTagData['id'],
619
-            ]);
620
-        }
621
-
622
-        array_walk($testPostData, [$this, 'insertPostData']);
623
-        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
624
-        $this->insertTagData($testTagData);
625
-
626
-        $repository = new MysqlPostRepository(self::$connection);
627
-        $data = $repository->getActivePostsCountByTag($testTagData['id']);
628
-
629
-        $this->assertNotFalse($data);
630
-        $this->assertStringMatchesFormat('%d', $data);
631
-        $this->assertEquals(count($testPostData), $data);
632
-    }
633
-
634
-    public function testGetActivePostsCountByTagInactive()
635
-    {
636
-        $testPostData = [
637
-            [
638
-                'id'      => rand(1, 100),
639
-                'display' => 1,
640
-            ],
641
-            [
642
-                'id'      => rand(101, 200),
643
-                'display' => 0,
644
-            ],
645
-            [
646
-                'id'      => rand(201, 300),
647
-                'display' => 1,
648
-            ],
649
-        ];
650
-
651
-        $testTagData = [
652
-            'id' => rand(1, 100),
653
-        ];
654
-
655
-        $testPTLinkData = [];
656
-        foreach ($testPostData as $testPostRow) {
657
-            array_push($testPTLinkData, [
658
-                'post_id' => $testPostRow['id'],
659
-                'tag_id' => $testTagData['id'],
660
-            ]);
661
-        }
662
-
663
-        array_walk($testPostData, [$this, 'insertPostData']);
664
-        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
665
-        $this->insertTagData($testTagData);
666
-
667
-        $repository = new MysqlPostRepository(self::$connection);
668
-        $data = $repository->getActivePostsCountByTag($testTagData['id']);
669
-
670
-        $this->assertNotFalse($data);
671
-        $this->assertStringMatchesFormat('%d', $data);
672
-
673
-        $testPostData = array_filter($testPostData, function ($row) {
674
-            return ($row['display'] == 1);
675
-        });
676
-
677
-        $this->assertEquals(count($testPostData), $data);
678
-    }
488
+	public function testGetActivePostsByTagFailure()
489
+	{
490
+		$testTagData = [
491
+			'id' => rand(1, 100),
492
+		];
493
+
494
+		$repository = new MysqlPostRepository(self::$connection);
495
+		$data = $repository->getActivePostsByTag($testTagData['id']);
496
+
497
+		$this->assertEmpty($data);
498
+		$this->assertInternalType('array', $data);
499
+	}
500
+
501
+	public function testGetActivePostsByTagRange()
502
+	{
503
+		$testPostData = [
504
+			[
505
+				'id'      => rand(1, 100),
506
+				'display' => 1,
507
+			],
508
+			[
509
+				'id'      => rand(101, 200),
510
+				'display' => 1,
511
+			],
512
+			[
513
+				'id'      => rand(201, 300),
514
+				'display' => 1,
515
+			],
516
+		];
517
+
518
+		$testTagData = [
519
+			'id' => rand(1, 100),
520
+		];
521
+
522
+		$testPTLinkData = [];
523
+		foreach ($testPostData as $testPostRow) {
524
+			array_push($testPTLinkData, [
525
+				'post_id' => $testPostRow['id'],
526
+				'tag_id' => $testTagData['id'],
527
+			]);
528
+		}
529
+
530
+		array_walk($testPostData, [$this, 'insertPostData']);
531
+		array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
532
+		$this->insertTagData($testTagData);
533
+
534
+		$repository = new MysqlPostRepository(self::$connection);
535
+		$data = $repository->getActivePostsByTag($testTagData['id'], 2, 1);
536
+
537
+		$this->assertNotFalse($data);
538
+		$this->assertInternalType('array', $data);
539
+
540
+		$testPostData = array_slice($testPostData, 1, 2);
541
+
542
+		$this->assertCount(count($testPostData), $data);
543
+
544
+		$testIds = array_column($testPostData, 'ids');
545
+		$dataIds = array_column($data, 'ids');
546
+
547
+		$this->assertEmpty(array_merge(
548
+			array_diff($testIds, $dataIds),
549
+			array_diff($dataIds, $testIds)
550
+		));
551
+	}
552
+
553
+	public function testGetActivePostsByTagRangeFailure()
554
+	{
555
+		$testPostData = [
556
+			[
557
+				'id'      => rand(1, 100),
558
+				'display' => 1,
559
+			],
560
+			[
561
+				'id'      => rand(101, 200),
562
+				'display' => 1,
563
+			],
564
+			[
565
+				'id'      => rand(201, 300),
566
+				'display' => 1,
567
+			],
568
+		];
569
+
570
+		$testTagData = [
571
+			'id' => rand(1, 100),
572
+		];
573
+
574
+		$testPTLinkData = [];
575
+		foreach ($testPostData as $testPostRow) {
576
+			array_push($testPTLinkData, [
577
+				'post_id' => $testPostRow['id'],
578
+				'tag_id' => $testTagData['id'],
579
+			]);
580
+		}
581
+
582
+		array_walk($testPostData, [$this, 'insertPostData']);
583
+		array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
584
+		$this->insertTagData($testTagData);
585
+
586
+		$repository = new MysqlPostRepository(self::$connection);
587
+		$data = $repository->getActivePostsByTag($testTagData['id'], 1, 3);
588
+
589
+		$this->assertEmpty($data);
590
+		$this->assertInternalType('array', $data);
591
+	}
592
+
593
+	public function testGetActivePostsCountByTag()
594
+	{
595
+		$testPostData = [
596
+			[
597
+				'id'      => rand(1, 100),
598
+				'display' => 1,
599
+			],
600
+			[
601
+				'id'      => rand(101, 200),
602
+				'display' => 1,
603
+			],
604
+			[
605
+				'id'      => rand(201, 300),
606
+				'display' => 1,
607
+			],
608
+		];
609
+
610
+		$testTagData = [
611
+			'id' => rand(1, 100),
612
+		];
613
+
614
+		$testPTLinkData = [];
615
+		foreach ($testPostData as $testPostRow) {
616
+			array_push($testPTLinkData, [
617
+				'post_id' => $testPostRow['id'],
618
+				'tag_id' => $testTagData['id'],
619
+			]);
620
+		}
621
+
622
+		array_walk($testPostData, [$this, 'insertPostData']);
623
+		array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
624
+		$this->insertTagData($testTagData);
625
+
626
+		$repository = new MysqlPostRepository(self::$connection);
627
+		$data = $repository->getActivePostsCountByTag($testTagData['id']);
628
+
629
+		$this->assertNotFalse($data);
630
+		$this->assertStringMatchesFormat('%d', $data);
631
+		$this->assertEquals(count($testPostData), $data);
632
+	}
633
+
634
+	public function testGetActivePostsCountByTagInactive()
635
+	{
636
+		$testPostData = [
637
+			[
638
+				'id'      => rand(1, 100),
639
+				'display' => 1,
640
+			],
641
+			[
642
+				'id'      => rand(101, 200),
643
+				'display' => 0,
644
+			],
645
+			[
646
+				'id'      => rand(201, 300),
647
+				'display' => 1,
648
+			],
649
+		];
650
+
651
+		$testTagData = [
652
+			'id' => rand(1, 100),
653
+		];
654
+
655
+		$testPTLinkData = [];
656
+		foreach ($testPostData as $testPostRow) {
657
+			array_push($testPTLinkData, [
658
+				'post_id' => $testPostRow['id'],
659
+				'tag_id' => $testTagData['id'],
660
+			]);
661
+		}
662
+
663
+		array_walk($testPostData, [$this, 'insertPostData']);
664
+		array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
665
+		$this->insertTagData($testTagData);
666
+
667
+		$repository = new MysqlPostRepository(self::$connection);
668
+		$data = $repository->getActivePostsCountByTag($testTagData['id']);
669
+
670
+		$this->assertNotFalse($data);
671
+		$this->assertStringMatchesFormat('%d', $data);
672
+
673
+		$testPostData = array_filter($testPostData, function ($row) {
674
+			return ($row['display'] == 1);
675
+		});
676
+
677
+		$this->assertEquals(count($testPostData), $data);
678
+	}
679 679
  
680
-    public function testGetActivePostsCountByTagFailure()
681
-    {
682
-        $testTagData = [
683
-            'id' => rand(1, 100),
684
-        ];
680
+	public function testGetActivePostsCountByTagFailure()
681
+	{
682
+		$testTagData = [
683
+			'id' => rand(1, 100),
684
+		];
685 685
 
686
-        $this->insertTagData($testTagData);
686
+		$this->insertTagData($testTagData);
687 687
 
688
-        $repository = new MysqlPostRepository(self::$connection);
689
-        $data = $repository->getActivePostsCountByTag($testTagData['id']);
688
+		$repository = new MysqlPostRepository(self::$connection);
689
+		$data = $repository->getActivePostsCountByTag($testTagData['id']);
690 690
 
691
-        $this->assertNotFalse($data);
692
-        $this->assertStringMatchesFormat('%d', $data);
693
-        $this->assertEquals('0', $data);
694
-    }
691
+		$this->assertNotFalse($data);
692
+		$this->assertStringMatchesFormat('%d', $data);
693
+		$this->assertEquals('0', $data);
694
+	}
695 695
  
696
-    public function testGetActivePostsByCategory()
697
-    {
698
-        $testData = [
699
-            [
700
-                'id'       => rand(1, 100),
701
-                'title'    => 'title one',
702
-                'path'     => 'path-one',
703
-                'category' => 'test category',
704
-                'date'     => (new DateTime('-1 day'))->format('Y-m-d H:i:s'),
705
-                'body'     => 'body one',
706
-                'display'  => 1,
707
-            ],
708
-            [
709
-                'id'       => rand(101, 200),
710
-                'title'    => 'title two',
711
-                'path'     => 'path-two',
712
-                'category' => 'test category',
713
-                'date'     => (new DateTime())->format('Y-m-d H:i:s'),
714
-                'body'     => 'body one',
715
-                'display'  => 1,
716
-            ],
717
-        ];
718
-
719
-        array_walk($testData, [$this, 'insertPostData']);
720
-
721
-        $repository = new MysqlPostRepository(self::$connection);
722
-        $data = $repository->getActivePostsByCategory(reset($testData)['category']);
723
-
724
-        $this->assertNotFalse($data);
725
-        $this->assertInternalType('array', $data);
726
-        $this->assertCount(count($testData), $data);
727
-        foreach ($testData as $key => $testDataRow) {
728
-            $this->assertArrayHasKey('id', $data[$key]);
729
-            $this->assertEquals($testDataRow['id'], $data[$key]['id']);
730
-            $this->assertArrayHasKey('title', $data[$key]);
731
-            $this->assertEquals($testDataRow['title'], $data[$key]['title']);
732
-            $this->assertArrayHasKey('path', $data[$key]);
733
-            $this->assertEquals($testDataRow['path'], $data[$key]['path']);
734
-            $this->assertArrayHasKey('date', $data[$key]);
735
-            $this->assertEquals($testDataRow['date'], $data[$key]['date']);
736
-            $this->assertArrayHasKey('body', $data[$key]);
737
-            $this->assertEquals($testDataRow['body'], $data[$key]['body']);
738
-            $this->assertArrayHasKey('category', $data[$key]);
739
-            $this->assertEquals($testDataRow['category'], $data[$key]['category']);
740
-        }
741
-    }
742
-
743
-    public function testGetActivePostsByCategoryInactive()
744
-    {
745
-        $testData = [
746
-            [
747
-                'id'       => rand(1, 100),
748
-                'category' => 'test category',
749
-                'display'  => 1,
750
-            ],
751
-            [
752
-                'id'       => rand(101, 200),
753
-                'category' => 'test category',
754
-                'display'  => 1,
755
-            ],
756
-            [
757
-                'id'       => rand(201, 300),
758
-                'category' => 'test category',
759
-                'display'  => 0,
760
-            ],
761
-        ];
762
-
763
-        array_walk($testData, [$this, 'insertPostData']);
764
-
765
-        $repository = new MysqlPostRepository(self::$connection);
766
-        $data = $repository->getActivePostsByCategory(reset($testData)['category']);
767
-
768
-        $this->assertNotFalse($data);
769
-        $this->assertInternalType('array', $data);
770
-
771
-        $testData = array_filter($testData, function ($row) {
772
-            return ($row['display'] == 1);
773
-        });
774
-
775
-        $this->assertCount(count($testData), $data);
776
-
777
-        $testIds = array_column($testData, 'ids');
778
-        $dataIds = array_column($data, 'ids');
779
-
780
-        $this->assertEmpty(array_merge(
781
-            array_diff($testIds, $dataIds),
782
-            array_diff($dataIds, $testIds)
783
-        ));
784
-    }
696
+	public function testGetActivePostsByCategory()
697
+	{
698
+		$testData = [
699
+			[
700
+				'id'       => rand(1, 100),
701
+				'title'    => 'title one',
702
+				'path'     => 'path-one',
703
+				'category' => 'test category',
704
+				'date'     => (new DateTime('-1 day'))->format('Y-m-d H:i:s'),
705
+				'body'     => 'body one',
706
+				'display'  => 1,
707
+			],
708
+			[
709
+				'id'       => rand(101, 200),
710
+				'title'    => 'title two',
711
+				'path'     => 'path-two',
712
+				'category' => 'test category',
713
+				'date'     => (new DateTime())->format('Y-m-d H:i:s'),
714
+				'body'     => 'body one',
715
+				'display'  => 1,
716
+			],
717
+		];
718
+
719
+		array_walk($testData, [$this, 'insertPostData']);
720
+
721
+		$repository = new MysqlPostRepository(self::$connection);
722
+		$data = $repository->getActivePostsByCategory(reset($testData)['category']);
723
+
724
+		$this->assertNotFalse($data);
725
+		$this->assertInternalType('array', $data);
726
+		$this->assertCount(count($testData), $data);
727
+		foreach ($testData as $key => $testDataRow) {
728
+			$this->assertArrayHasKey('id', $data[$key]);
729
+			$this->assertEquals($testDataRow['id'], $data[$key]['id']);
730
+			$this->assertArrayHasKey('title', $data[$key]);
731
+			$this->assertEquals($testDataRow['title'], $data[$key]['title']);
732
+			$this->assertArrayHasKey('path', $data[$key]);
733
+			$this->assertEquals($testDataRow['path'], $data[$key]['path']);
734
+			$this->assertArrayHasKey('date', $data[$key]);
735
+			$this->assertEquals($testDataRow['date'], $data[$key]['date']);
736
+			$this->assertArrayHasKey('body', $data[$key]);
737
+			$this->assertEquals($testDataRow['body'], $data[$key]['body']);
738
+			$this->assertArrayHasKey('category', $data[$key]);
739
+			$this->assertEquals($testDataRow['category'], $data[$key]['category']);
740
+		}
741
+	}
742
+
743
+	public function testGetActivePostsByCategoryInactive()
744
+	{
745
+		$testData = [
746
+			[
747
+				'id'       => rand(1, 100),
748
+				'category' => 'test category',
749
+				'display'  => 1,
750
+			],
751
+			[
752
+				'id'       => rand(101, 200),
753
+				'category' => 'test category',
754
+				'display'  => 1,
755
+			],
756
+			[
757
+				'id'       => rand(201, 300),
758
+				'category' => 'test category',
759
+				'display'  => 0,
760
+			],
761
+		];
762
+
763
+		array_walk($testData, [$this, 'insertPostData']);
764
+
765
+		$repository = new MysqlPostRepository(self::$connection);
766
+		$data = $repository->getActivePostsByCategory(reset($testData)['category']);
767
+
768
+		$this->assertNotFalse($data);
769
+		$this->assertInternalType('array', $data);
770
+
771
+		$testData = array_filter($testData, function ($row) {
772
+			return ($row['display'] == 1);
773
+		});
774
+
775
+		$this->assertCount(count($testData), $data);
776
+
777
+		$testIds = array_column($testData, 'ids');
778
+		$dataIds = array_column($data, 'ids');
779
+
780
+		$this->assertEmpty(array_merge(
781
+			array_diff($testIds, $dataIds),
782
+			array_diff($dataIds, $testIds)
783
+		));
784
+	}
785 785
  
786
-    public function testGetActivePostsByCategoryFailure()
787
-    {
788
-        $repository = new MysqlPostRepository(self::$connection);
789
-        $data = $repository->getActivePostsByCategory('');
790
-
791
-        $this->assertEmpty($data);
792
-        $this->assertInternalType('array', $data);
793
-    }
794
-
795
-    public function testGetActivePostsByCategoryRange()
796
-    {
797
-        $testData = [
798
-            [
799
-                'id'       => rand(1, 100),
800
-                'category' => 'test category',
801
-                'display'  => 1,
802
-            ],
803
-            [
804
-                'id'       => rand(101, 200),
805
-                'category' => 'test category',
806
-                'display'  => 1,
807
-            ],
808
-            [
809
-                'id'       => rand(201, 300),
810
-                'category' => 'test category',
811
-                'display'  => 1,
812
-            ],
813
-        ];
814
-
815
-        array_walk($testData, [$this, 'insertPostData']);
816
-
817
-        $repository = new MysqlPostRepository(self::$connection);
818
-        $data = $repository->getActivePostsByCategory(reset($testData)['category'], 2, 1);
819
-
820
-        $this->assertNotFalse($data);
821
-        $this->assertInternalType('array', $data);
822
-
823
-        $testData = array_slice($testData, 1, 2);
824
-
825
-        $this->assertCount(count($testData), $data);
826
-
827
-        $testIds = array_column($testData, 'ids');
828
-        $dataIds = array_column($data, 'ids');
829
-
830
-        $this->assertEmpty(array_merge(
831
-            array_diff($testIds, $dataIds),
832
-            array_diff($dataIds, $testIds)
833
-        ));
834
-    }
835
-
836
-    public function testGetActivePostsByCategoryRangeFailure()
837
-    {
838
-        $testData = [
839
-            [
840
-                'id'       => rand(1, 100),
841
-                'category' => 'test category',
842
-                'display'  => 1,
843
-            ],
844
-            [
845
-                'id'       => rand(101, 200),
846
-                'category' => 'test category',
847
-                'display'  => 1,
848
-            ],
849
-            [
850
-                'id'       => rand(201, 300),
851
-                'category' => 'test category',
852
-                'display'  => 1,
853
-            ],
854
-        ];
855
-
856
-        array_walk($testData, [$this, 'insertPostData']);
857
-
858
-        $repository = new MysqlPostRepository(self::$connection);
859
-        $data = $repository->getActivePostsByCategory(reset($testData)['category'], 1, 3);
860
-
861
-        $this->assertEmpty($data);
862
-        $this->assertInternalType('array', $data);
863
-    }
864
-
865
-    public function testGetActivePostsCountByCategory()
866
-    {
867
-        $testData = [
868
-            [
869
-                'id'       => rand(1, 100),
870
-                'category' => 'test category',
871
-                'display'  => 1,
872
-            ],
873
-            [
874
-                'id'       => rand(101, 200),
875
-                'category' => 'test category',
876
-                'display'  => 1,
877
-            ],
878
-            [
879
-                'id'       => rand(201, 300),
880
-                'category' => 'test category',
881
-                'display'  => 1,
882
-            ],
883
-        ];
884
-
885
-        array_walk($testData, [$this, 'insertPostData']);
886
-
887
-        $repository = new MysqlPostRepository(self::$connection);
888
-        $data = $repository->getActivePostsCountByCategory(reset($testData)['category']);
889
-
890
-        $this->assertNotFalse($data);
891
-        $this->assertStringMatchesFormat('%d', $data);
892
-        $this->assertEquals(count($testData), $data);
893
-    }
894
-
895
-    public function testGetActivePostsCountByCategoryInactive()
896
-    {
897
-        $testData = [
898
-            [
899
-                'id'       => rand(1, 100),
900
-                'category' => 'test category',
901
-                'display'  => 0,
902
-            ],
903
-            [
904
-                'id'       => rand(101, 200),
905
-                'category' => 'test category',
906
-                'display'  => 1,
907
-            ],
908
-            [
909
-                'id'       => rand(201, 300),
910
-                'category' => 'test category',
911
-                'display'  => 1,
912
-            ],
913
-        ];
914
-
915
-        array_walk($testData, [$this, 'insertPostData']);
916
-
917
-        $repository = new MysqlPostRepository(self::$connection);
918
-        $data = $repository->getActivePostsCountByCategory(reset($testData)['category']);
919
-
920
-        $this->assertNotFalse($data);
921
-        $this->assertStringMatchesFormat('%d', $data);
922
-
923
-        $testData = array_filter($testData, function ($row) {
924
-            return ($row['display'] == 1);
925
-        });
926
-
927
-        $this->assertEquals(count($testData), $data);
928
-    }
929
-
930
-    public function testGetActivePostsCountByCategoryFailure()
931
-    {
932
-        $repository = new MysqlPostRepository(self::$connection);
933
-        $data = $repository->getActivePostsCountByCategory('');
934
-
935
-        $this->assertNotFalse($data);
936
-        $this->assertStringMatchesFormat('%d', $data);
937
-        $this->assertEquals('0', $data);
938
-    }
939
-
940
-    public function testGetActivePostsByRelatedTags()
941
-    {
942
-        $testPostData = [
943
-            [
944
-                'id'       => rand(1, 100),
945
-                'title'    => 'title one',
946
-                'path'     => 'path-one',
947
-                'category' => 'test category',
948
-                'date'     => (new DateTime('-1 day'))->format('Y-m-d H:i:s'),
949
-                'body'     => 'body one',
950
-                'display'  => 1,
951
-            ],
952
-            [
953
-                'id'       => rand(101, 200),
954
-                'title'    => 'title two',
955
-                'path'     => 'path-two',
956
-                'category' => 'test category',
957
-                'date'     => (new DateTime('-2 days'))->format('Y-m-d H:i:s'),
958
-                'body'     => 'body two',
959
-                'display'  => 1,
960
-            ],
961
-            [
962
-                'id'       => rand(201, 300),
963
-                'title'    => 'title three',
964
-                'path'     => 'path-three',
965
-                'category' => 'test category',
966
-                'date'     => (new DateTime('-3 days'))->format('Y-m-d H:i:s'),
967
-                'body'     => 'body three',
968
-                'display'  => 1,
969
-            ],
970
-        ];
971
-
972
-        $testTagData = [
973
-            'id' => rand(1, 100),
974
-        ];
975
-
976
-        $testPTLinkData = [];
977
-        foreach ($testPostData as $testPostRow) {
978
-            array_push($testPTLinkData, [
979
-                'post_id' => $testPostRow['id'],
980
-                'tag_id' => $testTagData['id'],
981
-            ]);
982
-        }
983
-
984
-        array_walk($testPostData, [$this, 'insertPostData']);
985
-        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
986
-        $this->insertTagData($testTagData);
987
-
988
-        $repository = new MysqlPostRepository(self::$connection);
989
-        $data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id']);
990
-
991
-        $this->assertNotFalse($data);
992
-        $this->assertInternalType('array', $data);
993
-
994
-        array_shift($testPostData);
995
-
996
-        $this->assertCount(count($testPostData), $data);
997
-        foreach ($testPostData as $key => $testPostRow) {
998
-            $this->assertArrayHasKey('id', $data[$key]);
999
-            $this->assertEquals($testPostRow['id'], $data[$key]['id']);
1000
-            $this->assertArrayHasKey('title', $data[$key]);
1001
-            $this->assertEquals($testPostRow['title'], $data[$key]['title']);
1002
-            $this->assertArrayHasKey('path', $data[$key]);
1003
-            $this->assertEquals($testPostRow['path'], $data[$key]['path']);
1004
-            $this->assertArrayHasKey('date', $data[$key]);
1005
-            $this->assertEquals($testPostRow['date'], $data[$key]['date']);
1006
-            $this->assertArrayHasKey('body', $data[$key]);
1007
-            $this->assertEquals($testPostRow['body'], $data[$key]['body']);
1008
-            $this->assertArrayHasKey('category', $data[$key]);
1009
-            $this->assertEquals($testPostRow['category'], $data[$key]['category']);
1010
-            $this->assertArrayHasKey('count', $data[$key]);
1011
-            $this->assertEquals(count($testTagData), $data[$key]['count']);
1012
-        }
1013
-    }
1014
-
1015
-    public function testGetActivePostsByRelatedTagsLimit()
1016
-    {
1017
-        $testPostData = [
1018
-            [
1019
-                'id'      => rand(1, 100),
1020
-                'display' => 1,
1021
-            ],
1022
-            [
1023
-                'id'      => rand(101, 200),
1024
-                'display' => 1,
1025
-            ],
1026
-            [
1027
-                'id'      => rand(201, 300),
1028
-                'display' => 1,
1029
-            ],
1030
-        ];
1031
-
1032
-        $testTagData = [
1033
-            'id' => rand(1, 100),
1034
-        ];
1035
-
1036
-        $testPTLinkData = [];
1037
-        foreach ($testPostData as $testPostRow) {
1038
-            array_push($testPTLinkData, [
1039
-                'post_id' => $testPostRow['id'],
1040
-                'tag_id' => $testTagData['id'],
1041
-            ]);
1042
-        }
1043
-
1044
-        array_walk($testPostData, [$this, 'insertPostData']);
1045
-        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
1046
-        $this->insertTagData($testTagData);
1047
-
1048
-        $repository = new MysqlPostRepository(self::$connection);
1049
-        $data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id'], 1);
1050
-
1051
-        $this->assertNotFalse($data);
1052
-        $this->assertInternalType('array', $data);
1053
-
1054
-        $testPostData = array_slice($testPostData, 1, 1);
1055
-
1056
-        $this->assertCount(count($testPostData), $data);
1057
-
1058
-        $testIds = array_column($testPostData, 'ids');
1059
-        $dataIds = array_column($data, 'ids');
1060
-
1061
-        $this->assertEmpty(array_merge(
1062
-            array_diff($testIds, $dataIds),
1063
-            array_diff($dataIds, $testIds)
1064
-        ));
1065
-    }
786
+	public function testGetActivePostsByCategoryFailure()
787
+	{
788
+		$repository = new MysqlPostRepository(self::$connection);
789
+		$data = $repository->getActivePostsByCategory('');
790
+
791
+		$this->assertEmpty($data);
792
+		$this->assertInternalType('array', $data);
793
+	}
794
+
795
+	public function testGetActivePostsByCategoryRange()
796
+	{
797
+		$testData = [
798
+			[
799
+				'id'       => rand(1, 100),
800
+				'category' => 'test category',
801
+				'display'  => 1,
802
+			],
803
+			[
804
+				'id'       => rand(101, 200),
805
+				'category' => 'test category',
806
+				'display'  => 1,
807
+			],
808
+			[
809
+				'id'       => rand(201, 300),
810
+				'category' => 'test category',
811
+				'display'  => 1,
812
+			],
813
+		];
814
+
815
+		array_walk($testData, [$this, 'insertPostData']);
816
+
817
+		$repository = new MysqlPostRepository(self::$connection);
818
+		$data = $repository->getActivePostsByCategory(reset($testData)['category'], 2, 1);
819
+
820
+		$this->assertNotFalse($data);
821
+		$this->assertInternalType('array', $data);
822
+
823
+		$testData = array_slice($testData, 1, 2);
824
+
825
+		$this->assertCount(count($testData), $data);
826
+
827
+		$testIds = array_column($testData, 'ids');
828
+		$dataIds = array_column($data, 'ids');
829
+
830
+		$this->assertEmpty(array_merge(
831
+			array_diff($testIds, $dataIds),
832
+			array_diff($dataIds, $testIds)
833
+		));
834
+	}
835
+
836
+	public function testGetActivePostsByCategoryRangeFailure()
837
+	{
838
+		$testData = [
839
+			[
840
+				'id'       => rand(1, 100),
841
+				'category' => 'test category',
842
+				'display'  => 1,
843
+			],
844
+			[
845
+				'id'       => rand(101, 200),
846
+				'category' => 'test category',
847
+				'display'  => 1,
848
+			],
849
+			[
850
+				'id'       => rand(201, 300),
851
+				'category' => 'test category',
852
+				'display'  => 1,
853
+			],
854
+		];
855
+
856
+		array_walk($testData, [$this, 'insertPostData']);
857
+
858
+		$repository = new MysqlPostRepository(self::$connection);
859
+		$data = $repository->getActivePostsByCategory(reset($testData)['category'], 1, 3);
860
+
861
+		$this->assertEmpty($data);
862
+		$this->assertInternalType('array', $data);
863
+	}
864
+
865
+	public function testGetActivePostsCountByCategory()
866
+	{
867
+		$testData = [
868
+			[
869
+				'id'       => rand(1, 100),
870
+				'category' => 'test category',
871
+				'display'  => 1,
872
+			],
873
+			[
874
+				'id'       => rand(101, 200),
875
+				'category' => 'test category',
876
+				'display'  => 1,
877
+			],
878
+			[
879
+				'id'       => rand(201, 300),
880
+				'category' => 'test category',
881
+				'display'  => 1,
882
+			],
883
+		];
884
+
885
+		array_walk($testData, [$this, 'insertPostData']);
886
+
887
+		$repository = new MysqlPostRepository(self::$connection);
888
+		$data = $repository->getActivePostsCountByCategory(reset($testData)['category']);
889
+
890
+		$this->assertNotFalse($data);
891
+		$this->assertStringMatchesFormat('%d', $data);
892
+		$this->assertEquals(count($testData), $data);
893
+	}
894
+
895
+	public function testGetActivePostsCountByCategoryInactive()
896
+	{
897
+		$testData = [
898
+			[
899
+				'id'       => rand(1, 100),
900
+				'category' => 'test category',
901
+				'display'  => 0,
902
+			],
903
+			[
904
+				'id'       => rand(101, 200),
905
+				'category' => 'test category',
906
+				'display'  => 1,
907
+			],
908
+			[
909
+				'id'       => rand(201, 300),
910
+				'category' => 'test category',
911
+				'display'  => 1,
912
+			],
913
+		];
914
+
915
+		array_walk($testData, [$this, 'insertPostData']);
916
+
917
+		$repository = new MysqlPostRepository(self::$connection);
918
+		$data = $repository->getActivePostsCountByCategory(reset($testData)['category']);
919
+
920
+		$this->assertNotFalse($data);
921
+		$this->assertStringMatchesFormat('%d', $data);
922
+
923
+		$testData = array_filter($testData, function ($row) {
924
+			return ($row['display'] == 1);
925
+		});
926
+
927
+		$this->assertEquals(count($testData), $data);
928
+	}
929
+
930
+	public function testGetActivePostsCountByCategoryFailure()
931
+	{
932
+		$repository = new MysqlPostRepository(self::$connection);
933
+		$data = $repository->getActivePostsCountByCategory('');
934
+
935
+		$this->assertNotFalse($data);
936
+		$this->assertStringMatchesFormat('%d', $data);
937
+		$this->assertEquals('0', $data);
938
+	}
939
+
940
+	public function testGetActivePostsByRelatedTags()
941
+	{
942
+		$testPostData = [
943
+			[
944
+				'id'       => rand(1, 100),
945
+				'title'    => 'title one',
946
+				'path'     => 'path-one',
947
+				'category' => 'test category',
948
+				'date'     => (new DateTime('-1 day'))->format('Y-m-d H:i:s'),
949
+				'body'     => 'body one',
950
+				'display'  => 1,
951
+			],
952
+			[
953
+				'id'       => rand(101, 200),
954
+				'title'    => 'title two',
955
+				'path'     => 'path-two',
956
+				'category' => 'test category',
957
+				'date'     => (new DateTime('-2 days'))->format('Y-m-d H:i:s'),
958
+				'body'     => 'body two',
959
+				'display'  => 1,
960
+			],
961
+			[
962
+				'id'       => rand(201, 300),
963
+				'title'    => 'title three',
964
+				'path'     => 'path-three',
965
+				'category' => 'test category',
966
+				'date'     => (new DateTime('-3 days'))->format('Y-m-d H:i:s'),
967
+				'body'     => 'body three',
968
+				'display'  => 1,
969
+			],
970
+		];
971
+
972
+		$testTagData = [
973
+			'id' => rand(1, 100),
974
+		];
975
+
976
+		$testPTLinkData = [];
977
+		foreach ($testPostData as $testPostRow) {
978
+			array_push($testPTLinkData, [
979
+				'post_id' => $testPostRow['id'],
980
+				'tag_id' => $testTagData['id'],
981
+			]);
982
+		}
983
+
984
+		array_walk($testPostData, [$this, 'insertPostData']);
985
+		array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
986
+		$this->insertTagData($testTagData);
987
+
988
+		$repository = new MysqlPostRepository(self::$connection);
989
+		$data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id']);
990
+
991
+		$this->assertNotFalse($data);
992
+		$this->assertInternalType('array', $data);
993
+
994
+		array_shift($testPostData);
995
+
996
+		$this->assertCount(count($testPostData), $data);
997
+		foreach ($testPostData as $key => $testPostRow) {
998
+			$this->assertArrayHasKey('id', $data[$key]);
999
+			$this->assertEquals($testPostRow['id'], $data[$key]['id']);
1000
+			$this->assertArrayHasKey('title', $data[$key]);
1001
+			$this->assertEquals($testPostRow['title'], $data[$key]['title']);
1002
+			$this->assertArrayHasKey('path', $data[$key]);
1003
+			$this->assertEquals($testPostRow['path'], $data[$key]['path']);
1004
+			$this->assertArrayHasKey('date', $data[$key]);
1005
+			$this->assertEquals($testPostRow['date'], $data[$key]['date']);
1006
+			$this->assertArrayHasKey('body', $data[$key]);
1007
+			$this->assertEquals($testPostRow['body'], $data[$key]['body']);
1008
+			$this->assertArrayHasKey('category', $data[$key]);
1009
+			$this->assertEquals($testPostRow['category'], $data[$key]['category']);
1010
+			$this->assertArrayHasKey('count', $data[$key]);
1011
+			$this->assertEquals(count($testTagData), $data[$key]['count']);
1012
+		}
1013
+	}
1014
+
1015
+	public function testGetActivePostsByRelatedTagsLimit()
1016
+	{
1017
+		$testPostData = [
1018
+			[
1019
+				'id'      => rand(1, 100),
1020
+				'display' => 1,
1021
+			],
1022
+			[
1023
+				'id'      => rand(101, 200),
1024
+				'display' => 1,
1025
+			],
1026
+			[
1027
+				'id'      => rand(201, 300),
1028
+				'display' => 1,
1029
+			],
1030
+		];
1031
+
1032
+		$testTagData = [
1033
+			'id' => rand(1, 100),
1034
+		];
1035
+
1036
+		$testPTLinkData = [];
1037
+		foreach ($testPostData as $testPostRow) {
1038
+			array_push($testPTLinkData, [
1039
+				'post_id' => $testPostRow['id'],
1040
+				'tag_id' => $testTagData['id'],
1041
+			]);
1042
+		}
1043
+
1044
+		array_walk($testPostData, [$this, 'insertPostData']);
1045
+		array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
1046
+		$this->insertTagData($testTagData);
1047
+
1048
+		$repository = new MysqlPostRepository(self::$connection);
1049
+		$data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id'], 1);
1050
+
1051
+		$this->assertNotFalse($data);
1052
+		$this->assertInternalType('array', $data);
1053
+
1054
+		$testPostData = array_slice($testPostData, 1, 1);
1055
+
1056
+		$this->assertCount(count($testPostData), $data);
1057
+
1058
+		$testIds = array_column($testPostData, 'ids');
1059
+		$dataIds = array_column($data, 'ids');
1060
+
1061
+		$this->assertEmpty(array_merge(
1062
+			array_diff($testIds, $dataIds),
1063
+			array_diff($dataIds, $testIds)
1064
+		));
1065
+	}
1066 1066
  
1067
-    public function testGetActivePostsByRelatedTagsInactive()
1068
-    {
1069
-        $testPostData = [
1070
-            [
1071
-                'id'      => rand(1, 100),
1072
-                'display' => 1,
1073
-            ],
1074
-            [
1075
-                'id'      => rand(101, 200),
1076
-                'display' => 1,
1077
-            ],
1078
-            [
1079
-                'id'      => rand(201, 300),
1080
-                'display' => 0,
1081
-            ],
1082
-            [
1083
-                'id'      => rand(301, 400),
1084
-                'display' => 1,
1085
-            ],
1086
-        ];
1087
-
1088
-        $testTagData = [
1089
-            'id' => rand(1, 100),
1090
-        ];
1091
-
1092
-        $testPTLinkData = [];
1093
-        foreach ($testPostData as $testPostRow) {
1094
-            array_push($testPTLinkData, [
1095
-                'post_id' => $testPostRow['id'],
1096
-                'tag_id' => $testTagData['id'],
1097
-            ]);
1098
-        }
1099
-
1100
-        array_walk($testPostData, [$this, 'insertPostData']);
1101
-        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
1102
-        $this->insertTagData($testTagData);
1103
-
1104
-        $repository = new MysqlPostRepository(self::$connection);
1105
-        $data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id']);
1106
-
1107
-        $this->assertNotFalse($data);
1108
-        $this->assertInternalType('array', $data);
1109
-
1110
-        array_shift($testPostData);
1111
-        $testPostData = array_filter($testPostData, function ($row) {
1112
-            return ($row['display'] == 1);
1113
-        });
1114
-
1115
-        $this->assertCount(count($testPostData), $data);
1116
-
1117
-        $testIds = array_column($testPostData, 'ids');
1118
-        $dataIds = array_column($data, 'ids');
1119
-
1120
-        $this->assertEmpty(array_merge(
1121
-            array_diff($testIds, $dataIds),
1122
-            array_diff($dataIds, $testIds)
1123
-        ));
1124
-    }
1067
+	public function testGetActivePostsByRelatedTagsInactive()
1068
+	{
1069
+		$testPostData = [
1070
+			[
1071
+				'id'      => rand(1, 100),
1072
+				'display' => 1,
1073
+			],
1074
+			[
1075
+				'id'      => rand(101, 200),
1076
+				'display' => 1,
1077
+			],
1078
+			[
1079
+				'id'      => rand(201, 300),
1080
+				'display' => 0,
1081
+			],
1082
+			[
1083
+				'id'      => rand(301, 400),
1084
+				'display' => 1,
1085
+			],
1086
+		];
1087
+
1088
+		$testTagData = [
1089
+			'id' => rand(1, 100),
1090
+		];
1091
+
1092
+		$testPTLinkData = [];
1093
+		foreach ($testPostData as $testPostRow) {
1094
+			array_push($testPTLinkData, [
1095
+				'post_id' => $testPostRow['id'],
1096
+				'tag_id' => $testTagData['id'],
1097
+			]);
1098
+		}
1099
+
1100
+		array_walk($testPostData, [$this, 'insertPostData']);
1101
+		array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
1102
+		$this->insertTagData($testTagData);
1103
+
1104
+		$repository = new MysqlPostRepository(self::$connection);
1105
+		$data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id']);
1106
+
1107
+		$this->assertNotFalse($data);
1108
+		$this->assertInternalType('array', $data);
1109
+
1110
+		array_shift($testPostData);
1111
+		$testPostData = array_filter($testPostData, function ($row) {
1112
+			return ($row['display'] == 1);
1113
+		});
1114
+
1115
+		$this->assertCount(count($testPostData), $data);
1116
+
1117
+		$testIds = array_column($testPostData, 'ids');
1118
+		$dataIds = array_column($data, 'ids');
1119
+
1120
+		$this->assertEmpty(array_merge(
1121
+			array_diff($testIds, $dataIds),
1122
+			array_diff($dataIds, $testIds)
1123
+		));
1124
+	}
1125 1125
  
1126
-    public function testGetActivePostsByRelatedTagsExcludeSeries()
1127
-    {
1128
-        $testPostData = [
1129
-            [
1130
-                'id'      => rand(1, 100),
1131
-                'display' => 1,
1132
-            ],
1133
-            [
1134
-                'id'      => rand(101, 200),
1135
-                'display' => 1,
1136
-            ],
1137
-            [
1138
-                'id'      => rand(201, 300),
1139
-                'display' => 1,
1140
-            ],
1141
-            [
1142
-                'id'      => rand(301, 400),
1143
-                'display' => 1,
1144
-            ],
1145
-        ];
1146
-
1147
-        $testTagData = [
1148
-            'id' => rand(1, 100),
1149
-        ];
1150
-
1151
-        $testPTLinkData = [];
1152
-        foreach ($testPostData as $testPostRow) {
1153
-            array_push($testPTLinkData, [
1154
-                'post_id' => $testPostRow['id'],
1155
-                'tag_id' => $testTagData['id'],
1156
-            ]);
1157
-        }
1158
-
1159
-        $seriesPostKey = rand(1, 3);
1160
-        $testSeriesPostData = [
1161
-            [
1162
-                'series' => 1,
1163
-                'post' => reset($testPostData)['id'],
1164
-            ],
1165
-            [
1166
-                'series' => 1,
1167
-                'post' => $testPostData[$seriesPostKey]['id'],
1168
-            ],
1169
-        ];
1170
-
1171
-        array_walk($testPostData, [$this, 'insertPostData']);
1172
-        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
1173
-        array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
1174
-        $this->insertTagData($testTagData);
1175
-
1176
-        $repository = new MysqlPostRepository(self::$connection);
1177
-        $data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id']);
1178
-
1179
-        $this->assertNotFalse($data);
1180
-        $this->assertInternalType('array', $data);
1181
-
1182
-        array_shift($testPostData);
1183
-        $testPostData = array_filter($testPostData, function ($row) use ($testSeriesPostData) {
1184
-            return (!in_array($row['id'], array_column($testSeriesPostData, 'post')));
1185
-        });
1186
-
1187
-        $this->assertCount(count($testPostData), $data);
1188
-
1189
-        $testIds = array_column($testPostData, 'ids');
1190
-        $dataIds = array_column($data, 'ids');
1191
-
1192
-        $this->assertEmpty(array_merge(
1193
-            array_diff($testIds, $dataIds),
1194
-            array_diff($dataIds, $testIds)
1195
-        ));
1196
-    }
1197
-
1198
-    public function testGetActivePostsByRelatedTagsFailure()
1199
-    {
1200
-        $repository = new MysqlPostRepository(self::$connection);
1201
-        $data = $repository->getActivePostsByRelatedTags('');
1202
-
1203
-        $this->assertEmpty($data);
1204
-        $this->assertInternalType('array', $data);
1205
-    }
1206
-
1207
-    protected function insertPostData(array $data)
1208
-    {
1209
-        $defaultData = [
1210
-            'id' => null,
1211
-            'title' => '',
1212
-            'path' => '',
1213
-            'category' => '',
1214
-            'date' => '',
1215
-            'body' => '',
1216
-            'display' => 0,
1217
-        ];
1218
-
1219
-        $data = array_merge($defaultData, $data);
1220
-
1221
-        return self::$connection->getDefault()->perform("
1126
+	public function testGetActivePostsByRelatedTagsExcludeSeries()
1127
+	{
1128
+		$testPostData = [
1129
+			[
1130
+				'id'      => rand(1, 100),
1131
+				'display' => 1,
1132
+			],
1133
+			[
1134
+				'id'      => rand(101, 200),
1135
+				'display' => 1,
1136
+			],
1137
+			[
1138
+				'id'      => rand(201, 300),
1139
+				'display' => 1,
1140
+			],
1141
+			[
1142
+				'id'      => rand(301, 400),
1143
+				'display' => 1,
1144
+			],
1145
+		];
1146
+
1147
+		$testTagData = [
1148
+			'id' => rand(1, 100),
1149
+		];
1150
+
1151
+		$testPTLinkData = [];
1152
+		foreach ($testPostData as $testPostRow) {
1153
+			array_push($testPTLinkData, [
1154
+				'post_id' => $testPostRow['id'],
1155
+				'tag_id' => $testTagData['id'],
1156
+			]);
1157
+		}
1158
+
1159
+		$seriesPostKey = rand(1, 3);
1160
+		$testSeriesPostData = [
1161
+			[
1162
+				'series' => 1,
1163
+				'post' => reset($testPostData)['id'],
1164
+			],
1165
+			[
1166
+				'series' => 1,
1167
+				'post' => $testPostData[$seriesPostKey]['id'],
1168
+			],
1169
+		];
1170
+
1171
+		array_walk($testPostData, [$this, 'insertPostData']);
1172
+		array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
1173
+		array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
1174
+		$this->insertTagData($testTagData);
1175
+
1176
+		$repository = new MysqlPostRepository(self::$connection);
1177
+		$data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id']);
1178
+
1179
+		$this->assertNotFalse($data);
1180
+		$this->assertInternalType('array', $data);
1181
+
1182
+		array_shift($testPostData);
1183
+		$testPostData = array_filter($testPostData, function ($row) use ($testSeriesPostData) {
1184
+			return (!in_array($row['id'], array_column($testSeriesPostData, 'post')));
1185
+		});
1186
+
1187
+		$this->assertCount(count($testPostData), $data);
1188
+
1189
+		$testIds = array_column($testPostData, 'ids');
1190
+		$dataIds = array_column($data, 'ids');
1191
+
1192
+		$this->assertEmpty(array_merge(
1193
+			array_diff($testIds, $dataIds),
1194
+			array_diff($dataIds, $testIds)
1195
+		));
1196
+	}
1197
+
1198
+	public function testGetActivePostsByRelatedTagsFailure()
1199
+	{
1200
+		$repository = new MysqlPostRepository(self::$connection);
1201
+		$data = $repository->getActivePostsByRelatedTags('');
1202
+
1203
+		$this->assertEmpty($data);
1204
+		$this->assertInternalType('array', $data);
1205
+	}
1206
+
1207
+	protected function insertPostData(array $data)
1208
+	{
1209
+		$defaultData = [
1210
+			'id' => null,
1211
+			'title' => '',
1212
+			'path' => '',
1213
+			'category' => '',
1214
+			'date' => '',
1215
+			'body' => '',
1216
+			'display' => 0,
1217
+		];
1218
+
1219
+		$data = array_merge($defaultData, $data);
1220
+
1221
+		return self::$connection->getDefault()->perform("
1222 1222
             INSERT INTO `jpemeric_blog`.`post`
1223 1223
                 (id, title, path, category, date, body, display)
1224 1224
             VALUES
1225 1225
                 (:id, :title, :path, :category, :date, :body, :display)",
1226
-            $data
1227
-        );
1228
-    }
1226
+			$data
1227
+		);
1228
+	}
1229 1229
 
1230
-    protected function insertPTLinkData(array $data)
1231
-    {
1232
-        $defaultData = [
1233
-            'post' => null,
1234
-            'tag' => null,
1235
-        ];
1230
+	protected function insertPTLinkData(array $data)
1231
+	{
1232
+		$defaultData = [
1233
+			'post' => null,
1234
+			'tag' => null,
1235
+		];
1236 1236
 
1237
-        $data = array_merge($defaultData, $data);
1237
+		$data = array_merge($defaultData, $data);
1238 1238
 
1239
-        return self::$connection->getDefault()->perform("
1239
+		return self::$connection->getDefault()->perform("
1240 1240
             INSERT INTO `jpemeric_blog`.`ptlink`
1241 1241
                 (post_id, tag_id)
1242 1242
             VALUES
1243 1243
                 (:post_id, :tag_id)",
1244
-            $data
1245
-        );
1246
-    }
1244
+			$data
1245
+		);
1246
+	}
1247 1247
 
1248
-    protected function insertSeriesPostData(array $data)
1249
-    {
1250
-        $defaultData = [
1251
-            'series' => '',
1252
-            'post' => '',
1253
-            'order' => 0,
1254
-        ];
1248
+	protected function insertSeriesPostData(array $data)
1249
+	{
1250
+		$defaultData = [
1251
+			'series' => '',
1252
+			'post' => '',
1253
+			'order' => 0,
1254
+		];
1255 1255
 
1256
-        $data = array_merge($defaultData, $data);
1256
+		$data = array_merge($defaultData, $data);
1257 1257
 
1258
-        return self::$connection->getDefault()->perform("
1258
+		return self::$connection->getDefault()->perform("
1259 1259
             INSERT INTO `jpemeric_blog`.`series_post`
1260 1260
                 (series, post, `order`)
1261 1261
             VALUES
1262 1262
                 (:series, :post, :order)",
1263
-            $data
1264
-        );
1265
-    }
1263
+			$data
1264
+		);
1265
+	}
1266 1266
 
1267
-    protected function insertTagData(array $data)
1268
-    {
1269
-        $defaultData = [
1270
-            'id' => null,
1271
-            'tag' => '',
1272
-        ];
1267
+	protected function insertTagData(array $data)
1268
+	{
1269
+		$defaultData = [
1270
+			'id' => null,
1271
+			'tag' => '',
1272
+		];
1273 1273
 
1274
-        $data = array_merge($defaultData, $data);
1274
+		$data = array_merge($defaultData, $data);
1275 1275
 
1276
-        return self::$connection->getDefault()->perform("
1276
+		return self::$connection->getDefault()->perform("
1277 1277
             INSERT INTO `jpemeric_blog`.`tag`
1278 1278
                 (id, tag)
1279 1279
             VALUES
1280 1280
                 (:id, :tag)",
1281
-            $data
1282
-        );
1283
-    }
1284
-
1285
-    protected function tearDown()
1286
-    {
1287
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`post`");
1288
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`ptlink`");
1289
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series_post`");
1290
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`tag`");
1291
-    }
1292
-
1293
-    public static function tearDownAfterClass()
1294
-    {
1295
-        self::$connection->getDefault()->disconnect();
1296
-        unlink('jpemeric_blog.db');
1297
-    }
1281
+			$data
1282
+		);
1283
+	}
1284
+
1285
+	protected function tearDown()
1286
+	{
1287
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`post`");
1288
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`ptlink`");
1289
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series_post`");
1290
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`tag`");
1291
+	}
1292
+
1293
+	public static function tearDownAfterClass()
1294
+	{
1295
+		self::$connection->getDefault()->disconnect();
1296
+		unlink('jpemeric_blog.db');
1297
+	}
1298 1298
 }
Please login to merge, or discard this patch.
controller/blog/PostController.class.inc.php 3 patches
Braces   +9 added lines, -7 removed lines patch added patch discarded remove patch
@@ -26,8 +26,9 @@  discard block
 block discarded – undo
26 26
 		parent::__construct();
27 27
 		
28 28
 		$this->post = PostCollector::getPostByURI(URLDecode::getPiece(2));
29
-		if($this->post == null)
30
-			$this->eject();
29
+		if($this->post == null) {
30
+					$this->eject();
31
+		}
31 32
 		
32 33
 		$this->handle_comment_submit(
33 34
 			self::$BLOG_SITE_ID,
@@ -106,8 +107,9 @@  discard block
 block discarded – undo
106 107
 	private function get_series_posts()
107 108
 	{
108 109
 		$series_posts = $this->fetch_series_posts();
109
-		if(count($series_posts) < 1)
110
-			return array();
110
+		if(count($series_posts) < 1) {
111
+					return array();
112
+		}
111 113
 		
112 114
 		$previous_post = new stdclass();
113 115
 		$next_post = new stdclass();
@@ -141,9 +143,9 @@  discard block
 block discarded – undo
141 143
 
142 144
 			$post->url = Loader::getRootUrl('blog') . "{$post_row['category']}/{$post_row['path']}/";
143 145
 			
144
-			if(!$found_current_post)
145
-				$previous_post = $post;
146
-			else
146
+			if(!$found_current_post) {
147
+							$previous_post = $post;
148
+			} else
147 149
 			{
148 150
 				$next_post = $post;
149 151
 				break;
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
         $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
28 28
         $this->post = $repository->findPostByPath(URLDecode::getPiece(2));
29 29
 
30
-		if($this->post == null)
30
+		if ($this->post == null)
31 31
 			$this->eject();
32 32
 		
33 33
 		$this->handle_comment_submit(
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		$keyword_array = array();
96 96
 		$keywords = $this->tags;
97 97
 		
98
-		foreach($keywords as $keyword)
98
+		foreach ($keywords as $keyword)
99 99
 		{
100 100
 			$keyword_array[] = $keyword['tag'];
101 101
 		}
@@ -109,16 +109,16 @@  discard block
 block discarded – undo
109 109
 	private function get_series_posts()
110 110
 	{
111 111
 		$series_posts = $this->fetch_series_posts();
112
-		if(count($series_posts) < 1)
112
+		if (count($series_posts) < 1)
113 113
 			return array();
114 114
 		
115 115
 		$previous_post = new stdclass();
116 116
 		$next_post = new stdclass();
117 117
 		
118 118
 		$found_current_post = false;
119
-		foreach($series_posts as $post_row)
119
+		foreach ($series_posts as $post_row)
120 120
 		{
121
-			if($post_row['post'] == $this->post['id'])
121
+			if ($post_row['post'] == $this->post['id'])
122 122
 			{
123 123
 				$found_current_post = true;
124 124
 				continue;
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 
145 145
 			$post->url = Loader::getRootUrl('blog') . "{$post_row['category']}/{$post_row['path']}/";
146 146
 			
147
-			if(!$found_current_post)
147
+			if (!$found_current_post)
148 148
 				$previous_post = $post;
149 149
 			else
150 150
 			{
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 	private $series_posts;
164 164
 	private function fetch_series_posts()
165 165
 	{
166
-      if(!isset($this->series_posts)) {
166
+      if (!isset($this->series_posts)) {
167 167
           global $container;
168 168
           $repository = new Jacobemerick\Web\Domain\Blog\Series\MysqlSeriesRepository($container['db_connection_locator']);
169 169
           $this->series_posts = $repository->getSeriesForPost($this->post['id']);
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 	private function get_related_posts()
175 175
 	{
176 176
 		$tag_array = array();
177
-		foreach($this->tags as $tag)
177
+		foreach ($this->tags as $tag)
178 178
 		{
179 179
 			$tag_array[] = $tag['id'];
180 180
 		}
181 181
 		
182 182
 		$series_posts = $this->fetch_series_posts();
183 183
 		$exclude_post_array = array();
184
-		foreach($series_posts as $series_post)
184
+		foreach ($series_posts as $series_post)
185 185
 		{
186 186
 			$exclude_post_array[] = $series_post['post'];
187 187
 		}
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
         $post_array = array();
194 194
 		
195
-		foreach($post_result as $post_row)
195
+		foreach ($post_result as $post_row)
196 196
 		{
197 197
 			$post = new stdclass();
198 198
 			$post->title = $post_row['title'];
Please login to merge, or discard this patch.
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -23,9 +23,9 @@  discard block
 block discarded – undo
23 23
 	{
24 24
 		parent::__construct();
25 25
 		
26
-        global $container;
27
-        $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
28
-        $this->post = $repository->findPostByPath(URLDecode::getPiece(2));
26
+		global $container;
27
+		$repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
28
+		$this->post = $repository->findPostByPath(URLDecode::getPiece(2));
29 29
 
30 30
 		if($this->post == null)
31 31
 			$this->eject();
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 			Loader::getRootUrl('blog') . $this->post['category'] . '/' . $this->post['path'] . '/',
37 37
 			$this->post['title']);
38 38
 
39
-        global $container;
40
-        $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']);
41
-        $this->tags = $repository->getTagsForPost($this->post['id']);
39
+		global $container;
40
+		$repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']);
41
+		$this->tags = $repository->getTagsForPost($this->post['id']);
42 42
 	}
43 43
 
44 44
 	protected function set_head_data()
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 		$this->set_keywords($this->get_post_keywords());
51 51
 		$this->set_author(self::$AUTHOR);
52 52
 
53
-    $photo = Content::instance('FetchFirstPhoto', $this->post['body'])->activate(true);
54
-    $photo = preg_match('/^<img src="([a-z-:\.\/]+)" [^>]+>$/', $photo, $matches);
55
-    $this->set_head('thumbnail', $matches[1]);
53
+	$photo = Content::instance('FetchFirstPhoto', $this->post['body'])->activate(true);
54
+	$photo = preg_match('/^<img src="([a-z-:\.\/]+)" [^>]+>$/', $photo, $matches);
55
+	$this->set_head('thumbnail', $matches[1]);
56 56
 
57 57
 		if (array_key_exists($this->post['id'], self::$DEPRECATED_BLOGS)) {
58 58
 			$log_id = self::$DEPRECATED_BLOGS[$this->post['id']];
@@ -126,16 +126,16 @@  discard block
 block discarded – undo
126 126
 			
127 127
 			$post = new stdclass();
128 128
 
129
-      if (
130
-        strpos($post_row['title'], 'Rainy Supe Loop') === 0 ||
131
-        strpos($post_row['title'], 'Malapais Loop') === 0
132
-      ) {
133
-        $title = $post_row['title'];
134
-        $title = explode(':', $title);
135
-        $title = array_pop($title);
136
-        $title = trim($title);
137
-        $post->title = $title;
138
-      } else if (strpos($post_row['title'], 'Isle Royale') === 0) {
129
+	  if (
130
+		strpos($post_row['title'], 'Rainy Supe Loop') === 0 ||
131
+		strpos($post_row['title'], 'Malapais Loop') === 0
132
+	  ) {
133
+		$title = $post_row['title'];
134
+		$title = explode(':', $title);
135
+		$title = array_pop($title);
136
+		$title = trim($title);
137
+		$post->title = $title;
138
+	  } else if (strpos($post_row['title'], 'Isle Royale') === 0) {
139 139
 				$title = $post_row['title'];
140 140
 				$title = explode(',', $title);
141 141
 				$title = array_pop($title);
@@ -166,12 +166,12 @@  discard block
 block discarded – undo
166 166
 	private $series_posts;
167 167
 	private function fetch_series_posts()
168 168
 	{
169
-      if(!isset($this->series_posts)) {
170
-          global $container;
171
-          $repository = new Jacobemerick\Web\Domain\Blog\Series\MysqlSeriesRepository($container['db_connection_locator']);
172
-          $this->series_posts = $repository->getSeriesForPost($this->post['id']);
173
-      }
174
-      return $this->series_posts;
169
+	  if(!isset($this->series_posts)) {
170
+		  global $container;
171
+		  $repository = new Jacobemerick\Web\Domain\Blog\Series\MysqlSeriesRepository($container['db_connection_locator']);
172
+		  $this->series_posts = $repository->getSeriesForPost($this->post['id']);
173
+	  }
174
+	  return $this->series_posts;
175 175
 	}
176 176
 
177 177
 	private function get_related_posts()
@@ -189,11 +189,11 @@  discard block
 block discarded – undo
189 189
 			$exclude_post_array[] = $series_post['post'];
190 190
 		}
191 191
 
192
-        global $container;
193
-        $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
194
-        $post_result = $repository->getActivePostsByRelatedTags($this->post['id']);
192
+		global $container;
193
+		$repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
194
+		$post_result = $repository->getActivePostsByRelatedTags($this->post['id']);
195 195
 
196
-        $post_array = array();
196
+		$post_array = array();
197 197
 		
198 198
 		foreach($post_result as $post_row)
199 199
 		{
Please login to merge, or discard this patch.
src/Domain/Blog/Post/MysqlPostRepository.php 2 patches
Doc Comments   +10 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
     protected $connections;
12 12
 
13 13
     /**
14
-     * @param Aura\Sql\ConnectionLocator $connections
14
+     * @param ConnectionLocator $connections
15 15
      */
16 16
     public function __construct(ConnectionLocator $connections)
17 17
     {
@@ -41,6 +41,9 @@  discard block
 block discarded – undo
41 41
             ->fetchOne($query, $bindings);
42 42
     }
43 43
 
44
+    /**
45
+     * @param integer $limit
46
+     */
44 47
     public function getActivePosts($limit = null, $offset = 0)
45 48
     {
46 49
         $query = "
@@ -79,6 +82,9 @@  discard block
 block discarded – undo
79 82
             ->fetchValue($query, $bindings);
80 83
     }
81 84
 
85
+    /**
86
+     * @param integer $limit
87
+     */
82 88
     public function getActivePostsByTag($tag, $limit = null, $offset = 0)
83 89
     {
84 90
         $query = "
@@ -122,6 +128,9 @@  discard block
 block discarded – undo
122 128
             ->fetchValue($query, $bindings);
123 129
     }
124 130
 
131
+    /**
132
+     * @param integer $limit
133
+     */
125 134
     public function getActivePostsByCategory($category, $limit = null, $offset = 0)
126 135
     {
127 136
         $query = "
Please login to merge, or discard this patch.
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -7,163 +7,163 @@  discard block
 block discarded – undo
7 7
 class MysqlPostRepository implements PostRepositoryInterface
8 8
 {
9 9
 
10
-    /** @var  Aura\Sql\ConnectionLocator */
11
-    protected $connections;
12
-
13
-    /**
14
-     * @param Aura\Sql\ConnectionLocator $connections
15
-     */
16
-    public function __construct(ConnectionLocator $connections)
17
-    {
18
-        $this->connections = $connections;
19
-    }
20
-
21
-    /**
22
-     * @param string $path
23
-     *
24
-     * @return array|false
25
-     */
26
-    public function findPostByPath($path)
27
-    {
28
-        $query = "
10
+	/** @var  Aura\Sql\ConnectionLocator */
11
+	protected $connections;
12
+
13
+	/**
14
+	 * @param Aura\Sql\ConnectionLocator $connections
15
+	 */
16
+	public function __construct(ConnectionLocator $connections)
17
+	{
18
+		$this->connections = $connections;
19
+	}
20
+
21
+	/**
22
+	 * @param string $path
23
+	 *
24
+	 * @return array|false
25
+	 */
26
+	public function findPostByPath($path)
27
+	{
28
+		$query = "
29 29
             SELECT `id`, `title`, `path`, `date`, `body`, `category`
30 30
             FROM `jpemeric_blog`.`post`
31 31
             WHERE `path` = :path AND `display` = :is_active
32 32
             LIMIT 1";
33
-        $bindings = [
34
-            'path'      => $path,
35
-            'is_active' => 1,
36
-        ];
37
-
38
-        return $this
39
-            ->connections
40
-            ->getRead()
41
-            ->fetchOne($query, $bindings);
42
-    }
43
-
44
-    public function getActivePosts($limit = null, $offset = 0)
45
-    {
46
-        $query = "
33
+		$bindings = [
34
+			'path'      => $path,
35
+			'is_active' => 1,
36
+		];
37
+
38
+		return $this
39
+			->connections
40
+			->getRead()
41
+			->fetchOne($query, $bindings);
42
+	}
43
+
44
+	public function getActivePosts($limit = null, $offset = 0)
45
+	{
46
+		$query = "
47 47
             SELECT `id`, `title`, `path`, `date`, `body`, `category`
48 48
             FROM `jpemeric_blog`.`post`
49 49
             WHERE `display` = :is_active
50 50
             ORDER BY `date` DESC";
51
-        if ($limit != null) {
52
-            $query .= "
51
+		if ($limit != null) {
52
+			$query .= "
53 53
             LIMIT {$offset}, {$limit}";
54
-        }
54
+		}
55 55
 
56
-        $bindings = [
57
-            'is_active' => 1,
58
-        ];
56
+		$bindings = [
57
+			'is_active' => 1,
58
+		];
59 59
 
60
-        return $this
61
-            ->connections
62
-            ->getRead()
63
-            ->fetchAll($query, $bindings);
64
-    }
60
+		return $this
61
+			->connections
62
+			->getRead()
63
+			->fetchAll($query, $bindings);
64
+	}
65 65
 
66
-    public function getActivePostsCount()
67
-    {
68
-        $query = "
66
+	public function getActivePostsCount()
67
+	{
68
+		$query = "
69 69
             SELECT COUNT(1) AS `count`
70 70
             FROM `jpemeric_blog`.`post`
71 71
             WHERE `display` = :is_active";
72
-        $bindings = [
73
-            'is_active' => 1,
74
-        ];
75
-
76
-        return $this
77
-            ->connections
78
-            ->getRead()
79
-            ->fetchValue($query, $bindings);
80
-    }
81
-
82
-    public function getActivePostsByTag($tag, $limit = null, $offset = 0)
83
-    {
84
-        $query = "
72
+		$bindings = [
73
+			'is_active' => 1,
74
+		];
75
+
76
+		return $this
77
+			->connections
78
+			->getRead()
79
+			->fetchValue($query, $bindings);
80
+	}
81
+
82
+	public function getActivePostsByTag($tag, $limit = null, $offset = 0)
83
+	{
84
+		$query = "
85 85
             SELECT `id`, `title`, `path`, `date`, `body`, `category`
86 86
             FROM `jpemeric_blog`.`post`
87 87
             INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`post_id` = `post`.`id` AND
88 88
                                                    `ptlink`.`tag_id` = :tag_id
89 89
             WHERE `display` = :is_active";
90
-        if ($limit != null) {
91
-            $query .= "
90
+		if ($limit != null) {
91
+			$query .= "
92 92
             LIMIT {$offset}, {$limit}";
93
-        }
94
-
95
-        $bindings = [
96
-            'tag_id'    => $tag,
97
-            'is_active' => 1,
98
-        ];
99
-
100
-        return $this
101
-            ->connections
102
-            ->getRead()
103
-            ->fetchAll($query, $bindings);
104
-    }
105
-
106
-    public function getActivePostsCountByTag($tag)
107
-    {
108
-        $query = "
93
+		}
94
+
95
+		$bindings = [
96
+			'tag_id'    => $tag,
97
+			'is_active' => 1,
98
+		];
99
+
100
+		return $this
101
+			->connections
102
+			->getRead()
103
+			->fetchAll($query, $bindings);
104
+	}
105
+
106
+	public function getActivePostsCountByTag($tag)
107
+	{
108
+		$query = "
109 109
             SELECT COUNT(1) AS `count`
110 110
             FROM `jpemeric_blog`.`post`
111 111
             INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`post_id` = `post`.`id` AND
112 112
                                                    `ptlink`.`tag_id` = :tag_id
113 113
             WHERE `display` = :is_active";
114
-        $bindings = [
115
-            'tag_id'    => $tag,
116
-            'is_active' => 1,
117
-        ];
118
-
119
-        return $this
120
-            ->connections
121
-            ->getRead()
122
-            ->fetchValue($query, $bindings);
123
-    }
124
-
125
-    public function getActivePostsByCategory($category, $limit = null, $offset = 0)
126
-    {
127
-        $query = "
114
+		$bindings = [
115
+			'tag_id'    => $tag,
116
+			'is_active' => 1,
117
+		];
118
+
119
+		return $this
120
+			->connections
121
+			->getRead()
122
+			->fetchValue($query, $bindings);
123
+	}
124
+
125
+	public function getActivePostsByCategory($category, $limit = null, $offset = 0)
126
+	{
127
+		$query = "
128 128
             SELECT `id`, `title`, `path`, `date`, `body`, `category`
129 129
             FROM `jpemeric_blog`.`post`
130 130
             WHERE `category` = :category AND `display` = :is_active";
131
-        if ($limit != null) {
132
-            $query .= "
131
+		if ($limit != null) {
132
+			$query .= "
133 133
             LIMIT {$offset}, {$limit}";
134
-        }
135
-
136
-        $bindings = [
137
-            'category'  => $category,
138
-            'is_active' => 1,
139
-        ];
140
-
141
-        return $this
142
-            ->connections
143
-            ->getRead()
144
-            ->fetchAll($query, $bindings);
145
-    }
146
-
147
-    public function getActivePostsCountByCategory($category)
148
-    {
149
-        $query = "
134
+		}
135
+
136
+		$bindings = [
137
+			'category'  => $category,
138
+			'is_active' => 1,
139
+		];
140
+
141
+		return $this
142
+			->connections
143
+			->getRead()
144
+			->fetchAll($query, $bindings);
145
+	}
146
+
147
+	public function getActivePostsCountByCategory($category)
148
+	{
149
+		$query = "
150 150
             SELECT COUNT(1) AS `count`
151 151
             FROM `jpemeric_blog`.`post`
152 152
             WHERE `category` = :category AND `display` = :is_active";
153
-        $bindings = [
154
-            'category'  => $category,
155
-            'is_active' => 1,
156
-        ];
157
-
158
-        return $this
159
-            ->connections
160
-            ->getRead()
161
-            ->fetchValue($query, $bindings);
162
-    }
163
-
164
-    public function getActivePostsByRelatedTags($post, $limit = 4)
165
-    {
166
-        $query = "
153
+		$bindings = [
154
+			'category'  => $category,
155
+			'is_active' => 1,
156
+		];
157
+
158
+		return $this
159
+			->connections
160
+			->getRead()
161
+			->fetchValue($query, $bindings);
162
+	}
163
+
164
+	public function getActivePostsByRelatedTags($post, $limit = 4)
165
+	{
166
+		$query = "
167 167
             SELECT `id`, `title`, `path`, `date`, `body`, `category`, COUNT(1) AS `count`
168 168
             FROM `jpemeric_blog`.`post`
169 169
             INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`post_id` = `post`.`id` AND
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
             GROUP BY `id`
184 184
             ORDER BY `count` DESC
185 185
             LIMIT {$limit}";
186
-        $bindings = [
187
-            'post'      => $post,
188
-            'is_active' => 1,
189
-        ];
190
-
191
-        return $this
192
-            ->connections
193
-            ->getRead()
194
-            ->fetchAll($query, $bindings);
195
-    }
186
+		$bindings = [
187
+			'post'      => $post,
188
+			'is_active' => 1,
189
+		];
190
+
191
+		return $this
192
+			->connections
193
+			->getRead()
194
+			->fetchAll($query, $bindings);
195
+	}
196 196
 }
Please login to merge, or discard this patch.