Completed
Pull Request — master (#5)
by Jacob
03:16
created
controller/blog/HomeController.class.inc.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 	{
50 50
 		if($this->page == 1)
51 51
 		{
52
-        global $container;
53
-        $repository = new Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository($container['db_connection_locator']);
54
-        $introduction_result = $repository->findByType('home');
52
+		global $container;
53
+		$repository = new Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository($container['db_connection_locator']);
54
+		$introduction_result = $repository->findByType('home');
55 55
 			
56 56
 			$introduction = array();
57 57
 			$introduction['title'] = $introduction_result['title'];
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
 
76 76
 	protected function get_list_results()
77 77
 	{
78
-        global $container;
79
-        $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
80
-        return $repository->getActivePosts(self::$POSTS_PER_PAGE, $this->offset);
78
+		global $container;
79
+		$repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
80
+		return $repository->getActivePosts(self::$POSTS_PER_PAGE, $this->offset);
81 81
 	}
82 82
 
83 83
 	protected function get_list_description()
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 	private $total_post_count;
108 108
 	protected function get_total_post_count()
109 109
 	{
110
-      if(!isset($this->total_post_count)) {
111
-          global $container;
112
-          $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
113
-          $this->total_post_count = $repository->getActivePostsCount();
114
-      }
110
+	  if(!isset($this->total_post_count)) {
111
+		  global $container;
112
+		  $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
113
+		  $this->total_post_count = $repository->getActivePostsCount();
114
+	  }
115 115
 
116 116
 		return $this->total_post_count;
117 117
 	}
Please login to merge, or discard this patch.
controller/blog/TagController.class.inc.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -26,9 +26,9 @@  discard block
 block discarded – undo
26 26
 		$tag = URLDecode::getPiece(2);
27 27
 		$tag = str_replace('-', ' ', $tag);
28 28
 
29
-        global $container;
30
-        $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']);
31
-        $tag_result = $repository->findTagByTitle($tag);
29
+		global $container;
30
+		$repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']);
31
+		$tag_result = $repository->findTagByTitle($tag);
32 32
 
33 33
 		if($tag_result === false)
34 34
 			$this->eject();
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 		
65 65
 		if($this->page == 1)
66 66
 		{
67
-        global $container;
68
-        $repository = new Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository($container['db_connection_locator']);
69
-        $introduction_result = $repository->findByType('tag', $this->tag['tag']);
67
+		global $container;
68
+		$repository = new Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository($container['db_connection_locator']);
69
+		$introduction_result = $repository->findByType('tag', $this->tag['tag']);
70 70
 			
71 71
 			if($introduction_result !== false)
72 72
 			{
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
 
97 97
 	protected function get_list_results()
98 98
 	{
99
-        global $container;
100
-        $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
101
-        return $repository->getActivePostsByTag($this->tag['id'], self::$POSTS_PER_PAGE, $this->offset);
99
+		global $container;
100
+		$repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
101
+		return $repository->getActivePostsByTag($this->tag['id'], self::$POSTS_PER_PAGE, $this->offset);
102 102
 	}
103 103
 
104 104
 	protected function get_list_description()
@@ -129,10 +129,10 @@  discard block
 block discarded – undo
129 129
 	protected function get_total_post_count()
130 130
 	{
131 131
 		if(!isset($this->total_post_count)) {
132
-        global $container;
133
-        $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
134
-        $this->total_post_count = $repository->getActivePostsCountByTag($this->tag['id']);
135
-    }
132
+		global $container;
133
+		$repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
134
+		$this->total_post_count = $repository->getActivePostsCountByTag($this->tag['id']);
135
+	}
136 136
 
137 137
 		return $this->total_post_count;
138 138
 	}
Please login to merge, or discard this patch.
controller/blog/CategoryController.class.inc.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
 	{
116 116
 		if($this->page == 1)
117 117
 		{
118
-        global $container;
119
-        $repository = new Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository($container['db_connection_locator']);
120
-        $introduction_result = $repository->findByType('category', $this->category->link);
118
+		global $container;
119
+		$repository = new Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository($container['db_connection_locator']);
120
+		$introduction_result = $repository->findByType('category', $this->category->link);
121 121
 			
122 122
 			$introduction = array();
123 123
 			$introduction['title'] = $introduction_result['title'];
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 
142 142
 	protected function get_list_results()
143 143
 	{
144
-        global $container;
145
-        $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
146
-        return $repository->getActivePostsByCategory($this->category->link, self::$POSTS_PER_PAGE, $this->offset);
144
+		global $container;
145
+		$repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
146
+		return $repository->getActivePostsByCategory($this->category->link, self::$POSTS_PER_PAGE, $this->offset);
147 147
 	}
148 148
 
149 149
 	protected function get_list_description()
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 	protected function get_total_post_count()
175 175
 	{
176 176
 		if(!isset($this->total_post_count)) {
177
-        global $container;
178
-        $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
179
-        $this->total_post_count = $repository->getActivePostsCountByCategory($this->category->link);
180
-    }
177
+		global $container;
178
+		$repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
179
+		$this->total_post_count = $repository->getActivePostsCountByCategory($this->category->link);
180
+	}
181 181
 		return $this->total_post_count;
182 182
 	}
183 183
 
Please login to merge, or discard this patch.
controller/blog/AboutController.class.inc.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -33,9 +33,9 @@
 block discarded – undo
33 33
 
34 34
 	protected function get_introduction()
35 35
 	{
36
-        global $container;
37
-        $repository = new Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository($container['db_connection_locator']);
38
-        $introduction_result = $repository->findByType('about');
36
+		global $container;
37
+		$repository = new Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository($container['db_connection_locator']);
38
+		$introduction_result = $repository->findByType('about');
39 39
 		
40 40
 		if($introduction_result !== null)
41 41
 		{
Please login to merge, or discard this patch.
controller/blog/SearchController.class.inc.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	{
35 35
 		$query = URLDecode::getPiece(2);
36 36
 		$query = urldecode($query);
37
-        $query = str_replace('-', ' ', $query);
37
+		$query = str_replace('-', ' ', $query);
38 38
 		
39 39
 		$this->query = $query;
40 40
 		
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 	{
88 88
 		if(!isset($this->search_result))
89 89
 		{
90
-        global $container;
91
-        $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
92
-        $posts = $repository->getActivePosts();
90
+		global $container;
91
+		$repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']);
92
+		$posts = $repository->getActivePosts();
93 93
 			
94 94
 			$this->search_result = Search::instance()
95 95
 				->setQuery($this->query)
Please login to merge, or discard this patch.
controller/blog/DefaultPageController.class.inc.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@  discard block
 block discarded – undo
18 18
 
19 19
 	protected function set_head_data()
20 20
 	{
21
-    $this->set_head('rss_link', [
22
-      'title' => 'Jacob Emerick Blog Feed',
23
-      'url' => '/rss.xml'
24
-    ]);
25
-    $this->set_head('rss_comment_link', [
26
-      'title' => 'Jacob Emerick Blog Comment Feed',
27
-      'url' => '/rss-comments.xml'
28
-    ]);
21
+	$this->set_head('rss_link', [
22
+	  'title' => 'Jacob Emerick Blog Feed',
23
+	  'url' => '/rss.xml'
24
+	]);
25
+	$this->set_head('rss_comment_link', [
26
+	  'title' => 'Jacob Emerick Blog Comment Feed',
27
+	  'url' => '/rss-comments.xml'
28
+	]);
29 29
 		
30 30
 		$this->add_css('normalize');
31 31
 		$this->add_css('blog');
@@ -87,11 +87,11 @@  discard block
 block discarded – undo
87 87
 
88 88
 	final private function get_tags_for_post($post)
89 89
 	{
90
-        global $container;
91
-        $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']);
92
-        $tag_result = $repository->getTagsForPost($post['id']);
90
+		global $container;
91
+		$repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']);
92
+		$tag_result = $repository->getTagsForPost($post['id']);
93 93
 
94
-        $tag_array = array();
94
+		$tag_array = array();
95 95
 		foreach($tag_result as $tag)
96 96
 		{
97 97
 			$tag_object = new stdclass();
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 
126 126
 	final private function get_tag_cloud()
127 127
 	{
128
-        global $container;
129
-        $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']);
130
-        $tag_result = $repository->getTagCloud();
128
+		global $container;
129
+		$repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']);
130
+		$tag_result = $repository->getTagCloud();
131 131
 		
132 132
 		$maximum_tag_count = $this->get_maximum_tag_count($tag_result);
133 133
 		
Please login to merge, or discard this patch.
src/Domain/Blog/Post/MysqlPostRepository.php 1 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.
src/Domain/Blog/Post/PostRepositoryInterface.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -4,12 +4,12 @@
 block discarded – undo
4 4
 
5 5
 interface PostRepositoryInterface
6 6
 {
7
-    public function findPostByPath($path);
8
-    public function getActivePosts($limit = null, $offset= 0);
9
-    public function getActivePostsCount();
10
-    public function getActivePostsByTag($tag, $limit = null, $offset = 0);
11
-    public function getActivePostsCountByTag($tag);
12
-    public function getActivePostsByCategory($category, $limit = null, $offset = 0);
13
-    public function getActivePostsCountByCategory($category);
14
-    public function getActivePostsByRelatedTags($post, $limit = 4);
7
+	public function findPostByPath($path);
8
+	public function getActivePosts($limit = null, $offset= 0);
9
+	public function getActivePostsCount();
10
+	public function getActivePostsByTag($tag, $limit = null, $offset = 0);
11
+	public function getActivePostsCountByTag($tag);
12
+	public function getActivePostsByCategory($category, $limit = null, $offset = 0);
13
+	public function getActivePostsCountByCategory($category);
14
+	public function getActivePostsByRelatedTags($post, $limit = 4);
15 15
 }
Please login to merge, or discard this patch.
tests/unit/Domain/Blog/Post/MysqlPostRepositoryTest.php 1 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.