Completed
Push — master ( 8c8014...211020 )
by Jacob
03:25
created
router/Router.class.inc.php 3 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@  discard block
 block discarded – undo
18 18
 
19 19
 	private static function get_router_name()
20 20
 	{
21
-		if(Request::isAJAX())
21
+		if (Request::isAJAX())
22 22
 			return 'AJAXRouter';
23 23
 		
24
-		switch(URLDecode::getSite())
24
+		switch (URLDecode::getSite())
25 25
 		{
26 26
 			case 'ajax' :
27 27
 				return 'AjaxRouter';
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
 
66 66
 	final protected function check_for_redirect($redirect_uri)
67 67
 	{
68
-		foreach($this->get_redirect_array() as $check)
68
+		foreach ($this->get_redirect_array() as $check)
69 69
 		{
70 70
 			$redirect_uri = preg_replace($check->pattern, $check->replace, $redirect_uri);
71 71
 		}
72 72
 		
73 73
 		$redirect_uri = $this->check_for_special_redirect($redirect_uri);
74 74
 		
75
-		if($this->requires_trailing_slash() && substr($redirect_uri, -1) != '/')
75
+		if ($this->requires_trailing_slash() && substr($redirect_uri, -1) != '/')
76 76
 			$redirect_uri .= '/';
77 77
 		
78 78
         if (URLDecode::getHost() == 'waterfalls.jacobemerick.com') {
@@ -80,23 +80,23 @@  discard block
 block discarded – undo
80 80
             $redirect_uri = $protocol . '://' . (!Loader::isLive() ? 'dev' : 'www') . '.waterfallsofthekeweenaw.com' . $redirect_uri;
81 81
         }
82 82
         
83
-		if($redirect_uri == URLDecode::getURI())
83
+		if ($redirect_uri == URLDecode::getURI())
84 84
 			return;
85 85
 		
86 86
 		$controller_check = $redirect_uri;
87
-		if(substr($redirect_uri, 0, 4) == 'http') {
87
+		if (substr($redirect_uri, 0, 4) == 'http') {
88 88
       $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
89 89
 			$controller_check = preg_replace('@^' . $protocol . '://([a-z\.]+)@', '', $redirect_uri);
90 90
 		
91 91
 		$controller = $this->get_controller($controller_check);
92
-		if($controller == '/Error404Controller')
92
+		if ($controller == '/Error404Controller')
93 93
 		{
94 94
 			Loader::loadNew('controller', '/Error404Controller')
95 95
 				->activate();
96 96
 			exit;
97 97
 		}
98 98
 
99
-		if(substr($redirect_uri, 0, 4) != 'http')
99
+		if (substr($redirect_uri, 0, 4) != 'http')
100 100
 		{
101 101
 			$redirect_uri = substr($redirect_uri, 1);
102 102
 			$redirect_uri = URLDecode::getBase() . $redirect_uri;
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
 
114 114
 	final private function get_controller($uri)
115 115
 	{
116
-		foreach($this->get_direct_array() as $check)
116
+		foreach ($this->get_direct_array() as $check)
117 117
 		{
118
-			if($uri == $check->match)
118
+			if ($uri == $check->match)
119 119
 				return "{$this->get_primary_folder()}/{$check->controller}";
120 120
 			
121
-			if(preg_match("@^{$check->match}$@", $uri))
121
+			if (preg_match("@^{$check->match}$@", $uri))
122 122
 				return "{$this->get_primary_folder()}/{$check->controller}";
123 123
 		}
124 124
 		
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 
128 128
 	final private function get_primary_folder()
129 129
 	{
130
-		if(Request::isAjax())
130
+		if (Request::isAjax())
131 131
 			return 'ajax';
132 132
 		
133 133
 		return URLDecode::getSite();
Please login to merge, or discard this patch.
Braces   +18 added lines, -12 removed lines patch added patch discarded remove patch
@@ -18,8 +18,9 @@  discard block
 block discarded – undo
18 18
 
19 19
 	private static function get_router_name()
20 20
 	{
21
-		if(Request::isAJAX())
22
-			return 'AJAXRouter';
21
+		if(Request::isAJAX()) {
22
+					return 'AJAXRouter';
23
+		}
23 24
 		
24 25
 		switch(URLDecode::getSite())
25 26
 		{
@@ -72,16 +73,18 @@  discard block
 block discarded – undo
72 73
 		
73 74
 		$redirect_uri = $this->check_for_special_redirect($redirect_uri);
74 75
 		
75
-		if($this->requires_trailing_slash() && substr($redirect_uri, -1) != '/')
76
-			$redirect_uri .= '/';
76
+		if($this->requires_trailing_slash() && substr($redirect_uri, -1) != '/') {
77
+					$redirect_uri .= '/';
78
+		}
77 79
 		
78 80
         if (URLDecode::getHost() == 'waterfalls.jacobemerick.com') {
79 81
             $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
80 82
             $redirect_uri = $protocol . '://' . (!Loader::isLive() ? 'dev' : 'www') . '.waterfallsofthekeweenaw.com' . $redirect_uri;
81 83
         }
82 84
         
83
-		if($redirect_uri == URLDecode::getURI())
84
-			return;
85
+		if($redirect_uri == URLDecode::getURI()) {
86
+					return;
87
+		}
85 88
 		
86 89
 		$controller_check = $redirect_uri;
87 90
 		if(substr($redirect_uri, 0, 4) == 'http') {
@@ -115,11 +118,13 @@  discard block
 block discarded – undo
115 118
 	{
116 119
 		foreach($this->get_direct_array() as $check)
117 120
 		{
118
-			if($uri == $check->match)
119
-				return "{$this->get_primary_folder()}/{$check->controller}";
121
+			if($uri == $check->match) {
122
+							return "{$this->get_primary_folder()}/{$check->controller}";
123
+			}
120 124
 			
121
-			if(preg_match("@^{$check->match}$@", $uri))
122
-				return "{$this->get_primary_folder()}/{$check->controller}";
125
+			if(preg_match("@^{$check->match}$@", $uri)) {
126
+							return "{$this->get_primary_folder()}/{$check->controller}";
127
+			}
123 128
 		}
124 129
 		
125 130
 		return '/Error404Controller';
@@ -127,8 +132,9 @@  discard block
 block discarded – undo
127 132
 
128 133
 	final private function get_primary_folder()
129 134
 	{
130
-		if(Request::isAjax())
131
-			return 'ajax';
135
+		if(Request::isAjax()) {
136
+					return 'ajax';
137
+		}
132 138
 		
133 139
 		return URLDecode::getSite();
134 140
 	}
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -75,19 +75,19 @@  discard block
 block discarded – undo
75 75
 		if($this->requires_trailing_slash() && substr($redirect_uri, -1) != '/')
76 76
 			$redirect_uri .= '/';
77 77
 		
78
-        if (URLDecode::getHost() == 'waterfalls.jacobemerick.com') {
79
-            $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
80
-            $redirect_uri = $protocol . '://' . (!Loader::isLive() ? 'dev' : 'www') . '.waterfallsofthekeweenaw.com' . $redirect_uri;
81
-        }
78
+		if (URLDecode::getHost() == 'waterfalls.jacobemerick.com') {
79
+			$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
80
+			$redirect_uri = $protocol . '://' . (!Loader::isLive() ? 'dev' : 'www') . '.waterfallsofthekeweenaw.com' . $redirect_uri;
81
+		}
82 82
         
83 83
 		if($redirect_uri == URLDecode::getURI())
84 84
 			return;
85 85
 		
86 86
 		$controller_check = $redirect_uri;
87 87
 		if(substr($redirect_uri, 0, 4) == 'http') {
88
-      $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
88
+	  $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
89 89
 			$controller_check = preg_replace('@^' . $protocol . '://([a-z\.]+)@', '', $redirect_uri);
90
-    }
90
+	}
91 91
 		
92 92
 		$controller = $this->get_controller($controller_check);
93 93
 		if($controller == '/Error404Controller')
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	{
139 139
 		return (
140 140
 			URLDecode::getExtension() != 'json' &&
141
-            strstr(URLDecode::getURI(), '#') === false);
141
+			strstr(URLDecode::getURI(), '#') === false);
142 142
 	}
143 143
 
144 144
 }
Please login to merge, or discard this patch.
src/Domain/Stream/Activity/MysqlActivityRepository.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -7,108 +7,108 @@
 block discarded – undo
7 7
 class MysqlActivityRepository implements ActivityRepositoryInterface
8 8
 {
9 9
 
10
-    /** @var  ConnectionLocator */
11
-    protected $connections;
10
+	/** @var  ConnectionLocator */
11
+	protected $connections;
12 12
 
13
-    /**
14
-     * @param ConnectonLocator $connections
15
-     */
16
-    public function __construct(ConnectionLocator $connections)
17
-    {
18
-        $this->connections = $connections;
19
-    }
13
+	/**
14
+	 * @param ConnectonLocator $connections
15
+	 */
16
+	public function __construct(ConnectionLocator $connections)
17
+	{
18
+		$this->connections = $connections;
19
+	}
20 20
 
21
-    /**
22
-     * @param integer $id
23
-     *
24
-     * @return array|false
25
-     */
26
-    public function getActivityById($id)
27
-    {
28
-        $query = "
21
+	/**
22
+	 * @param integer $id
23
+	 *
24
+	 * @return array|false
25
+	 */
26
+	public function getActivityById($id)
27
+	{
28
+		$query = "
29 29
             SELECT *
30 30
             FROM `jpemeric_stream`.`activity`
31 31
             WHERE `id` = :id
32 32
             LIMIT 1";
33
-        $bindings = [
34
-            'id' => $id,
35
-        ];
33
+		$bindings = [
34
+			'id' => $id,
35
+		];
36 36
 
37
-        return $this
38
-            ->connections
39
-            ->getRead()
40
-            ->fetchOne($query, $bindings);
41
-    }
37
+		return $this
38
+			->connections
39
+			->getRead()
40
+			->fetchOne($query, $bindings);
41
+	}
42 42
 
43
-    /**
44
-     * @param integer $limit
45
-     * @param integer $offset
46
-     *
47
-     * @return array|false
48
-     */
49
-    public function getActivities($limit = null, $offset = 0)
50
-    {
51
-        $query = "
43
+	/**
44
+	 * @param integer $limit
45
+	 * @param integer $offset
46
+	 *
47
+	 * @return array|false
48
+	 */
49
+	public function getActivities($limit = null, $offset = 0)
50
+	{
51
+		$query = "
52 52
             SELECT *
53 53
             FROM `jpemeric_stream`.`activity`
54 54
             ORDER BY `datetime` DESC";
55
-        if (!is_null($limit)) {
56
-            $query .= "
55
+		if (!is_null($limit)) {
56
+			$query .= "
57 57
             LIMIT {$offset}, {$limit}";
58
-        }
58
+		}
59 59
 
60
-        return $this
61
-            ->connections
62
-            ->getRead()
63
-            ->fetchAll($query);
64
-    }
60
+		return $this
61
+			->connections
62
+			->getRead()
63
+			->fetchAll($query);
64
+	}
65 65
 
66
-    public function getActivitiesCount()
67
-    {
68
-        $query = "
66
+	public function getActivitiesCount()
67
+	{
68
+		$query = "
69 69
             SELECT COUNT(1) AS `count`
70 70
             FROM `jpemeric_stream`.`activity`";
71 71
 
72
-        return $this
73
-            ->connections
74
-            ->getRead()
75
-            ->fetchValue($query);
76
-    }
72
+		return $this
73
+			->connections
74
+			->getRead()
75
+			->fetchValue($query);
76
+	}
77 77
 
78
-    public function getActivitiesByType($type, $limit = null, $offset = 0)
79
-    {
80
-        $query = "
78
+	public function getActivitiesByType($type, $limit = null, $offset = 0)
79
+	{
80
+		$query = "
81 81
             SELECT *
82 82
             FROM `jpemeric_stream`.`activity`
83 83
             WHERE `type` = :type
84 84
             ORDER BY `datetime` DESC";
85
-        if (!is_null($limit)) {
86
-            $query .= "
85
+		if (!is_null($limit)) {
86
+			$query .= "
87 87
             LIMIT {$offset}, {$limit}";
88
-        }
89
-        $bindings = [
90
-            'type' => $type,
91
-        ];
88
+		}
89
+		$bindings = [
90
+			'type' => $type,
91
+		];
92 92
 
93
-        return $this
94
-            ->connections
95
-            ->getRead()
96
-            ->fetchAll($query, $bindings);
97
-    }
93
+		return $this
94
+			->connections
95
+			->getRead()
96
+			->fetchAll($query, $bindings);
97
+	}
98 98
 
99
-    public function getActivitiesByTypeCount($type)
100
-    {
101
-        $query = "
99
+	public function getActivitiesByTypeCount($type)
100
+	{
101
+		$query = "
102 102
             SELECT COUNT(1) AS `count`
103 103
             FROM `jpemeric_stream`.`activity`
104 104
             WHERE `type` = :type";
105
-        $bindings = [
106
-            'type' => $type,
107
-        ];
105
+		$bindings = [
106
+			'type' => $type,
107
+		];
108 108
 
109
-        return $this
110
-            ->connections
111
-            ->getRead()
112
-            ->fetchValue($query, $bindings);
113
-    }
109
+		return $this
110
+			->connections
111
+			->getRead()
112
+			->fetchValue($query, $bindings);
113
+	}
114 114
 }
Please login to merge, or discard this patch.
src/Domain/Stream/Changelog/MysqlChangelogRepository.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -7,37 +7,37 @@
 block discarded – undo
7 7
 class MysqlChangelogRepository implements ChangelogRepositoryInterface
8 8
 {
9 9
 
10
-    /** @var  ConnectionLocator */
11
-    protected $connections;
10
+	/** @var  ConnectionLocator */
11
+	protected $connections;
12 12
 
13
-    /**
14
-     * @param ConnectonLocator $connections
15
-     */
16
-    public function __construct(ConnectionLocator $connections)
17
-    {
18
-        $this->connections = $connections;
19
-    }
13
+	/**
14
+	 * @param ConnectonLocator $connections
15
+	 */
16
+	public function __construct(ConnectionLocator $connections)
17
+	{
18
+		$this->connections = $connections;
19
+	}
20 20
 
21
-    /**
22
-     * @param integer $limit
23
-     * @param integer $offset
24
-     *
25
-     * @return array|false
26
-     */
27
-    public function getChanges($limit = null, $offset = 0)
28
-    {
29
-        $query = "
21
+	/**
22
+	 * @param integer $limit
23
+	 * @param integer $offset
24
+	 *
25
+	 * @return array|false
26
+	 */
27
+	public function getChanges($limit = null, $offset = 0)
28
+	{
29
+		$query = "
30 30
             SELECT `message`, `message_short`, `datetime`, `commit_link`
31 31
             FROM `jpemeric_stream`.`changelog`
32 32
             ORDER BY `datetime` DESC";
33
-        if (!is_null($limit)) {
34
-            $query .= "
33
+		if (!is_null($limit)) {
34
+			$query .= "
35 35
             LIMIT {$offset}, {$limit}";
36
-        }
36
+		}
37 37
 
38
-        return $this
39
-            ->connections
40
-            ->getRead()
41
-            ->fetchAll($query);
42
-    }
38
+		return $this
39
+			->connections
40
+			->getRead()
41
+			->fetchAll($query);
42
+	}
43 43
 }
Please login to merge, or discard this patch.
tests/unit/Domain/Blog/Post/MysqlPostRepositoryTest.php 2 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -7,21 +7,21 @@  discard block
 block discarded – undo
7 7
 class MysqlPostRepositoryTest extends PHPUnit_Framework_TestCase
8 8
 {
9 9
 
10
-    protected $connections;
11
-
12
-    public function __construct()
13
-    {
14
-        $extendedPdo = $this->newExtendedPdo();
15
-        $this->connections = new ConnectionLocator(function () use ($extendedPdo) {
16
-            return $extendedPdo;
17
-        });
18
-    }
19
-
20
-    protected function newExtendedPdo()
21
-    {
22
-        $extendedPdo = new ExtendedPdo('sqlite::memory:');
23
-        $extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`');
24
-        $extendedPdo->exec("
10
+	protected $connections;
11
+
12
+	public function __construct()
13
+	{
14
+		$extendedPdo = $this->newExtendedPdo();
15
+		$this->connections = new ConnectionLocator(function () use ($extendedPdo) {
16
+			return $extendedPdo;
17
+		});
18
+	}
19
+
20
+	protected function newExtendedPdo()
21
+	{
22
+		$extendedPdo = new ExtendedPdo('sqlite::memory:');
23
+		$extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`');
24
+		$extendedPdo->exec("
25 25
             CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`post` (
26 26
               `id` integer PRIMARY KEY AUTOINCREMENT,
27 27
               `title` varchar(60) NOT NULL,
@@ -31,88 +31,88 @@  discard block
 block discarded – undo
31 31
               `body` text NOT NULL,
32 32
               `display` integer NOT NULL
33 33
             )"
34
-        );
35
-        return $extendedPdo;
36
-    }
37
-
38
-    public function newMysqlPostRepository()
39
-    {
40
-        return new MysqlPostRepository($this->connections);
41
-    }
42
-
43
-    public function testConstructSetsConnections()
44
-    {
45
-        $this->assertAttributeEquals(
46
-            $this->connections,
47
-            'connections',
48
-            $this->newMysqlPostRepository()
49
-        );
50
-    }
51
-
52
-    public function testFindPostByPath()
53
-    {
54
-        $test_active_post = array(
55
-            'title'     => 'test findByPath active',
56
-            'path'      => 'test-findbypath-active',
57
-            'category'  => 'test-category',
58
-            'date'      => (new DateTime())->format('Y-m-d H:i:s'),
59
-            'body'      => 'test content',
60
-            'display'   => 1
61
-        );
62
-
63
-        $this->connections->getDefault()->perform("
34
+		);
35
+		return $extendedPdo;
36
+	}
37
+
38
+	public function newMysqlPostRepository()
39
+	{
40
+		return new MysqlPostRepository($this->connections);
41
+	}
42
+
43
+	public function testConstructSetsConnections()
44
+	{
45
+		$this->assertAttributeEquals(
46
+			$this->connections,
47
+			'connections',
48
+			$this->newMysqlPostRepository()
49
+		);
50
+	}
51
+
52
+	public function testFindPostByPath()
53
+	{
54
+		$test_active_post = array(
55
+			'title'     => 'test findByPath active',
56
+			'path'      => 'test-findbypath-active',
57
+			'category'  => 'test-category',
58
+			'date'      => (new DateTime())->format('Y-m-d H:i:s'),
59
+			'body'      => 'test content',
60
+			'display'   => 1
61
+		);
62
+
63
+		$this->connections->getDefault()->perform("
64 64
             INSERT INTO jpemeric_blog.post
65 65
                 (title, path, category, date, body, display)
66 66
             VALUES
67 67
                 (:title, :path, :category, :date, :body, :display)",
68
-            $test_active_post);
69
-
70
-        $active_post = $this->newMysqlPostRepository()->findPostByPath(
71
-            $test_active_post['category'],
72
-            $test_active_post['path']
73
-        );
74
-        $this->assertSame($test_active_post['title'], $active_post['title']);
75
-
76
-        $test_inactive_post = array(
77
-            'title'     => 'test findByPath inactive',
78
-            'path'      => 'test-findbypath-inactive',
79
-            'category'  => 'test-category',
80
-            'date'      => (new DateTime())->format('Y-m-d H:i:s'),
81
-            'body'      => 'test content',
82
-            'display'   => 0
83
-        );
84
-
85
-        $this->connections->getDefault()->perform("
68
+			$test_active_post);
69
+
70
+		$active_post = $this->newMysqlPostRepository()->findPostByPath(
71
+			$test_active_post['category'],
72
+			$test_active_post['path']
73
+		);
74
+		$this->assertSame($test_active_post['title'], $active_post['title']);
75
+
76
+		$test_inactive_post = array(
77
+			'title'     => 'test findByPath inactive',
78
+			'path'      => 'test-findbypath-inactive',
79
+			'category'  => 'test-category',
80
+			'date'      => (new DateTime())->format('Y-m-d H:i:s'),
81
+			'body'      => 'test content',
82
+			'display'   => 0
83
+		);
84
+
85
+		$this->connections->getDefault()->perform("
86 86
             INSERT INTO jpemeric_blog.post
87 87
                 (title, path, category, date, body, display)
88 88
             VALUES
89 89
                 (:title, :path, :category, :date, :body, :display)",
90
-            $test_inactive_post);
91
-
92
-        $inactive_post = $this->newMysqlPostRepository()->findPostByPath(
93
-            $test_inactive_post['category'],
94
-            $test_inactive_post['path']
95
-        );
96
-        $this->assertFalse($inactive_post);
97
-
98
-        $nonexistant_post = $this->newMysqlPostRepository()->findPostByPath(
99
-            'test-category',
100
-            'test-findbypath-nonexistant'
101
-        );
102
-        $this->assertFalse($nonexistant_post);
90
+			$test_inactive_post);
91
+
92
+		$inactive_post = $this->newMysqlPostRepository()->findPostByPath(
93
+			$test_inactive_post['category'],
94
+			$test_inactive_post['path']
95
+		);
96
+		$this->assertFalse($inactive_post);
97
+
98
+		$nonexistant_post = $this->newMysqlPostRepository()->findPostByPath(
99
+			'test-category',
100
+			'test-findbypath-nonexistant'
101
+		);
102
+		$this->assertFalse($nonexistant_post);
103 103
    }
104 104
 
105
-    public function testIsInstanceOfPostRepository()
106
-    {
107
-        $this->assertInstanceOf(
108
-            'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface',
109
-            $this->newMysqlPostRepository()
110
-        );
111
-    }
105
+	public function testIsInstanceOfPostRepository()
106
+	{
107
+		$this->assertInstanceOf(
108
+			'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface',
109
+			$this->newMysqlPostRepository()
110
+		);
111
+	}
112 112
 
113
-    public static function tearDownAfterClass()
114
-    {
113
+	public static function tearDownAfterClass()
114
+	{
115 115
 //        $this->connections->getDefault()->disconnect();
116
-        unlink('jpemeric_blog.db');
117
-    }
116
+		unlink('jpemeric_blog.db');
117
+	}
118 118
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
     public function __construct()
14 14
     {
15 15
         $extendedPdo = $this->newExtendedPdo();
16
-        $this->connections = new ConnectionLocator(function () use ($extendedPdo) {
16
+        $this->connections = new ConnectionLocator(function() use ($extendedPdo) {
17 17
             return $extendedPdo;
18 18
         });
19 19
     }
Please login to merge, or discard this patch.
tests/unit/Domain/Stream/Activity/MysqlActivityRepositoryTest.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
             )"
30 30
         );
31 31
 
32
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
32
+        self::$connection = new ConnectionLocator(function() use ($extendedPdo) {
33 33
             return $extendedPdo;
34 34
         });
35 35
     }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
         $this->assertNotFalse($data);
250 250
         $this->assertInternalType('array', $data);
251 251
 
252
-        $testData = array_filter($testData, function ($row) {
252
+        $testData = array_filter($testData, function($row) {
253 253
             return ($row['type'] == 'type one');
254 254
         });
255 255
         $testData = array_values($testData);
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
         $this->assertInternalType('array', $data);
319 319
         $this->assertCount(2, $data);
320 320
 
321
-        $testData = array_filter($testData, function ($row) {
321
+        $testData = array_filter($testData, function($row) {
322 322
             return ($row['type'] == 'type one');
323 323
         });
324 324
         $testData = array_values($testData);
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
         $repository = new MysqlActivityRepository(self::$connection);
385 385
         $data = $repository->getActivitiesByTypeCount('type one');
386 386
 
387
-        $testData = array_filter($testData, function ($row) {
387
+        $testData = array_filter($testData, function($row) {
388 388
             return ($row['type'] == 'type one');
389 389
         });
390 390
 
Please login to merge, or discard this patch.
Indentation   +426 added lines, -426 removed lines patch added patch discarded remove patch
@@ -9,14 +9,14 @@  discard block
 block discarded – undo
9 9
 class MysqlActivityRepositoryTest extends PHPUnit_Framework_TestCase
10 10
 {
11 11
 
12
-    protected static $connection;
12
+	protected static $connection;
13 13
 
14
-    public static function setUpBeforeClass()
15
-    {
16
-        $extendedPdo = new ExtendedPdo('sqlite::memory:');
17
-        $extendedPdo->exec("ATTACH DATABASE `jpemeric_stream.db` AS `jpemeric_stream`");
14
+	public static function setUpBeforeClass()
15
+	{
16
+		$extendedPdo = new ExtendedPdo('sqlite::memory:');
17
+		$extendedPdo->exec("ATTACH DATABASE `jpemeric_stream.db` AS `jpemeric_stream`");
18 18
 
19
-        $extendedPdo->exec("
19
+		$extendedPdo->exec("
20 20
             CREATE TABLE IF NOT EXISTS `jpemeric_stream`.`activity` (
21 21
                 `id` integer PRIMARY KEY AUTOINCREMENT,
22 22
                 `message` text NOT NULL,
@@ -28,428 +28,428 @@  discard block
 block discarded – undo
28 28
                 `created_at` datetime,
29 29
                 `updated_at` datetime
30 30
             )"
31
-        );
32
-
33
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
34
-            return $extendedPdo;
35
-        });
36
-    }
37
-
38
-    public function testIsInstanceOfActivityRepository()
39
-    {
40
-        $repository = new MysqlActivityRepository(self::$connection);
41
-
42
-        $this->assertInstanceOf(
43
-            'Jacobemerick\Web\Domain\Stream\Activity\MysqlActivityRepository',
44
-            $repository
45
-        );
46
-    }
47
-
48
-    public function testImplementsActivityInterface()
49
-    {
50
-        $repository = new MysqlActivityRepository(self::$connection);
51
-
52
-        $this->assertInstanceOf(
53
-            'Jacobemerick\Web\Domain\Stream\Activity\ActivityRepositoryInterface',
54
-            $repository
55
-        );
56
-    }
57
-
58
-    public function testConstructSetsConnections()
59
-    {
60
-        $respository = new MysqlActivityRepository(self::$connection);
61
-
62
-        $this->assertAttributeSame(
63
-            self::$connection,
64
-            'connections',
65
-            $respository
66
-        );
67
-    }
68
-
69
-    public function testGetActivityById()
70
-    {
71
-        $testData = [
72
-            'id' => rand(1, 100),
73
-            'message' => 'test data',
74
-        ];
75
-
76
-        $this->insertData($testData);
77
-
78
-        $repository = new MysqlActivityRepository(self::$connection);
79
-        $data = $repository->getActivityById($testData['id']);
80
-
81
-        $this->assertNotFalse($data);
82
-        $this->assertInternalType('array', $data);
83
-        $this->assertArraySubset($testData, $data);
84
-    }
85
-
86
-    public function testGetActivityByIdFailure()
87
-    {
88
-        $testData = [
89
-            'id' => rand(1, 100),
90
-            'message' => 'test data',
91
-        ];
92
-
93
-        $this->insertData($testData);
94
-
95
-        $repository = new MysqlActivityRepository(self::$connection);
96
-        $data = $repository->getActivityById($testData['id'] + 1);
97
-
98
-        $this->assertFalse($data);
99
-    }
100
-
101
-    public function testGetActivities()
102
-    {
103
-        $testData = [
104
-            [
105
-                'id' => rand(1, 100),
106
-                'message' => 'test one',
107
-            ],
108
-            [
109
-                'id' => rand(101, 200),
110
-                'message' => 'test two',
111
-            ],
112
-        ];
113
-
114
-        array_walk($testData, [$this, 'insertData']);
115
-
116
-        $repository = new MysqlActivityRepository(self::$connection);
117
-        $data = $repository->getActivities();
118
-
119
-        $this->assertNotFalse($data);
120
-        $this->assertInternalType('array', $data);
121
-        foreach ($testData as $key => $testRow) {
122
-            $this->assertInternalType('array', $data[$key]);
123
-            $this->assertArraySubset($testRow, $data[$key]);
124
-        }
125
-    }
126
-
127
-    public function testGetActivitiesFailure()
128
-    {
129
-        $repository = new MysqlActivityRepository(self::$connection);
130
-        $data = $repository->getActivities();
131
-
132
-        $this->assertEmpty($data);
133
-        $this->assertInternalType('array', $data);
134
-    }
135
-
136
-    public function testGetActivitiesRange()
137
-    {
138
-        $testData = [
139
-            [
140
-                'id' => rand(1, 100),
141
-                'message' => 'test one',
142
-            ],
143
-            [
144
-                'id' => rand(101, 200),
145
-                'message' => 'test two',
146
-            ],
147
-            [
148
-                'id' => rand(201, 300),
149
-                'message' => 'test three',
150
-            ],
151
-        ];
152
-
153
-        array_walk($testData, [$this, 'insertData']);
154
-
155
-        $repository = new MysqlActivityRepository(self::$connection);
156
-        $data = $repository->getActivities(2, 1);
157
-
158
-        $this->assertNotFalse($data);
159
-        $this->assertInternalType('array', $data);
160
-        $this->assertCount(2, $data);
161
-
162
-        $testData = array_slice($testData, 1, 2);
163
-
164
-        foreach ($testData as $key => $testRow) {
165
-            $this->assertInternalType('array', $data[$key]);
166
-            $this->assertArraySubset($testRow, $data[$key]);
167
-        }
168
-    }
169
-
170
-    public function testGetActivitiesRangeFailure()
171
-    {
172
-        $testData = [
173
-            [
174
-                'id' => rand(1, 100),
175
-                'message' => 'test one',
176
-            ],
177
-            [
178
-                'id' => rand(101, 200),
179
-                'message' => 'test two',
180
-            ],
181
-        ];
182
-
183
-        array_walk($testData, [$this, 'insertData']);
184
-
185
-        $repository = new MysqlActivityRepository(self::$connection);
186
-        $data = $repository->getActivities(1, 3);
187
-
188
-        $this->assertEmpty($data);
189
-        $this->assertInternalType('array', $data);
190
-    }
191
-
192
-    public function testGetActivitiesCount()
193
-    {
194
-        $testData = [
195
-            [
196
-                'id' => rand(1, 100),
197
-                'message' => 'test one',
198
-            ],
199
-            [
200
-                'id' => rand(101, 200),
201
-                'message' => 'test two',
202
-            ],
203
-        ];
204
-
205
-        array_walk($testData, [$this, 'insertData']);
206
-
207
-        $repository = new MysqlActivityRepository(self::$connection);
208
-        $data = $repository->getActivitiesCount();
209
-
210
-        $this->assertNotFalse($data);
211
-        $this->assertStringMatchesFormat('%d', $data);
212
-        $this->assertEquals(count($testData), $data);
213
-    }
214
-
215
-    public function testGetActivitiesCountEmpty()
216
-    {
217
-        $repository = new MysqlActivityRepository(self::$connection);
218
-        $data = $repository->getActivitiesCount();
219
-
220
-        $this->assertNotFalse($data);
221
-        $this->assertStringMatchesFormat('%d', $data);
222
-        $this->assertEquals('0', $data);
223
-    }
224
-
225
-    public function testGetActivitiesByType()
226
-    {
227
-        $testData = [
228
-            [
229
-                'id' => rand(1, 100),
230
-                'message' => 'test one',
231
-                'type' => 'type one',
232
-            ],
233
-            [
234
-                'id' => rand(101, 200),
235
-                'message' => 'test two',
236
-                'type' => 'type two',
237
-            ],
238
-            [
239
-                'id' => rand(201, 300),
240
-                'message' => 'test three',
241
-                'type' => 'type one',
242
-            ],
243
-        ];
244
-
245
-        array_walk($testData, [$this, 'insertData']);
246
-
247
-        $repository = new MysqlActivityRepository(self::$connection);
248
-        $data = $repository->getActivitiesByType('type one');
249
-
250
-        $this->assertNotFalse($data);
251
-        $this->assertInternalType('array', $data);
252
-
253
-        $testData = array_filter($testData, function ($row) {
254
-            return ($row['type'] == 'type one');
255
-        });
256
-        $testData = array_values($testData);
257
-
258
-        foreach ($testData as $key => $testRow) {
259
-            $this->assertInternalType('array', $data[$key]);
260
-            $this->assertArraySubset($testRow, $data[$key]);
261
-        }
262
-    }
263
-
264
-    public function testGetActivitiesByTypeFailure()
265
-    {
266
-        $testData = [
267
-            [
268
-                'id' => rand(1, 100),
269
-                'message' => 'test one',
270
-                'type' => 'type one',
271
-            ],
272
-            [
273
-                'id' => rand(101, 200),
274
-                'message' => 'test two',
275
-                'type' => 'type one',
276
-            ],
277
-        ];
278
-
279
-        array_walk($testData, [$this, 'insertData']);
280
-
281
-        $repository = new MysqlActivityRepository(self::$connection);
282
-        $data = $repository->getActivitiesByType('type two');
283
-
284
-        $this->assertEmpty($data);
285
-        $this->assertInternalType('array', $data);
286
-    }
287
-
288
-    public function testGetActivitiesByTypeRange()
289
-    {
290
-        $testData = [
291
-            [
292
-                'id' => rand(1, 100),
293
-                'message' => 'test one',
294
-                'type' => 'type one',
295
-            ],
296
-            [
297
-                'id' => rand(101, 200),
298
-                'message' => 'test two',
299
-                'type' => 'type two',
300
-            ],
301
-            [
302
-                'id' => rand(201, 300),
303
-                'message' => 'test three',
304
-                'type' => 'type one',
305
-            ],
306
-            [
307
-                'id' => rand(301, 400),
308
-                'message' => 'test four',
309
-                'type' => 'type one',
310
-            ],
311
-        ];
312
-
313
-        array_walk($testData, [$this, 'insertData']);
314
-
315
-        $repository = new MysqlActivityRepository(self::$connection);
316
-        $data = $repository->getActivitiesByType('type one', 2, 1);
317
-
318
-        $this->assertNotFalse($data);
319
-        $this->assertInternalType('array', $data);
320
-        $this->assertCount(2, $data);
321
-
322
-        $testData = array_filter($testData, function ($row) {
323
-            return ($row['type'] == 'type one');
324
-        });
325
-        $testData = array_values($testData);
326
-        $testData = array_slice($testData, 1, 2);
327
-
328
-        foreach ($testData as $key => $testRow) {
329
-            $this->assertInternalType('array', $data[$key]);
330
-            $this->assertArraySubset($testRow, $data[$key]);
331
-        }
332
-    }
333
-
334
-    public function testGetActivitiesByTypeRangeFailure()
335
-    {
336
-        $testData = [
337
-            [
338
-                'id' => rand(1, 100),
339
-                'message' => 'test one',
340
-                'type' => 'type one',
341
-            ],
342
-            [
343
-                'id' => rand(101, 200),
344
-                'message' => 'test two',
345
-                'type' => 'type one',
346
-            ],
347
-            [
348
-                'id' => rand(201, 300),
349
-                'message' => 'test three',
350
-                'type' => 'type one',
351
-            ],
352
-        ];
353
-
354
-        array_walk($testData, [$this, 'insertData']);
355
-
356
-        $repository = new MysqlActivityRepository(self::$connection);
357
-        $data = $repository->getActivitiesByType('type two', 2, 1);
358
-
359
-        $this->assertEmpty($data);
360
-        $this->assertInternalType('array', $data);
361
-    }
362
-
363
-    public function testGetActivitiesByTypeCount()
364
-    {
365
-        $testData = [
366
-            [
367
-                'id' => rand(1, 100),
368
-                'message' => 'test one',
369
-                'type' => 'type one',
370
-            ],
371
-            [
372
-                'id' => rand(101, 200),
373
-                'message' => 'test two',
374
-                'type' => 'type two',
375
-            ],
376
-            [
377
-                'id' => rand(201, 300),
378
-                'message' => 'test three',
379
-                'type' => 'type one',
380
-            ],
381
-        ];
382
-
383
-        array_walk($testData, [$this, 'insertData']);
384
-
385
-        $repository = new MysqlActivityRepository(self::$connection);
386
-        $data = $repository->getActivitiesByTypeCount('type one');
387
-
388
-        $testData = array_filter($testData, function ($row) {
389
-            return ($row['type'] == 'type one');
390
-        });
391
-
392
-        $this->assertNotFalse($data);
393
-        $this->assertStringMatchesFormat('%d', $data);
394
-        $this->assertEquals(count($testData), $data);
395
-    }
396
-
397
-    public function testGetActivitiesByTypeCountEmpty()
398
-    {
399
-        $testData = [
400
-            [
401
-                'id' => rand(1, 100),
402
-                'message' => 'test one',
403
-                'type' => 'type one',
404
-            ],
405
-            [
406
-                'id' => rand(101, 200),
407
-                'message' => 'test two',
408
-                'type' => 'type one',
409
-            ],
410
-        ];
411
-
412
-        array_walk($testData, [$this, 'insertData']);
413
-
414
-        $repository = new MysqlActivityRepository(self::$connection);
415
-        $data = $repository->getActivitiesByTypeCount('type two');
416
-
417
-        $this->assertNotFalse($data);
418
-        $this->assertStringMatchesFormat('%d', $data);
419
-        $this->assertEquals('0', $data);
420
-    }
421
-
422
-    protected function tearDown()
423
-    {
424
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_stream`.`activity`");
425
-    }
426
-
427
-    public static function tearDownAfterClass()
428
-    {
429
-        self::$connection->getDefault()->disconnect();
430
-        unlink('jpemeric_stream.db');
431
-    }
432
-
433
-    protected function insertData(array $data)
434
-    {
435
-        $defaultData = [
436
-            'id' => null,
437
-            'message' => '',
438
-            'message_long' => '',
439
-            'datetime' => '',
440
-            'metadata' => '',
441
-            'type' => '',
442
-            'type_id' => '',
443
-        ];
444
-
445
-        $data = array_merge($defaultData, $data);
446
-
447
-        return self::$connection->getDefault()->perform("
31
+		);
32
+
33
+		self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
34
+			return $extendedPdo;
35
+		});
36
+	}
37
+
38
+	public function testIsInstanceOfActivityRepository()
39
+	{
40
+		$repository = new MysqlActivityRepository(self::$connection);
41
+
42
+		$this->assertInstanceOf(
43
+			'Jacobemerick\Web\Domain\Stream\Activity\MysqlActivityRepository',
44
+			$repository
45
+		);
46
+	}
47
+
48
+	public function testImplementsActivityInterface()
49
+	{
50
+		$repository = new MysqlActivityRepository(self::$connection);
51
+
52
+		$this->assertInstanceOf(
53
+			'Jacobemerick\Web\Domain\Stream\Activity\ActivityRepositoryInterface',
54
+			$repository
55
+		);
56
+	}
57
+
58
+	public function testConstructSetsConnections()
59
+	{
60
+		$respository = new MysqlActivityRepository(self::$connection);
61
+
62
+		$this->assertAttributeSame(
63
+			self::$connection,
64
+			'connections',
65
+			$respository
66
+		);
67
+	}
68
+
69
+	public function testGetActivityById()
70
+	{
71
+		$testData = [
72
+			'id' => rand(1, 100),
73
+			'message' => 'test data',
74
+		];
75
+
76
+		$this->insertData($testData);
77
+
78
+		$repository = new MysqlActivityRepository(self::$connection);
79
+		$data = $repository->getActivityById($testData['id']);
80
+
81
+		$this->assertNotFalse($data);
82
+		$this->assertInternalType('array', $data);
83
+		$this->assertArraySubset($testData, $data);
84
+	}
85
+
86
+	public function testGetActivityByIdFailure()
87
+	{
88
+		$testData = [
89
+			'id' => rand(1, 100),
90
+			'message' => 'test data',
91
+		];
92
+
93
+		$this->insertData($testData);
94
+
95
+		$repository = new MysqlActivityRepository(self::$connection);
96
+		$data = $repository->getActivityById($testData['id'] + 1);
97
+
98
+		$this->assertFalse($data);
99
+	}
100
+
101
+	public function testGetActivities()
102
+	{
103
+		$testData = [
104
+			[
105
+				'id' => rand(1, 100),
106
+				'message' => 'test one',
107
+			],
108
+			[
109
+				'id' => rand(101, 200),
110
+				'message' => 'test two',
111
+			],
112
+		];
113
+
114
+		array_walk($testData, [$this, 'insertData']);
115
+
116
+		$repository = new MysqlActivityRepository(self::$connection);
117
+		$data = $repository->getActivities();
118
+
119
+		$this->assertNotFalse($data);
120
+		$this->assertInternalType('array', $data);
121
+		foreach ($testData as $key => $testRow) {
122
+			$this->assertInternalType('array', $data[$key]);
123
+			$this->assertArraySubset($testRow, $data[$key]);
124
+		}
125
+	}
126
+
127
+	public function testGetActivitiesFailure()
128
+	{
129
+		$repository = new MysqlActivityRepository(self::$connection);
130
+		$data = $repository->getActivities();
131
+
132
+		$this->assertEmpty($data);
133
+		$this->assertInternalType('array', $data);
134
+	}
135
+
136
+	public function testGetActivitiesRange()
137
+	{
138
+		$testData = [
139
+			[
140
+				'id' => rand(1, 100),
141
+				'message' => 'test one',
142
+			],
143
+			[
144
+				'id' => rand(101, 200),
145
+				'message' => 'test two',
146
+			],
147
+			[
148
+				'id' => rand(201, 300),
149
+				'message' => 'test three',
150
+			],
151
+		];
152
+
153
+		array_walk($testData, [$this, 'insertData']);
154
+
155
+		$repository = new MysqlActivityRepository(self::$connection);
156
+		$data = $repository->getActivities(2, 1);
157
+
158
+		$this->assertNotFalse($data);
159
+		$this->assertInternalType('array', $data);
160
+		$this->assertCount(2, $data);
161
+
162
+		$testData = array_slice($testData, 1, 2);
163
+
164
+		foreach ($testData as $key => $testRow) {
165
+			$this->assertInternalType('array', $data[$key]);
166
+			$this->assertArraySubset($testRow, $data[$key]);
167
+		}
168
+	}
169
+
170
+	public function testGetActivitiesRangeFailure()
171
+	{
172
+		$testData = [
173
+			[
174
+				'id' => rand(1, 100),
175
+				'message' => 'test one',
176
+			],
177
+			[
178
+				'id' => rand(101, 200),
179
+				'message' => 'test two',
180
+			],
181
+		];
182
+
183
+		array_walk($testData, [$this, 'insertData']);
184
+
185
+		$repository = new MysqlActivityRepository(self::$connection);
186
+		$data = $repository->getActivities(1, 3);
187
+
188
+		$this->assertEmpty($data);
189
+		$this->assertInternalType('array', $data);
190
+	}
191
+
192
+	public function testGetActivitiesCount()
193
+	{
194
+		$testData = [
195
+			[
196
+				'id' => rand(1, 100),
197
+				'message' => 'test one',
198
+			],
199
+			[
200
+				'id' => rand(101, 200),
201
+				'message' => 'test two',
202
+			],
203
+		];
204
+
205
+		array_walk($testData, [$this, 'insertData']);
206
+
207
+		$repository = new MysqlActivityRepository(self::$connection);
208
+		$data = $repository->getActivitiesCount();
209
+
210
+		$this->assertNotFalse($data);
211
+		$this->assertStringMatchesFormat('%d', $data);
212
+		$this->assertEquals(count($testData), $data);
213
+	}
214
+
215
+	public function testGetActivitiesCountEmpty()
216
+	{
217
+		$repository = new MysqlActivityRepository(self::$connection);
218
+		$data = $repository->getActivitiesCount();
219
+
220
+		$this->assertNotFalse($data);
221
+		$this->assertStringMatchesFormat('%d', $data);
222
+		$this->assertEquals('0', $data);
223
+	}
224
+
225
+	public function testGetActivitiesByType()
226
+	{
227
+		$testData = [
228
+			[
229
+				'id' => rand(1, 100),
230
+				'message' => 'test one',
231
+				'type' => 'type one',
232
+			],
233
+			[
234
+				'id' => rand(101, 200),
235
+				'message' => 'test two',
236
+				'type' => 'type two',
237
+			],
238
+			[
239
+				'id' => rand(201, 300),
240
+				'message' => 'test three',
241
+				'type' => 'type one',
242
+			],
243
+		];
244
+
245
+		array_walk($testData, [$this, 'insertData']);
246
+
247
+		$repository = new MysqlActivityRepository(self::$connection);
248
+		$data = $repository->getActivitiesByType('type one');
249
+
250
+		$this->assertNotFalse($data);
251
+		$this->assertInternalType('array', $data);
252
+
253
+		$testData = array_filter($testData, function ($row) {
254
+			return ($row['type'] == 'type one');
255
+		});
256
+		$testData = array_values($testData);
257
+
258
+		foreach ($testData as $key => $testRow) {
259
+			$this->assertInternalType('array', $data[$key]);
260
+			$this->assertArraySubset($testRow, $data[$key]);
261
+		}
262
+	}
263
+
264
+	public function testGetActivitiesByTypeFailure()
265
+	{
266
+		$testData = [
267
+			[
268
+				'id' => rand(1, 100),
269
+				'message' => 'test one',
270
+				'type' => 'type one',
271
+			],
272
+			[
273
+				'id' => rand(101, 200),
274
+				'message' => 'test two',
275
+				'type' => 'type one',
276
+			],
277
+		];
278
+
279
+		array_walk($testData, [$this, 'insertData']);
280
+
281
+		$repository = new MysqlActivityRepository(self::$connection);
282
+		$data = $repository->getActivitiesByType('type two');
283
+
284
+		$this->assertEmpty($data);
285
+		$this->assertInternalType('array', $data);
286
+	}
287
+
288
+	public function testGetActivitiesByTypeRange()
289
+	{
290
+		$testData = [
291
+			[
292
+				'id' => rand(1, 100),
293
+				'message' => 'test one',
294
+				'type' => 'type one',
295
+			],
296
+			[
297
+				'id' => rand(101, 200),
298
+				'message' => 'test two',
299
+				'type' => 'type two',
300
+			],
301
+			[
302
+				'id' => rand(201, 300),
303
+				'message' => 'test three',
304
+				'type' => 'type one',
305
+			],
306
+			[
307
+				'id' => rand(301, 400),
308
+				'message' => 'test four',
309
+				'type' => 'type one',
310
+			],
311
+		];
312
+
313
+		array_walk($testData, [$this, 'insertData']);
314
+
315
+		$repository = new MysqlActivityRepository(self::$connection);
316
+		$data = $repository->getActivitiesByType('type one', 2, 1);
317
+
318
+		$this->assertNotFalse($data);
319
+		$this->assertInternalType('array', $data);
320
+		$this->assertCount(2, $data);
321
+
322
+		$testData = array_filter($testData, function ($row) {
323
+			return ($row['type'] == 'type one');
324
+		});
325
+		$testData = array_values($testData);
326
+		$testData = array_slice($testData, 1, 2);
327
+
328
+		foreach ($testData as $key => $testRow) {
329
+			$this->assertInternalType('array', $data[$key]);
330
+			$this->assertArraySubset($testRow, $data[$key]);
331
+		}
332
+	}
333
+
334
+	public function testGetActivitiesByTypeRangeFailure()
335
+	{
336
+		$testData = [
337
+			[
338
+				'id' => rand(1, 100),
339
+				'message' => 'test one',
340
+				'type' => 'type one',
341
+			],
342
+			[
343
+				'id' => rand(101, 200),
344
+				'message' => 'test two',
345
+				'type' => 'type one',
346
+			],
347
+			[
348
+				'id' => rand(201, 300),
349
+				'message' => 'test three',
350
+				'type' => 'type one',
351
+			],
352
+		];
353
+
354
+		array_walk($testData, [$this, 'insertData']);
355
+
356
+		$repository = new MysqlActivityRepository(self::$connection);
357
+		$data = $repository->getActivitiesByType('type two', 2, 1);
358
+
359
+		$this->assertEmpty($data);
360
+		$this->assertInternalType('array', $data);
361
+	}
362
+
363
+	public function testGetActivitiesByTypeCount()
364
+	{
365
+		$testData = [
366
+			[
367
+				'id' => rand(1, 100),
368
+				'message' => 'test one',
369
+				'type' => 'type one',
370
+			],
371
+			[
372
+				'id' => rand(101, 200),
373
+				'message' => 'test two',
374
+				'type' => 'type two',
375
+			],
376
+			[
377
+				'id' => rand(201, 300),
378
+				'message' => 'test three',
379
+				'type' => 'type one',
380
+			],
381
+		];
382
+
383
+		array_walk($testData, [$this, 'insertData']);
384
+
385
+		$repository = new MysqlActivityRepository(self::$connection);
386
+		$data = $repository->getActivitiesByTypeCount('type one');
387
+
388
+		$testData = array_filter($testData, function ($row) {
389
+			return ($row['type'] == 'type one');
390
+		});
391
+
392
+		$this->assertNotFalse($data);
393
+		$this->assertStringMatchesFormat('%d', $data);
394
+		$this->assertEquals(count($testData), $data);
395
+	}
396
+
397
+	public function testGetActivitiesByTypeCountEmpty()
398
+	{
399
+		$testData = [
400
+			[
401
+				'id' => rand(1, 100),
402
+				'message' => 'test one',
403
+				'type' => 'type one',
404
+			],
405
+			[
406
+				'id' => rand(101, 200),
407
+				'message' => 'test two',
408
+				'type' => 'type one',
409
+			],
410
+		];
411
+
412
+		array_walk($testData, [$this, 'insertData']);
413
+
414
+		$repository = new MysqlActivityRepository(self::$connection);
415
+		$data = $repository->getActivitiesByTypeCount('type two');
416
+
417
+		$this->assertNotFalse($data);
418
+		$this->assertStringMatchesFormat('%d', $data);
419
+		$this->assertEquals('0', $data);
420
+	}
421
+
422
+	protected function tearDown()
423
+	{
424
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_stream`.`activity`");
425
+	}
426
+
427
+	public static function tearDownAfterClass()
428
+	{
429
+		self::$connection->getDefault()->disconnect();
430
+		unlink('jpemeric_stream.db');
431
+	}
432
+
433
+	protected function insertData(array $data)
434
+	{
435
+		$defaultData = [
436
+			'id' => null,
437
+			'message' => '',
438
+			'message_long' => '',
439
+			'datetime' => '',
440
+			'metadata' => '',
441
+			'type' => '',
442
+			'type_id' => '',
443
+		];
444
+
445
+		$data = array_merge($defaultData, $data);
446
+
447
+		return self::$connection->getDefault()->perform("
448 448
             INSERT INTO `jpemeric_stream`.`activity`
449 449
                 (id, message, message_long, datetime, metadata, type, type_id)
450 450
             VALUES
451 451
                 (:id, :message, :message_long, :datetime, :metadata, :type, :type_id)",
452
-            $data
453
-        );
454
-    }
452
+			$data
453
+		);
454
+	}
455 455
 }
Please login to merge, or discard this patch.
tests/unit/Domain/Stream/Changelog/MysqlChangelogRepositoryTest.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
             )"
30 30
         );
31 31
 
32
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
32
+        self::$connection = new ConnectionLocator(function() use ($extendedPdo) {
33 33
             return $extendedPdo;
34 34
         });
35 35
     }
Please login to merge, or discard this patch.
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -9,14 +9,14 @@  discard block
 block discarded – undo
9 9
 class MysqlChangelogRepositoryTest extends PHPUnit_Framework_TestCase
10 10
 {
11 11
 
12
-    protected static $connection;
12
+	protected static $connection;
13 13
 
14
-    public static function setUpBeforeClass()
15
-    {
16
-        $extendedPdo = new ExtendedPdo('sqlite::memory:');
17
-        $extendedPdo->exec("ATTACH DATABASE `jpemeric_stream.db` AS `jpemeric_stream`");
14
+	public static function setUpBeforeClass()
15
+	{
16
+		$extendedPdo = new ExtendedPdo('sqlite::memory:');
17
+		$extendedPdo->exec("ATTACH DATABASE `jpemeric_stream.db` AS `jpemeric_stream`");
18 18
 
19
-        $extendedPdo->exec("
19
+		$extendedPdo->exec("
20 20
             CREATE TABLE IF NOT EXISTS `jpemeric_stream`.`changelog` (
21 21
                 `id` integer PRIMARY KEY AUTOINCREMENT,
22 22
                 `hash` char(40) NOT NULL,
@@ -28,171 +28,171 @@  discard block
 block discarded – undo
28 28
                 `created_at` datetime,
29 29
                 `updated_at` datetime
30 30
             )"
31
-        );
32
-
33
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
34
-            return $extendedPdo;
35
-        });
36
-    }
37
-
38
-    public function testIsInstanceOfChangelogRepository()
39
-    {
40
-        $repository = new MysqlChangelogRepository(self::$connection);
41
-
42
-        $this->assertInstanceOf(
43
-            'Jacobemerick\Web\Domain\Stream\Changelog\MysqlChangelogRepository',
44
-            $repository
45
-        );
46
-    }
47
-
48
-    public function testImplementsChangelogInterface()
49
-    {
50
-        $repository = new MysqlChangelogRepository(self::$connection);
51
-
52
-        $this->assertInstanceOf(
53
-            'Jacobemerick\Web\Domain\Stream\Changelog\ChangelogRepositoryInterface',
54
-            $repository
55
-        );
56
-    }
57
-
58
-    public function testConstructSetsConnections()
59
-    {
60
-        $respository = new MysqlChangelogRepository(self::$connection);
61
-
62
-        $this->assertAttributeSame(
63
-            self::$connection,
64
-            'connections',
65
-            $respository
66
-        );
67
-    }
68
-
69
-    public function testGetChanges()
70
-    {
71
-        $testData = [
72
-            [
73
-                'id' => rand(1, 100),
74
-                'message' => 'test one',
75
-            ],
76
-            [
77
-                'id' => rand(101, 200),
78
-                'message' => 'test two',
79
-            ],
80
-        ];
81
-
82
-        array_walk($testData, [$this, 'insertData']);
83
-
84
-        $repository = new MysqlChangelogRepository(self::$connection);
85
-        $data = $repository->getChanges();
86
-
87
-        $this->assertNotFalse($data);
88
-        $this->assertInternalType('array', $data);
89
-        foreach ($testData as $key => $testRow) {
90
-            $this->assertInternalType('array', $data[$key]);
91
-            $this->assertArraySubset($testRow, $data[$key]);
92
-            $this->assertArrayHasKey('id', $data[$key]);
93
-            $this->assertArrayHasKey('message', $data[$key]);
94
-            $this->assertArrayHasKey('message_short', $data[$key]);
95
-            $this->assertArrayHasKey('datetime', $data[$key]);
96
-            $this->assertArrayHasKey('commit_link', $data[$key]);
97
-        }
98
-    }
99
-
100
-    public function testGetChangesFailure()
101
-    {
102
-        $repository = new MysqlChangelogRepository(self::$connection);
103
-        $data = $repository->getChanges();
104
-
105
-        $this->assertEmpty($data);
106
-        $this->assertInternalType('array', $data);
107
-    }
108
-
109
-    public function testGetChangesRange()
110
-    {
111
-        $testData = [
112
-            [
113
-                'id' => rand(1, 100),
114
-                'message' => 'test one',
115
-            ],
116
-            [
117
-                'id' => rand(101, 200),
118
-                'message' => 'test two',
119
-            ],
120
-            [
121
-                'id' => rand(201, 300),
122
-                'message' => 'test three',
123
-            ],
124
-        ];
125
-
126
-        array_walk($testData, [$this, 'insertData']);
127
-
128
-        $repository = new MysqlChangelogRepository(self::$connection);
129
-        $data = $repository->getChanges(2, 1);
130
-
131
-        $this->assertNotFalse($data);
132
-        $this->assertInternalType('array', $data);
133
-        $this->assertCount(2, $data);
134
-
135
-        $testData = array_slice($testData, 1, 2);
136
-
137
-        foreach ($testData as $key => $testRow) {
138
-            $this->assertInternalType('array', $testRow);
139
-            $this->assertArraySubset($testRow, $data[$key]);
140
-        }
141
-    }
142
-
143
-    public function testGetChangesRangeFailure()
144
-    {
145
-        $testData = [
146
-            [
147
-                'id' => rand(1, 100),
148
-                'message' => 'test one',
149
-            ],
150
-            [
151
-                'id' => rand(101, 200),
152
-                'message' => 'test two',
153
-            ],
154
-        ];
155
-
156
-        array_walk($testData, [$this, 'insertData']);
157
-
158
-        $repository = new MysqlChangelogRepository(self::$connection);
159
-        $data = $repository->getChanges(1, 3);
160
-
161
-        $this->assertEmpty($data);
162
-        $this->assertInternalType('array', $data);
163
-    }
164
-
165
-    protected function tearDown()
166
-    {
167
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_stream`.`changelog`");
168
-    }
169
-
170
-    public static function tearDownAfterClass()
171
-    {
172
-        self::$connection->getDefault()->disconnect();
173
-        unlink('jpemeric_stream.db');
174
-    }
175
-
176
-    protected function insertData(array $data)
177
-    {
178
-        $defaultData = [
179
-            'id' => null,
180
-            'hash' => '',
181
-            'message' => null,
182
-            'message_short' => null,
183
-            'datetime' => '',
184
-            'author' => '',
185
-            'commit_link' => '',
186
-        ];
187
-
188
-        $data = array_merge($defaultData, $data);
189
-
190
-        return self::$connection->getDefault()->perform("
31
+		);
32
+
33
+		self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
34
+			return $extendedPdo;
35
+		});
36
+	}
37
+
38
+	public function testIsInstanceOfChangelogRepository()
39
+	{
40
+		$repository = new MysqlChangelogRepository(self::$connection);
41
+
42
+		$this->assertInstanceOf(
43
+			'Jacobemerick\Web\Domain\Stream\Changelog\MysqlChangelogRepository',
44
+			$repository
45
+		);
46
+	}
47
+
48
+	public function testImplementsChangelogInterface()
49
+	{
50
+		$repository = new MysqlChangelogRepository(self::$connection);
51
+
52
+		$this->assertInstanceOf(
53
+			'Jacobemerick\Web\Domain\Stream\Changelog\ChangelogRepositoryInterface',
54
+			$repository
55
+		);
56
+	}
57
+
58
+	public function testConstructSetsConnections()
59
+	{
60
+		$respository = new MysqlChangelogRepository(self::$connection);
61
+
62
+		$this->assertAttributeSame(
63
+			self::$connection,
64
+			'connections',
65
+			$respository
66
+		);
67
+	}
68
+
69
+	public function testGetChanges()
70
+	{
71
+		$testData = [
72
+			[
73
+				'id' => rand(1, 100),
74
+				'message' => 'test one',
75
+			],
76
+			[
77
+				'id' => rand(101, 200),
78
+				'message' => 'test two',
79
+			],
80
+		];
81
+
82
+		array_walk($testData, [$this, 'insertData']);
83
+
84
+		$repository = new MysqlChangelogRepository(self::$connection);
85
+		$data = $repository->getChanges();
86
+
87
+		$this->assertNotFalse($data);
88
+		$this->assertInternalType('array', $data);
89
+		foreach ($testData as $key => $testRow) {
90
+			$this->assertInternalType('array', $data[$key]);
91
+			$this->assertArraySubset($testRow, $data[$key]);
92
+			$this->assertArrayHasKey('id', $data[$key]);
93
+			$this->assertArrayHasKey('message', $data[$key]);
94
+			$this->assertArrayHasKey('message_short', $data[$key]);
95
+			$this->assertArrayHasKey('datetime', $data[$key]);
96
+			$this->assertArrayHasKey('commit_link', $data[$key]);
97
+		}
98
+	}
99
+
100
+	public function testGetChangesFailure()
101
+	{
102
+		$repository = new MysqlChangelogRepository(self::$connection);
103
+		$data = $repository->getChanges();
104
+
105
+		$this->assertEmpty($data);
106
+		$this->assertInternalType('array', $data);
107
+	}
108
+
109
+	public function testGetChangesRange()
110
+	{
111
+		$testData = [
112
+			[
113
+				'id' => rand(1, 100),
114
+				'message' => 'test one',
115
+			],
116
+			[
117
+				'id' => rand(101, 200),
118
+				'message' => 'test two',
119
+			],
120
+			[
121
+				'id' => rand(201, 300),
122
+				'message' => 'test three',
123
+			],
124
+		];
125
+
126
+		array_walk($testData, [$this, 'insertData']);
127
+
128
+		$repository = new MysqlChangelogRepository(self::$connection);
129
+		$data = $repository->getChanges(2, 1);
130
+
131
+		$this->assertNotFalse($data);
132
+		$this->assertInternalType('array', $data);
133
+		$this->assertCount(2, $data);
134
+
135
+		$testData = array_slice($testData, 1, 2);
136
+
137
+		foreach ($testData as $key => $testRow) {
138
+			$this->assertInternalType('array', $testRow);
139
+			$this->assertArraySubset($testRow, $data[$key]);
140
+		}
141
+	}
142
+
143
+	public function testGetChangesRangeFailure()
144
+	{
145
+		$testData = [
146
+			[
147
+				'id' => rand(1, 100),
148
+				'message' => 'test one',
149
+			],
150
+			[
151
+				'id' => rand(101, 200),
152
+				'message' => 'test two',
153
+			],
154
+		];
155
+
156
+		array_walk($testData, [$this, 'insertData']);
157
+
158
+		$repository = new MysqlChangelogRepository(self::$connection);
159
+		$data = $repository->getChanges(1, 3);
160
+
161
+		$this->assertEmpty($data);
162
+		$this->assertInternalType('array', $data);
163
+	}
164
+
165
+	protected function tearDown()
166
+	{
167
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_stream`.`changelog`");
168
+	}
169
+
170
+	public static function tearDownAfterClass()
171
+	{
172
+		self::$connection->getDefault()->disconnect();
173
+		unlink('jpemeric_stream.db');
174
+	}
175
+
176
+	protected function insertData(array $data)
177
+	{
178
+		$defaultData = [
179
+			'id' => null,
180
+			'hash' => '',
181
+			'message' => null,
182
+			'message_short' => null,
183
+			'datetime' => '',
184
+			'author' => '',
185
+			'commit_link' => '',
186
+		];
187
+
188
+		$data = array_merge($defaultData, $data);
189
+
190
+		return self::$connection->getDefault()->perform("
191 191
             INSERT INTO `jpemeric_stream`.`changelog`
192 192
                 (id, hash, message, message_short, datetime, author, commit_link)
193 193
             VALUES
194 194
                 (:id, :hash, :message, :message_short, :datetime, :author, :commit_link)",
195
-            $data
196
-        );
197
-    }
195
+			$data
196
+		);
197
+	}
198 198
 }
Please login to merge, or discard this patch.
tests/unit/Domain/Blog/Series/MysqlSeriesRepositoryTest.php 2 patches
Indentation   +352 added lines, -352 removed lines patch added patch discarded remove patch
@@ -9,14 +9,14 @@  discard block
 block discarded – undo
9 9
 class MysqlSeriesRepositoryTest extends PHPUnit_Framework_TestCase
10 10
 {
11 11
 
12
-    protected static $connection;
12
+	protected static $connection;
13 13
 
14
-    public static function setUpBeforeClass()
15
-    {
16
-        $extendedPdo = new ExtendedPdo('sqlite::memory:');
17
-        $extendedPdo->exec("ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`");
14
+	public static function setUpBeforeClass()
15
+	{
16
+		$extendedPdo = new ExtendedPdo('sqlite::memory:');
17
+		$extendedPdo->exec("ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`");
18 18
 
19
-        $extendedPdo->exec("
19
+		$extendedPdo->exec("
20 20
             CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`post` (
21 21
                 `id` integer PRIMARY KEY AUTOINCREMENT,
22 22
                 `title` varchar(60) NOT NULL,
@@ -26,380 +26,380 @@  discard block
 block discarded – undo
26 26
                 `body` text,
27 27
                 `display` integer(1) NOT NULL
28 28
             )"
29
-        );
30
-        $extendedPdo->exec("
29
+		);
30
+		$extendedPdo->exec("
31 31
             CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`series` (
32 32
                 `id` integer PRIMARY KEY AUTOINCREMENT,
33 33
                 `title` text NOT NULL,
34 34
                 `description` text NOT NULL
35 35
             )"
36
-        );
37
-        $extendedPdo->exec("
36
+		);
37
+		$extendedPdo->exec("
38 38
             CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`series_post` (
39 39
                 `series` integer NOT NULL,
40 40
                 `post` integer NOT NULL,
41 41
                 `order` integer(1) NOT NULL
42 42
             )"
43
-        );
44
-
45
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
46
-            return $extendedPdo;
47
-        });
48
-    }
49
-
50
-    public function testIsInstanceOfSeriesRepository()
51
-    {
52
-        $repository = new MysqlSeriesRepository(self::$connection);
53
-
54
-        $this->assertInstanceOf(
55
-            'Jacobemerick\Web\Domain\Blog\Series\MysqlSeriesRepository',
56
-            $repository
57
-        );
58
-    }
59
-
60
-    public function testImplementsSeriesInterface()
61
-    {
62
-        $repository = new MysqlSeriesRepository(self::$connection);
63
-
64
-        $this->assertInstanceOf(
65
-            'Jacobemerick\Web\Domain\Blog\Series\SeriesRepositoryInterface',
66
-            $repository
67
-        );
68
-    }
69
-
70
-    public function testConstructSetsConnections()
71
-    {
72
-        $respository = new MysqlSeriesRepository(self::$connection);
73
-
74
-        $this->assertAttributeSame(
75
-            self::$connection,
76
-            'connections',
77
-            $respository
78
-        );
79
-    }
80
-
81
-    public function testGetSeriesForPost()
82
-    {
83
-        $testPostData = [
84
-            [
85
-                'id' => rand(1, 100),
86
-                'title' => 'test one',
87
-                'category' => 'test category',
88
-                'path' => 'test-one',
89
-                'display' => 1,
90
-            ],
91
-            [
92
-                'id' => rand(101, 200),
93
-                'title' => 'test two',
94
-                'category' => 'test category',
95
-                'path' => 'test-two',
96
-                'display' => 1,
97
-            ],
98
-        ];
99
-
100
-        $testSeriesData = [
101
-            [
102
-                'id' => rand(1, 100),
103
-                'title' => 'test one',
104
-                'description' => 'test description',
105
-            ],
106
-        ];
107
-
108
-        $testSeriesPostData = [];
109
-        foreach ($testPostData as $testPostDataRow) {
110
-            array_push($testSeriesPostData, [
111
-                'series' => reset($testSeriesData)['id'],
112
-                'post' => $testPostDataRow['id'],
113
-            ]);
114
-        }
115
-
116
-        array_walk($testPostData, [$this, 'insertPostData']);
117
-        array_walk($testSeriesData, [$this, 'insertSeriesData']);
118
-        array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
119
-
120
-        $repository = new MysqlSeriesRepository(self::$connection);
121
-        $data = $repository->getSeriesForPost(reset($testPostData)['id']);
122
-
123
-        $this->assertNotFalse($data);
124
-        $this->assertInternalType('array', $data);
125
-        foreach ($testPostData as $key => $testPostRow) {
126
-            $this->assertInternalType('array', $data[$key]);
127
-            $this->assertArrayHasKey('series_title', $data[$key]);
128
-            $this->assertEquals(reset($testSeriesData)['title'], $data[$key]['series_title']);
129
-            $this->assertArrayHasKey('series_description', $data[$key]);
130
-            $this->assertEquals(reset($testSeriesData)['description'], $data[$key]['series_description']);
131
-            $this->assertArrayHasKey('post', $data[$key]);
132
-            $this->assertEquals($testPostRow['id'], $data[$key]['post']);
133
-            $this->assertArrayHasKey('title', $data[$key]);
134
-            $this->assertEquals($testPostRow['title'], $data[$key]['title']);
135
-            $this->assertArrayHasKey('category', $data[$key]);
136
-            $this->assertEquals($testPostRow['category'], $data[$key]['category']);
137
-            $this->assertArrayHasKey('path', $data[$key]);
138
-            $this->assertEquals($testPostRow['path'], $data[$key]['path']);
139
-        }
140
-    }
141
-
142
-    public function testGetSeriesForPostOrder()
143
-    {
144
-        $testPostData = [
145
-            [
146
-                'id' => rand(1, 100),
147
-                'display' => 1,
148
-            ],
149
-            [
150
-                'id' => rand(101, 200),
151
-                'display' => 1,
152
-            ],
153
-            [
154
-                'id' => rand(201, 300),
155
-                'display' => 1,
156
-            ],
157
-        ];
158
-
159
-        $testSeriesData = [
160
-            [
161
-                'id' => rand(1, 100),
162
-            ],
163
-        ];
164
-
165
-        $order = [1, 2, 3];
166
-        shuffle($order);
167
-        $testSeriesPostData = [];
168
-        foreach ($testPostData as $key => $testPostDataRow) {
169
-            array_push($testSeriesPostData, [
170
-                'series' => reset($testSeriesData)['id'],
171
-                'post' => $testPostDataRow['id'],
172
-                'order' => $order[$key],
173
-            ]);
174
-        }
175
-
176
-        array_walk($testPostData, [$this, 'insertPostData']);
177
-        array_walk($testSeriesData, [$this, 'insertSeriesData']);
178
-        array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
179
-
180
-        $repository = new MysqlSeriesRepository(self::$connection);
181
-        $data = $repository->getSeriesForPost(reset($testPostData)['id']);
182
-
183
-        usort($testPostData, function ($rowA, $rowB) use ($testSeriesPostData) {
184
-            $seriesA = array_filter($testSeriesPostData, function ($row) use ($rowA) {
185
-                return ($rowA['id'] == $row['post']);
186
-            });
187
-            $seriesB = array_filter($testSeriesPostData, function ($row) use ($rowB) {
188
-                return ($rowB['id'] == $row['post']);
189
-            });
190
-
191
-            return (reset($seriesA)['order'] > reset($seriesB)['order']);
192
-        });
193
-
194
-        $this->assertNotFalse($data);
195
-        $this->assertInternalType('array', $data);
196
-        foreach ($testPostData as $key => $testPostRow) {
197
-            $this->assertInternalType('array', $data[$key]);
198
-            $this->assertArrayHasKey('post', $data[$key]);
199
-            $this->assertEquals($testPostRow['id'], $data[$key]['post']);
200
-        }
201
-    }
43
+		);
44
+
45
+		self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
46
+			return $extendedPdo;
47
+		});
48
+	}
49
+
50
+	public function testIsInstanceOfSeriesRepository()
51
+	{
52
+		$repository = new MysqlSeriesRepository(self::$connection);
53
+
54
+		$this->assertInstanceOf(
55
+			'Jacobemerick\Web\Domain\Blog\Series\MysqlSeriesRepository',
56
+			$repository
57
+		);
58
+	}
59
+
60
+	public function testImplementsSeriesInterface()
61
+	{
62
+		$repository = new MysqlSeriesRepository(self::$connection);
63
+
64
+		$this->assertInstanceOf(
65
+			'Jacobemerick\Web\Domain\Blog\Series\SeriesRepositoryInterface',
66
+			$repository
67
+		);
68
+	}
69
+
70
+	public function testConstructSetsConnections()
71
+	{
72
+		$respository = new MysqlSeriesRepository(self::$connection);
73
+
74
+		$this->assertAttributeSame(
75
+			self::$connection,
76
+			'connections',
77
+			$respository
78
+		);
79
+	}
80
+
81
+	public function testGetSeriesForPost()
82
+	{
83
+		$testPostData = [
84
+			[
85
+				'id' => rand(1, 100),
86
+				'title' => 'test one',
87
+				'category' => 'test category',
88
+				'path' => 'test-one',
89
+				'display' => 1,
90
+			],
91
+			[
92
+				'id' => rand(101, 200),
93
+				'title' => 'test two',
94
+				'category' => 'test category',
95
+				'path' => 'test-two',
96
+				'display' => 1,
97
+			],
98
+		];
99
+
100
+		$testSeriesData = [
101
+			[
102
+				'id' => rand(1, 100),
103
+				'title' => 'test one',
104
+				'description' => 'test description',
105
+			],
106
+		];
107
+
108
+		$testSeriesPostData = [];
109
+		foreach ($testPostData as $testPostDataRow) {
110
+			array_push($testSeriesPostData, [
111
+				'series' => reset($testSeriesData)['id'],
112
+				'post' => $testPostDataRow['id'],
113
+			]);
114
+		}
115
+
116
+		array_walk($testPostData, [$this, 'insertPostData']);
117
+		array_walk($testSeriesData, [$this, 'insertSeriesData']);
118
+		array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
119
+
120
+		$repository = new MysqlSeriesRepository(self::$connection);
121
+		$data = $repository->getSeriesForPost(reset($testPostData)['id']);
122
+
123
+		$this->assertNotFalse($data);
124
+		$this->assertInternalType('array', $data);
125
+		foreach ($testPostData as $key => $testPostRow) {
126
+			$this->assertInternalType('array', $data[$key]);
127
+			$this->assertArrayHasKey('series_title', $data[$key]);
128
+			$this->assertEquals(reset($testSeriesData)['title'], $data[$key]['series_title']);
129
+			$this->assertArrayHasKey('series_description', $data[$key]);
130
+			$this->assertEquals(reset($testSeriesData)['description'], $data[$key]['series_description']);
131
+			$this->assertArrayHasKey('post', $data[$key]);
132
+			$this->assertEquals($testPostRow['id'], $data[$key]['post']);
133
+			$this->assertArrayHasKey('title', $data[$key]);
134
+			$this->assertEquals($testPostRow['title'], $data[$key]['title']);
135
+			$this->assertArrayHasKey('category', $data[$key]);
136
+			$this->assertEquals($testPostRow['category'], $data[$key]['category']);
137
+			$this->assertArrayHasKey('path', $data[$key]);
138
+			$this->assertEquals($testPostRow['path'], $data[$key]['path']);
139
+		}
140
+	}
141
+
142
+	public function testGetSeriesForPostOrder()
143
+	{
144
+		$testPostData = [
145
+			[
146
+				'id' => rand(1, 100),
147
+				'display' => 1,
148
+			],
149
+			[
150
+				'id' => rand(101, 200),
151
+				'display' => 1,
152
+			],
153
+			[
154
+				'id' => rand(201, 300),
155
+				'display' => 1,
156
+			],
157
+		];
158
+
159
+		$testSeriesData = [
160
+			[
161
+				'id' => rand(1, 100),
162
+			],
163
+		];
164
+
165
+		$order = [1, 2, 3];
166
+		shuffle($order);
167
+		$testSeriesPostData = [];
168
+		foreach ($testPostData as $key => $testPostDataRow) {
169
+			array_push($testSeriesPostData, [
170
+				'series' => reset($testSeriesData)['id'],
171
+				'post' => $testPostDataRow['id'],
172
+				'order' => $order[$key],
173
+			]);
174
+		}
175
+
176
+		array_walk($testPostData, [$this, 'insertPostData']);
177
+		array_walk($testSeriesData, [$this, 'insertSeriesData']);
178
+		array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
179
+
180
+		$repository = new MysqlSeriesRepository(self::$connection);
181
+		$data = $repository->getSeriesForPost(reset($testPostData)['id']);
182
+
183
+		usort($testPostData, function ($rowA, $rowB) use ($testSeriesPostData) {
184
+			$seriesA = array_filter($testSeriesPostData, function ($row) use ($rowA) {
185
+				return ($rowA['id'] == $row['post']);
186
+			});
187
+			$seriesB = array_filter($testSeriesPostData, function ($row) use ($rowB) {
188
+				return ($rowB['id'] == $row['post']);
189
+			});
190
+
191
+			return (reset($seriesA)['order'] > reset($seriesB)['order']);
192
+		});
193
+
194
+		$this->assertNotFalse($data);
195
+		$this->assertInternalType('array', $data);
196
+		foreach ($testPostData as $key => $testPostRow) {
197
+			$this->assertInternalType('array', $data[$key]);
198
+			$this->assertArrayHasKey('post', $data[$key]);
199
+			$this->assertEquals($testPostRow['id'], $data[$key]['post']);
200
+		}
201
+	}
202 202
  
203
-    public function testGetSeriesForPostSeriesFilter()
204
-    {
205
-        $testPostAData = [
206
-            [
207
-                'id' => rand(1, 100),
208
-                'display' => 1,
209
-            ],
210
-            [
211
-                'id' => rand(101, 200),
212
-                'display' => 1,
213
-            ],
214
-        ];
215
-
216
-        $testPostBData = [
217
-            [
218
-                'id' => rand(501, 600),
219
-                'display' => 1,
220
-            ],
221
-            [
222
-                'id' => rand(601, 700),
223
-                'display' => 1,
224
-            ],
225
-        ];
226
-
227
-        $testSeriesData = [
228
-            [
229
-                'id' => rand(1, 100),
230
-            ],
231
-            [
232
-                'id' => rand(101, 200),
233
-            ],
234
-        ];
235
-
236
-        $testSeriesPostData = [];
237
-        foreach ($testPostAData as $testPostDataRow) {
238
-            array_push($testSeriesPostData, [
239
-                'series' => $testSeriesData[0]['id'],
240
-                'post' => $testPostDataRow['id'],
241
-            ]);
242
-        }
243
-        foreach ($testPostBData as $testPostDataRow) {
244
-            array_push($testSeriesPostData, [
245
-                'series' => $testSeriesData[1]['id'],
246
-                'post' => $testPostDataRow['id'],
247
-            ]);
248
-        }
249
-
250
-        $testPostData = array_merge($testPostAData, $testPostBData);
251
-        array_walk($testPostData, [$this, 'insertPostData']);
252
-        array_walk($testSeriesData, [$this, 'insertSeriesData']);
253
-        array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
254
-
255
-        $repository = new MysqlSeriesRepository(self::$connection);
256
-        $data = $repository->getSeriesForPost(reset($testPostAData)['id']);
257
-
258
-        $this->assertNotFalse($data);
259
-        $this->assertInternalType('array', $data);
260
-
261
-        $testPosts = array_column($testPostAData, 'id');
262
-        $dataPosts = array_column($data, 'post');
263
-
264
-        $this->assertEmpty(array_merge(
265
-            array_diff($testPosts, $dataPosts),
266
-            array_diff($dataPosts, $testPosts)
267
-        ));
268
-    }
203
+	public function testGetSeriesForPostSeriesFilter()
204
+	{
205
+		$testPostAData = [
206
+			[
207
+				'id' => rand(1, 100),
208
+				'display' => 1,
209
+			],
210
+			[
211
+				'id' => rand(101, 200),
212
+				'display' => 1,
213
+			],
214
+		];
215
+
216
+		$testPostBData = [
217
+			[
218
+				'id' => rand(501, 600),
219
+				'display' => 1,
220
+			],
221
+			[
222
+				'id' => rand(601, 700),
223
+				'display' => 1,
224
+			],
225
+		];
226
+
227
+		$testSeriesData = [
228
+			[
229
+				'id' => rand(1, 100),
230
+			],
231
+			[
232
+				'id' => rand(101, 200),
233
+			],
234
+		];
235
+
236
+		$testSeriesPostData = [];
237
+		foreach ($testPostAData as $testPostDataRow) {
238
+			array_push($testSeriesPostData, [
239
+				'series' => $testSeriesData[0]['id'],
240
+				'post' => $testPostDataRow['id'],
241
+			]);
242
+		}
243
+		foreach ($testPostBData as $testPostDataRow) {
244
+			array_push($testSeriesPostData, [
245
+				'series' => $testSeriesData[1]['id'],
246
+				'post' => $testPostDataRow['id'],
247
+			]);
248
+		}
249
+
250
+		$testPostData = array_merge($testPostAData, $testPostBData);
251
+		array_walk($testPostData, [$this, 'insertPostData']);
252
+		array_walk($testSeriesData, [$this, 'insertSeriesData']);
253
+		array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
254
+
255
+		$repository = new MysqlSeriesRepository(self::$connection);
256
+		$data = $repository->getSeriesForPost(reset($testPostAData)['id']);
257
+
258
+		$this->assertNotFalse($data);
259
+		$this->assertInternalType('array', $data);
260
+
261
+		$testPosts = array_column($testPostAData, 'id');
262
+		$dataPosts = array_column($data, 'post');
263
+
264
+		$this->assertEmpty(array_merge(
265
+			array_diff($testPosts, $dataPosts),
266
+			array_diff($dataPosts, $testPosts)
267
+		));
268
+	}
269 269
  
270
-    public function testGetSeriesForPostInactive()
271
-    {
272
-        $testPostData = [
273
-            [
274
-                'id' => rand(1, 100),
275
-                'display' => 1,
276
-            ],
277
-            [
278
-                'id' => rand(101, 200),
279
-                'display' => 0,
280
-            ],
281
-            [
282
-                'id' => rand(201, 300),
283
-                'display' => 0,
284
-            ],
285
-        ];
286
-
287
-        $testSeriesData = [
288
-            [
289
-                'id' => rand(1, 100),
290
-            ],
291
-        ];
292
-
293
-        $testSeriesPostData = [];
294
-        foreach ($testPostData as $testPostDataRow) {
295
-            array_push($testSeriesPostData, [
296
-                'series' => reset($testSeriesData)['id'],
297
-                'post' => $testPostDataRow['id'],
298
-            ]);
299
-        }
300
-
301
-        array_walk($testPostData, [$this, 'insertPostData']);
302
-        array_walk($testSeriesData, [$this, 'insertSeriesData']);
303
-        array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
304
-
305
-        $repository = new MysqlSeriesRepository(self::$connection);
306
-        $data = $repository->getSeriesForPost(reset($testPostData)['id']);
307
-
308
-        $this->assertNotFalse($data);
309
-        $this->assertInternalType('array', $data);
310
-
311
-        $testPostData = array_filter($testPostData, function ($row) {
312
-            return ($row['display'] == 1);
313
-        });
314
-        $testPosts = array_column($testPostData, 'id');
315
-        $dataPosts = array_column($data, 'post');
316
-
317
-        $this->assertEmpty(array_merge(
318
-            array_diff($testPosts, $dataPosts),
319
-            array_diff($dataPosts, $testPosts)
320
-        ));
321
-    }
322
-
323
-    public function testGetSeriesForPostFailure()
324
-    {
325
-        $repository = new MysqlSeriesRepository(self::$connection);
326
-        $data = $repository->getSeriesForPost(rand(1, 100));
327
-
328
-        $this->assertEmpty($data);
329
-        $this->assertInternalType('array', $data);
330
-    }
331
-
332
-    protected function tearDown()
333
-    {
334
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`post`");
335
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series`");
336
-        self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series_post`");
337
-    }
338
-
339
-    public static function tearDownAfterClass()
340
-    {
341
-        self::$connection->getDefault()->disconnect();
342
-        unlink('jpemeric_blog.db');
343
-    }
344
-
345
-    protected function insertPostData(array $data)
346
-    {
347
-        $defaultData = [
348
-            'id' => null,
349
-            'title' => '',
350
-            'path' => '',
351
-            'category' => '',
352
-            'date' => '',
353
-            'body' => '',
354
-            'display' => 0,
355
-        ];
356
-
357
-        $data = array_merge($defaultData, $data);
358
-
359
-        return self::$connection->getDefault()->perform("
270
+	public function testGetSeriesForPostInactive()
271
+	{
272
+		$testPostData = [
273
+			[
274
+				'id' => rand(1, 100),
275
+				'display' => 1,
276
+			],
277
+			[
278
+				'id' => rand(101, 200),
279
+				'display' => 0,
280
+			],
281
+			[
282
+				'id' => rand(201, 300),
283
+				'display' => 0,
284
+			],
285
+		];
286
+
287
+		$testSeriesData = [
288
+			[
289
+				'id' => rand(1, 100),
290
+			],
291
+		];
292
+
293
+		$testSeriesPostData = [];
294
+		foreach ($testPostData as $testPostDataRow) {
295
+			array_push($testSeriesPostData, [
296
+				'series' => reset($testSeriesData)['id'],
297
+				'post' => $testPostDataRow['id'],
298
+			]);
299
+		}
300
+
301
+		array_walk($testPostData, [$this, 'insertPostData']);
302
+		array_walk($testSeriesData, [$this, 'insertSeriesData']);
303
+		array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']);
304
+
305
+		$repository = new MysqlSeriesRepository(self::$connection);
306
+		$data = $repository->getSeriesForPost(reset($testPostData)['id']);
307
+
308
+		$this->assertNotFalse($data);
309
+		$this->assertInternalType('array', $data);
310
+
311
+		$testPostData = array_filter($testPostData, function ($row) {
312
+			return ($row['display'] == 1);
313
+		});
314
+		$testPosts = array_column($testPostData, 'id');
315
+		$dataPosts = array_column($data, 'post');
316
+
317
+		$this->assertEmpty(array_merge(
318
+			array_diff($testPosts, $dataPosts),
319
+			array_diff($dataPosts, $testPosts)
320
+		));
321
+	}
322
+
323
+	public function testGetSeriesForPostFailure()
324
+	{
325
+		$repository = new MysqlSeriesRepository(self::$connection);
326
+		$data = $repository->getSeriesForPost(rand(1, 100));
327
+
328
+		$this->assertEmpty($data);
329
+		$this->assertInternalType('array', $data);
330
+	}
331
+
332
+	protected function tearDown()
333
+	{
334
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`post`");
335
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series`");
336
+		self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series_post`");
337
+	}
338
+
339
+	public static function tearDownAfterClass()
340
+	{
341
+		self::$connection->getDefault()->disconnect();
342
+		unlink('jpemeric_blog.db');
343
+	}
344
+
345
+	protected function insertPostData(array $data)
346
+	{
347
+		$defaultData = [
348
+			'id' => null,
349
+			'title' => '',
350
+			'path' => '',
351
+			'category' => '',
352
+			'date' => '',
353
+			'body' => '',
354
+			'display' => 0,
355
+		];
356
+
357
+		$data = array_merge($defaultData, $data);
358
+
359
+		return self::$connection->getDefault()->perform("
360 360
             INSERT INTO `jpemeric_blog`.`post`
361 361
                 (id, title, path, category, date, body, display)
362 362
             VALUES
363 363
                 (:id, :title, :path, :category, :date, :body, :display)",
364
-            $data
365
-        );
366
-    }
364
+			$data
365
+		);
366
+	}
367 367
 
368
-    protected function insertSeriesData(array $data)
369
-    {
370
-        $defaultData = [
371
-            'id' => null,
372
-            'title' => '',
373
-            'description' => '',
374
-        ];
368
+	protected function insertSeriesData(array $data)
369
+	{
370
+		$defaultData = [
371
+			'id' => null,
372
+			'title' => '',
373
+			'description' => '',
374
+		];
375 375
 
376
-        $data = array_merge($defaultData, $data);
376
+		$data = array_merge($defaultData, $data);
377 377
 
378
-        return self::$connection->getDefault()->perform("
378
+		return self::$connection->getDefault()->perform("
379 379
             INSERT INTO `jpemeric_blog`.`series`
380 380
                 (id, title, description)
381 381
             VALUES
382 382
                 (:id, :title, :description)",
383
-            $data
384
-        );
385
-    }
383
+			$data
384
+		);
385
+	}
386 386
 
387
-    protected function insertSeriesPostData(array $data)
388
-    {
389
-        $defaultData = [
390
-            'series' => '',
391
-            'post' => '',
392
-            'order' => 0,
393
-        ];
387
+	protected function insertSeriesPostData(array $data)
388
+	{
389
+		$defaultData = [
390
+			'series' => '',
391
+			'post' => '',
392
+			'order' => 0,
393
+		];
394 394
 
395
-        $data = array_merge($defaultData, $data);
395
+		$data = array_merge($defaultData, $data);
396 396
 
397
-        return self::$connection->getDefault()->perform("
397
+		return self::$connection->getDefault()->perform("
398 398
             INSERT INTO `jpemeric_blog`.`series_post`
399 399
                 (series, post, `order`)
400 400
             VALUES
401 401
                 (:series, :post, :order)",
402
-            $data
403
-        );
404
-    }
402
+			$data
403
+		);
404
+	}
405 405
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
             )"
43 43
         );
44 44
 
45
-        self::$connection = new ConnectionLocator(function () use ($extendedPdo) {
45
+        self::$connection = new ConnectionLocator(function() use ($extendedPdo) {
46 46
             return $extendedPdo;
47 47
         });
48 48
     }
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
         $repository = new MysqlSeriesRepository(self::$connection);
181 181
         $data = $repository->getSeriesForPost(reset($testPostData)['id']);
182 182
 
183
-        usort($testPostData, function ($rowA, $rowB) use ($testSeriesPostData) {
184
-            $seriesA = array_filter($testSeriesPostData, function ($row) use ($rowA) {
183
+        usort($testPostData, function($rowA, $rowB) use ($testSeriesPostData) {
184
+            $seriesA = array_filter($testSeriesPostData, function($row) use ($rowA) {
185 185
                 return ($rowA['id'] == $row['post']);
186 186
             });
187
-            $seriesB = array_filter($testSeriesPostData, function ($row) use ($rowB) {
187
+            $seriesB = array_filter($testSeriesPostData, function($row) use ($rowB) {
188 188
                 return ($rowB['id'] == $row['post']);
189 189
             });
190 190
 
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
         $this->assertNotFalse($data);
309 309
         $this->assertInternalType('array', $data);
310 310
 
311
-        $testPostData = array_filter($testPostData, function ($row) {
311
+        $testPostData = array_filter($testPostData, function($row) {
312 312
             return ($row['display'] == 1);
313 313
         });
314 314
         $testPosts = array_column($testPostData, 'id');
Please login to merge, or discard this patch.