@@ -9,14 +9,14 @@ discard block |
||
| 9 | 9 | class MysqlIntroductionRepositoryTest extends PHPUnit_Framework_TestCase |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - protected static $connection; |
|
| 12 | + protected static $connection; |
|
| 13 | 13 | |
| 14 | - public static function setUpBeforeClass() |
|
| 15 | - { |
|
| 16 | - $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
| 17 | - $extendedPdo->exec("ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`"); |
|
| 14 | + public static function setUpBeforeClass() |
|
| 15 | + { |
|
| 16 | + $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
| 17 | + $extendedPdo->exec("ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`"); |
|
| 18 | 18 | |
| 19 | - $extendedPdo->exec(" |
|
| 19 | + $extendedPdo->exec(" |
|
| 20 | 20 | CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`introduction` ( |
| 21 | 21 | `id` integer PRIMARY KEY AUTOINCREMENT, |
| 22 | 22 | `type` varchar(10) NOT NULL, |
@@ -25,134 +25,134 @@ discard block |
||
| 25 | 25 | `content` text NOT NULL, |
| 26 | 26 | `image` image |
| 27 | 27 | )" |
| 28 | - ); |
|
| 29 | - |
|
| 30 | - self::$connection = new ConnectionLocator(function () use ($extendedPdo) { |
|
| 31 | - return $extendedPdo; |
|
| 32 | - }); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function testIsInstanceOfIntroductionRepository() |
|
| 36 | - { |
|
| 37 | - $repository = new MysqlIntroductionRepository(self::$connection); |
|
| 38 | - |
|
| 39 | - $this->assertInstanceOf( |
|
| 40 | - 'Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository', |
|
| 41 | - $repository |
|
| 42 | - ); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function testImplementsIntroductionInterface() |
|
| 46 | - { |
|
| 47 | - $repository = new MysqlIntroductionRepository(self::$connection); |
|
| 48 | - |
|
| 49 | - $this->assertInstanceOf( |
|
| 50 | - 'Jacobemerick\Web\Domain\Blog\Introduction\IntroductionRepositoryInterface', |
|
| 51 | - $repository |
|
| 52 | - ); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function testConstructSetsConnections() |
|
| 56 | - { |
|
| 57 | - $respository = new MysqlIntroductionRepository(self::$connection); |
|
| 58 | - |
|
| 59 | - $this->assertAttributeSame( |
|
| 60 | - self::$connection, |
|
| 61 | - 'connections', |
|
| 62 | - $respository |
|
| 63 | - ); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - public function testFindByType() |
|
| 67 | - { |
|
| 68 | - $testData = [ |
|
| 69 | - 'id' => rand(1, 100), |
|
| 70 | - 'type' => 'test', |
|
| 71 | - 'title' => 'test title', |
|
| 72 | - 'content' => 'test content', |
|
| 73 | - 'image' => rand(1, 100), |
|
| 74 | - ]; |
|
| 75 | - |
|
| 76 | - $this->insertData($testData); |
|
| 77 | - |
|
| 78 | - $repository = new MysqlIntroductionRepository(self::$connection); |
|
| 79 | - $data = $repository->findByType('test'); |
|
| 80 | - |
|
| 81 | - $this->assertNotFalse($data); |
|
| 82 | - $this->assertInternalType('array', $data); |
|
| 83 | - $this->assertArrayHasKey('title', $data); |
|
| 84 | - $this->assertEquals($testData['title'], $data['title']); |
|
| 85 | - $this->assertArrayHasKey('content', $data); |
|
| 86 | - $this->assertEquals($testData['content'], $data['content']); |
|
| 87 | - $this->assertArrayHasKey('image', $data); |
|
| 88 | - $this->assertEquals($testData['image'], $data['image']); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function testFindByTypeFilterValue() |
|
| 92 | - { |
|
| 93 | - $testData = [ |
|
| 94 | - [ |
|
| 95 | - 'id' => rand(1, 100), |
|
| 96 | - 'type' => 'test', |
|
| 97 | - 'title' => 'title a', |
|
| 98 | - 'value' => 'value a', |
|
| 99 | - ], |
|
| 100 | - [ |
|
| 101 | - 'id' => rand(101, 200), |
|
| 102 | - 'type' => 'test', |
|
| 103 | - 'title' => 'title b', |
|
| 104 | - 'value' => 'value b', |
|
| 105 | - ], |
|
| 106 | - ]; |
|
| 107 | - |
|
| 108 | - array_walk($testData, [$this, 'insertData']); |
|
| 109 | - |
|
| 110 | - $repository = new MysqlIntroductionRepository(self::$connection); |
|
| 111 | - $data = $repository->findByType('test', reset($testData)['value']); |
|
| 112 | - |
|
| 113 | - $this->assertNotFalse($data); |
|
| 114 | - $this->assertInternalType('array', $data); |
|
| 115 | - $this->assertEquals(reset($testData)['title'], $data['title']); |
|
| 116 | - } |
|
| 28 | + ); |
|
| 29 | + |
|
| 30 | + self::$connection = new ConnectionLocator(function () use ($extendedPdo) { |
|
| 31 | + return $extendedPdo; |
|
| 32 | + }); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function testIsInstanceOfIntroductionRepository() |
|
| 36 | + { |
|
| 37 | + $repository = new MysqlIntroductionRepository(self::$connection); |
|
| 38 | + |
|
| 39 | + $this->assertInstanceOf( |
|
| 40 | + 'Jacobemerick\Web\Domain\Blog\Introduction\MysqlIntroductionRepository', |
|
| 41 | + $repository |
|
| 42 | + ); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function testImplementsIntroductionInterface() |
|
| 46 | + { |
|
| 47 | + $repository = new MysqlIntroductionRepository(self::$connection); |
|
| 48 | + |
|
| 49 | + $this->assertInstanceOf( |
|
| 50 | + 'Jacobemerick\Web\Domain\Blog\Introduction\IntroductionRepositoryInterface', |
|
| 51 | + $repository |
|
| 52 | + ); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function testConstructSetsConnections() |
|
| 56 | + { |
|
| 57 | + $respository = new MysqlIntroductionRepository(self::$connection); |
|
| 58 | + |
|
| 59 | + $this->assertAttributeSame( |
|
| 60 | + self::$connection, |
|
| 61 | + 'connections', |
|
| 62 | + $respository |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + public function testFindByType() |
|
| 67 | + { |
|
| 68 | + $testData = [ |
|
| 69 | + 'id' => rand(1, 100), |
|
| 70 | + 'type' => 'test', |
|
| 71 | + 'title' => 'test title', |
|
| 72 | + 'content' => 'test content', |
|
| 73 | + 'image' => rand(1, 100), |
|
| 74 | + ]; |
|
| 75 | + |
|
| 76 | + $this->insertData($testData); |
|
| 77 | + |
|
| 78 | + $repository = new MysqlIntroductionRepository(self::$connection); |
|
| 79 | + $data = $repository->findByType('test'); |
|
| 80 | + |
|
| 81 | + $this->assertNotFalse($data); |
|
| 82 | + $this->assertInternalType('array', $data); |
|
| 83 | + $this->assertArrayHasKey('title', $data); |
|
| 84 | + $this->assertEquals($testData['title'], $data['title']); |
|
| 85 | + $this->assertArrayHasKey('content', $data); |
|
| 86 | + $this->assertEquals($testData['content'], $data['content']); |
|
| 87 | + $this->assertArrayHasKey('image', $data); |
|
| 88 | + $this->assertEquals($testData['image'], $data['image']); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function testFindByTypeFilterValue() |
|
| 92 | + { |
|
| 93 | + $testData = [ |
|
| 94 | + [ |
|
| 95 | + 'id' => rand(1, 100), |
|
| 96 | + 'type' => 'test', |
|
| 97 | + 'title' => 'title a', |
|
| 98 | + 'value' => 'value a', |
|
| 99 | + ], |
|
| 100 | + [ |
|
| 101 | + 'id' => rand(101, 200), |
|
| 102 | + 'type' => 'test', |
|
| 103 | + 'title' => 'title b', |
|
| 104 | + 'value' => 'value b', |
|
| 105 | + ], |
|
| 106 | + ]; |
|
| 107 | + |
|
| 108 | + array_walk($testData, [$this, 'insertData']); |
|
| 109 | + |
|
| 110 | + $repository = new MysqlIntroductionRepository(self::$connection); |
|
| 111 | + $data = $repository->findByType('test', reset($testData)['value']); |
|
| 112 | + |
|
| 113 | + $this->assertNotFalse($data); |
|
| 114 | + $this->assertInternalType('array', $data); |
|
| 115 | + $this->assertEquals(reset($testData)['title'], $data['title']); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - public function testFindByTypeFailure() |
|
| 119 | - { |
|
| 120 | - $repository = new MysqlIntroductionRepository(self::$connection); |
|
| 121 | - $data = $repository->findByType('empty type'); |
|
| 122 | - |
|
| 123 | - $this->assertFalse($data); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - protected function tearDown() |
|
| 127 | - { |
|
| 128 | - self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`introduction`"); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - public static function tearDownAfterClass() |
|
| 132 | - { |
|
| 133 | - self::$connection->getDefault()->disconnect(); |
|
| 134 | - unlink('jpemeric_blog.db'); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - protected function insertData(array $data) |
|
| 138 | - { |
|
| 139 | - $defaultData = [ |
|
| 140 | - 'id' => null, |
|
| 141 | - 'type' => '', |
|
| 142 | - 'value' => '', |
|
| 143 | - 'title' => '', |
|
| 144 | - 'content' => '', |
|
| 145 | - 'image' => null, |
|
| 146 | - ]; |
|
| 147 | - |
|
| 148 | - $data = array_merge($defaultData, $data); |
|
| 149 | - |
|
| 150 | - return self::$connection->getDefault()->perform(" |
|
| 118 | + public function testFindByTypeFailure() |
|
| 119 | + { |
|
| 120 | + $repository = new MysqlIntroductionRepository(self::$connection); |
|
| 121 | + $data = $repository->findByType('empty type'); |
|
| 122 | + |
|
| 123 | + $this->assertFalse($data); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + protected function tearDown() |
|
| 127 | + { |
|
| 128 | + self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`introduction`"); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + public static function tearDownAfterClass() |
|
| 132 | + { |
|
| 133 | + self::$connection->getDefault()->disconnect(); |
|
| 134 | + unlink('jpemeric_blog.db'); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + protected function insertData(array $data) |
|
| 138 | + { |
|
| 139 | + $defaultData = [ |
|
| 140 | + 'id' => null, |
|
| 141 | + 'type' => '', |
|
| 142 | + 'value' => '', |
|
| 143 | + 'title' => '', |
|
| 144 | + 'content' => '', |
|
| 145 | + 'image' => null, |
|
| 146 | + ]; |
|
| 147 | + |
|
| 148 | + $data = array_merge($defaultData, $data); |
|
| 149 | + |
|
| 150 | + return self::$connection->getDefault()->perform(" |
|
| 151 | 151 | INSERT INTO `jpemeric_blog`.`introduction` |
| 152 | 152 | (id, type, value, title, content, image) |
| 153 | 153 | VALUES |
| 154 | 154 | (:id, :type, :value, :title, :content, :image)", |
| 155 | - $data |
|
| 156 | - ); |
|
| 157 | - } |
|
| 155 | + $data |
|
| 156 | + ); |
|
| 157 | + } |
|
| 158 | 158 | } |
@@ -29,7 +29,7 @@ |
||
| 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 | } |
@@ -10,14 +10,14 @@ discard block |
||
| 10 | 10 | class MysqlPostRepositoryTest extends PHPUnit_Framework_TestCase |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - protected static $connection; |
|
| 13 | + protected static $connection; |
|
| 14 | 14 | |
| 15 | - public static function setUpBeforeClass() |
|
| 16 | - { |
|
| 17 | - $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
| 18 | - $extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`'); |
|
| 15 | + public static function setUpBeforeClass() |
|
| 16 | + { |
|
| 17 | + $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
| 18 | + $extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`'); |
|
| 19 | 19 | |
| 20 | - $extendedPdo->exec(" |
|
| 20 | + $extendedPdo->exec(" |
|
| 21 | 21 | CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`post` ( |
| 22 | 22 | `id` integer PRIMARY KEY AUTOINCREMENT, |
| 23 | 23 | `title` varchar(60) NOT NULL, |
@@ -27,91 +27,91 @@ discard block |
||
| 27 | 27 | `body` text NOT NULL, |
| 28 | 28 | `display` integer NOT NULL |
| 29 | 29 | )" |
| 30 | - ); |
|
| 31 | - |
|
| 32 | - self::$connection = new ConnectionLocator(function () use ($extendedPdo) { |
|
| 33 | - return $extendedPdo; |
|
| 34 | - }); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function newMysqlPostRepository() |
|
| 38 | - { |
|
| 39 | - return new MysqlPostRepository(self::$connection); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - public function testConstructSetsConnections() |
|
| 43 | - { |
|
| 44 | - $this->assertAttributeEquals( |
|
| 45 | - self::$connection, |
|
| 46 | - 'connections', |
|
| 47 | - $this->newMysqlPostRepository() |
|
| 48 | - ); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function testFindPostByPath() |
|
| 52 | - { |
|
| 53 | - $test_active_post = array( |
|
| 54 | - 'title' => 'test findByPath active', |
|
| 55 | - 'path' => 'test-findbypath-active', |
|
| 56 | - 'category' => 'test-category', |
|
| 57 | - 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
| 58 | - 'body' => 'test content', |
|
| 59 | - 'display' => 1 |
|
| 60 | - ); |
|
| 61 | - |
|
| 62 | - self::$connection->getDefault()->perform(" |
|
| 30 | + ); |
|
| 31 | + |
|
| 32 | + self::$connection = new ConnectionLocator(function () use ($extendedPdo) { |
|
| 33 | + return $extendedPdo; |
|
| 34 | + }); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function newMysqlPostRepository() |
|
| 38 | + { |
|
| 39 | + return new MysqlPostRepository(self::$connection); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + public function testConstructSetsConnections() |
|
| 43 | + { |
|
| 44 | + $this->assertAttributeEquals( |
|
| 45 | + self::$connection, |
|
| 46 | + 'connections', |
|
| 47 | + $this->newMysqlPostRepository() |
|
| 48 | + ); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function testFindPostByPath() |
|
| 52 | + { |
|
| 53 | + $test_active_post = array( |
|
| 54 | + 'title' => 'test findByPath active', |
|
| 55 | + 'path' => 'test-findbypath-active', |
|
| 56 | + 'category' => 'test-category', |
|
| 57 | + 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
| 58 | + 'body' => 'test content', |
|
| 59 | + 'display' => 1 |
|
| 60 | + ); |
|
| 61 | + |
|
| 62 | + self::$connection->getDefault()->perform(" |
|
| 63 | 63 | INSERT INTO jpemeric_blog.post |
| 64 | 64 | (title, path, category, date, body, display) |
| 65 | 65 | VALUES |
| 66 | 66 | (:title, :path, :category, :date, :body, :display)", |
| 67 | - $test_active_post); |
|
| 68 | - |
|
| 69 | - $active_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 70 | - $test_active_post['category'], |
|
| 71 | - $test_active_post['path'] |
|
| 72 | - ); |
|
| 73 | - $this->assertSame($test_active_post['title'], $active_post['title']); |
|
| 74 | - |
|
| 75 | - $test_inactive_post = array( |
|
| 76 | - 'title' => 'test findByPath inactive', |
|
| 77 | - 'path' => 'test-findbypath-inactive', |
|
| 78 | - 'category' => 'test-category', |
|
| 79 | - 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
| 80 | - 'body' => 'test content', |
|
| 81 | - 'display' => 0 |
|
| 82 | - ); |
|
| 83 | - |
|
| 84 | - self::$connection->getDefault()->perform(" |
|
| 67 | + $test_active_post); |
|
| 68 | + |
|
| 69 | + $active_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 70 | + $test_active_post['category'], |
|
| 71 | + $test_active_post['path'] |
|
| 72 | + ); |
|
| 73 | + $this->assertSame($test_active_post['title'], $active_post['title']); |
|
| 74 | + |
|
| 75 | + $test_inactive_post = array( |
|
| 76 | + 'title' => 'test findByPath inactive', |
|
| 77 | + 'path' => 'test-findbypath-inactive', |
|
| 78 | + 'category' => 'test-category', |
|
| 79 | + 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
| 80 | + 'body' => 'test content', |
|
| 81 | + 'display' => 0 |
|
| 82 | + ); |
|
| 83 | + |
|
| 84 | + self::$connection->getDefault()->perform(" |
|
| 85 | 85 | INSERT INTO jpemeric_blog.post |
| 86 | 86 | (title, path, category, date, body, display) |
| 87 | 87 | VALUES |
| 88 | 88 | (:title, :path, :category, :date, :body, :display)", |
| 89 | - $test_inactive_post); |
|
| 90 | - |
|
| 91 | - $inactive_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 92 | - $test_inactive_post['category'], |
|
| 93 | - $test_inactive_post['path'] |
|
| 94 | - ); |
|
| 95 | - $this->assertFalse($inactive_post); |
|
| 96 | - |
|
| 97 | - $nonexistant_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 98 | - 'test-category', |
|
| 99 | - 'test-findbypath-nonexistant' |
|
| 100 | - ); |
|
| 101 | - $this->assertFalse($nonexistant_post); |
|
| 89 | + $test_inactive_post); |
|
| 90 | + |
|
| 91 | + $inactive_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 92 | + $test_inactive_post['category'], |
|
| 93 | + $test_inactive_post['path'] |
|
| 94 | + ); |
|
| 95 | + $this->assertFalse($inactive_post); |
|
| 96 | + |
|
| 97 | + $nonexistant_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 98 | + 'test-category', |
|
| 99 | + 'test-findbypath-nonexistant' |
|
| 100 | + ); |
|
| 101 | + $this->assertFalse($nonexistant_post); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - public function testIsInstanceOfPostRepository() |
|
| 105 | - { |
|
| 106 | - $this->assertInstanceOf( |
|
| 107 | - 'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface', |
|
| 108 | - $this->newMysqlPostRepository() |
|
| 109 | - ); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - public static function tearDownAfterClass() |
|
| 113 | - { |
|
| 114 | - self::$connection->getDefault()->disconnect(); |
|
| 115 | - unlink('jpemeric_blog.db'); |
|
| 116 | - } |
|
| 104 | + public function testIsInstanceOfPostRepository() |
|
| 105 | + { |
|
| 106 | + $this->assertInstanceOf( |
|
| 107 | + 'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface', |
|
| 108 | + $this->newMysqlPostRepository() |
|
| 109 | + ); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + public static function tearDownAfterClass() |
|
| 113 | + { |
|
| 114 | + self::$connection->getDefault()->disconnect(); |
|
| 115 | + unlink('jpemeric_blog.db'); |
|
| 116 | + } |
|
| 117 | 117 | } |
@@ -29,7 +29,7 @@ |
||
| 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 | } |