@@ -7,21 +7,21 @@ discard block |
||
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 |
||
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 testFindByPath() |
|
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 testFindByPath() |
|
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()->findByPath( |
|
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()->findByPath( |
|
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()->findByPath( |
|
93 | - $test_inactive_post['category'], |
|
94 | - $test_inactive_post['path'] |
|
95 | - ); |
|
96 | - $this->assertFalse($inactive_post); |
|
97 | - |
|
98 | - $nonexistant_post = $this->newMysqlPostRepository()->findByPath( |
|
99 | - 'test-category', |
|
100 | - 'test-findbypath-nonexistant' |
|
101 | - ); |
|
102 | - $this->assertFalse($nonexistant_post); |
|
90 | + $test_inactive_post); |
|
91 | + |
|
92 | + $inactive_post = $this->newMysqlPostRepository()->findByPath( |
|
93 | + $test_inactive_post['category'], |
|
94 | + $test_inactive_post['path'] |
|
95 | + ); |
|
96 | + $this->assertFalse($inactive_post); |
|
97 | + |
|
98 | + $nonexistant_post = $this->newMysqlPostRepository()->findByPath( |
|
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\PostRepository', |
|
109 | - $this->newMysqlPostRepository() |
|
110 | - ); |
|
111 | - } |
|
105 | + public function testIsInstanceOfPostRepository() |
|
106 | + { |
|
107 | + $this->assertInstanceOf( |
|
108 | + 'Jacobemerick\Web\Domain\Blog\PostRepository', |
|
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 | } |