Code Duplication    Length = 51-51 lines in 2 locations

tests/unit/Domain/Blog/Post/MysqlPostRepositoryTest.php 2 locations

@@ 144-194 (lines=51) @@
141
        $this->assertFalse($data);
142
    }
143
144
    public function testGetActivePosts()
145
    {
146
        $testData = [
147
            [
148
                'id'       => rand(1, 100),
149
                'title'    => 'title one',
150
                'path'     => 'path-one',
151
                'category' => 'test category',
152
                'date'     => (new DateTime('-1 day'))->format('Y-m-d H:i:s'),
153
                'body'     => 'body one',
154
                'display'  => 1,
155
            ],
156
            [
157
                'id'       => rand(101, 200),
158
                'title'    => 'title two',
159
                'path'     => 'path-two',
160
                'category' => 'test category',
161
                'date'     => (new DateTime())->format('Y-m-d H:i:s'),
162
                'body'     => 'body one',
163
                'display'  => 1,
164
            ],
165
        ];
166
167
        array_walk($testData, [$this, 'insertPostData']);
168
169
        $repository = new MysqlPostRepository(self::$connection);
170
        $data = $repository->getActivePosts();
171
172
        $this->assertNotFalse($data);
173
        $this->assertInternalType('array', $data);
174
        $this->assertCount(count($testData), $data);
175
176
        usort($testData, function ($rowA, $rowB) {
177
            return ((new DateTime($rowA['date'])) < (new DateTime($rowB['date'])));
178
        });
179
180
        foreach ($testData as $key => $testRow) {
181
            $this->assertArrayHasKey('id', $data[$key]);
182
            $this->assertEquals($testRow['id'], $data[$key]['id']);
183
            $this->assertArrayHasKey('title', $data[$key]);
184
            $this->assertEquals($testRow['title'], $data[$key]['title']);
185
            $this->assertArrayHasKey('path', $data[$key]);
186
            $this->assertEquals($testRow['path'], $data[$key]['path']);
187
            $this->assertArrayHasKey('date', $data[$key]);
188
            $this->assertEquals($testRow['date'], $data[$key]['date']);
189
            $this->assertArrayHasKey('body', $data[$key]);
190
            $this->assertEquals($testRow['body'], $data[$key]['body']);
191
            $this->assertArrayHasKey('category', $data[$key]);
192
            $this->assertEquals($testRow['category'], $data[$key]['category']);
193
        }
194
    }
195
 
196
    public function testGetActivePostsInactive()
197
    {
@@ 701-751 (lines=51) @@
698
        $this->assertEquals('0', $data);
699
    }
700
 
701
    public function testGetActivePostsByCategory()
702
    {
703
        $testData = [
704
            [
705
                'id'       => rand(1, 100),
706
                'title'    => 'title one',
707
                'path'     => 'path-one',
708
                'category' => 'test category',
709
                'date'     => (new DateTime('-1 day'))->format('Y-m-d H:i:s'),
710
                'body'     => 'body one',
711
                'display'  => 1,
712
            ],
713
            [
714
                'id'       => rand(101, 200),
715
                'title'    => 'title two',
716
                'path'     => 'path-two',
717
                'category' => 'test category',
718
                'date'     => (new DateTime())->format('Y-m-d H:i:s'),
719
                'body'     => 'body one',
720
                'display'  => 1,
721
            ],
722
        ];
723
724
        array_walk($testData, [$this, 'insertPostData']);
725
726
        $repository = new MysqlPostRepository(self::$connection);
727
        $data = $repository->getActivePostsByCategory(reset($testData)['category']);
728
729
        $this->assertNotFalse($data);
730
        $this->assertInternalType('array', $data);
731
        $this->assertCount(count($testData), $data);
732
733
        usort($testData, function ($rowA, $rowB) {
734
            return ((new DateTime($rowA['date'])) < (new DateTime($rowB['date'])));
735
        });
736
737
        foreach ($testData as $key => $testDataRow) {
738
            $this->assertArrayHasKey('id', $data[$key]);
739
            $this->assertEquals($testDataRow['id'], $data[$key]['id']);
740
            $this->assertArrayHasKey('title', $data[$key]);
741
            $this->assertEquals($testDataRow['title'], $data[$key]['title']);
742
            $this->assertArrayHasKey('path', $data[$key]);
743
            $this->assertEquals($testDataRow['path'], $data[$key]['path']);
744
            $this->assertArrayHasKey('date', $data[$key]);
745
            $this->assertEquals($testDataRow['date'], $data[$key]['date']);
746
            $this->assertArrayHasKey('body', $data[$key]);
747
            $this->assertEquals($testDataRow['body'], $data[$key]['body']);
748
            $this->assertArrayHasKey('category', $data[$key]);
749
            $this->assertEquals($testDataRow['category'], $data[$key]['category']);
750
        }
751
    }
752
753
    public function testGetActivePostsByCategoryInactive()
754
    {