Code Duplication    Length = 51-53 lines in 3 locations

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

@@ 439-491 (lines=53) @@
436
        }
437
    }
438
439
    public function testGetActivePostsByTagInactive()
440
    {
441
        $testPostData = [
442
            [
443
                'id'      => rand(1, 100),
444
                'display' => 1,
445
            ],
446
            [
447
                'id'      => rand(101, 200),
448
                'display' => 0,
449
            ],
450
            [
451
                'id'      => rand(201, 300),
452
                'display' => 1,
453
            ],
454
        ];
455
456
        $testTagData = [
457
            'id' => rand(1, 100),
458
        ];
459
460
        $testPTLinkData = [];
461
        foreach ($testPostData as $testPostRow) {
462
            array_push($testPTLinkData, [
463
                'post_id' => $testPostRow['id'],
464
                'tag_id' => $testTagData['id'],
465
            ]);
466
        }
467
468
        array_walk($testPostData, [$this, 'insertPostData']);
469
        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
470
        $this->insertTagData($testTagData);
471
472
        $repository = new MysqlPostRepository(self::$connection);
473
        $data = $repository->getActivePostsByTag($testTagData['id']);
474
475
        $this->assertNotFalse($data);
476
        $this->assertInternalType('array', $data);
477
478
        $testPostData = array_filter($testPostData, function ($row) {
479
            return ($row['display'] == 1);
480
        });
481
482
        $this->assertCount(count($testPostData), $data);
483
484
        $testIds = array_column($testPostData, 'ids');
485
        $dataIds = array_column($data, 'ids');
486
487
        $this->assertEmpty(array_merge(
488
            array_diff($testIds, $dataIds),
489
            array_diff($dataIds, $testIds)
490
        ));
491
    }
492
 
493
    public function testGetActivePostsByTagFailure()
494
    {
@@ 506-556 (lines=51) @@
503
        $this->assertInternalType('array', $data);
504
    }
505
506
    public function testGetActivePostsByTagRange()
507
    {
508
        $testPostData = [
509
            [
510
                'id'      => rand(1, 100),
511
                'display' => 1,
512
            ],
513
            [
514
                'id'      => rand(101, 200),
515
                'display' => 1,
516
            ],
517
            [
518
                'id'      => rand(201, 300),
519
                'display' => 1,
520
            ],
521
        ];
522
523
        $testTagData = [
524
            'id' => rand(1, 100),
525
        ];
526
527
        $testPTLinkData = [];
528
        foreach ($testPostData as $testPostRow) {
529
            array_push($testPTLinkData, [
530
                'post_id' => $testPostRow['id'],
531
                'tag_id' => $testTagData['id'],
532
            ]);
533
        }
534
535
        array_walk($testPostData, [$this, 'insertPostData']);
536
        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
537
        $this->insertTagData($testTagData);
538
539
        $repository = new MysqlPostRepository(self::$connection);
540
        $data = $repository->getActivePostsByTag($testTagData['id'], 2, 1);
541
542
        $this->assertNotFalse($data);
543
        $this->assertInternalType('array', $data);
544
545
        $testPostData = array_slice($testPostData, 1, 2);
546
547
        $this->assertCount(count($testPostData), $data);
548
549
        $testIds = array_column($testPostData, 'ids');
550
        $dataIds = array_column($data, 'ids');
551
552
        $this->assertEmpty(array_merge(
553
            array_diff($testIds, $dataIds),
554
            array_diff($dataIds, $testIds)
555
        ));
556
    }
557
558
    public function testGetActivePostsByTagRangeFailure()
559
    {
@@ 1025-1075 (lines=51) @@
1022
        }
1023
    }
1024
1025
    public function testGetActivePostsByRelatedTagsLimit()
1026
    {
1027
        $testPostData = [
1028
            [
1029
                'id'      => rand(1, 100),
1030
                'display' => 1,
1031
            ],
1032
            [
1033
                'id'      => rand(101, 200),
1034
                'display' => 1,
1035
            ],
1036
            [
1037
                'id'      => rand(201, 300),
1038
                'display' => 1,
1039
            ],
1040
        ];
1041
1042
        $testTagData = [
1043
            'id' => rand(1, 100),
1044
        ];
1045
1046
        $testPTLinkData = [];
1047
        foreach ($testPostData as $testPostRow) {
1048
            array_push($testPTLinkData, [
1049
                'post_id' => $testPostRow['id'],
1050
                'tag_id' => $testTagData['id'],
1051
            ]);
1052
        }
1053
1054
        array_walk($testPostData, [$this, 'insertPostData']);
1055
        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
1056
        $this->insertTagData($testTagData);
1057
1058
        $repository = new MysqlPostRepository(self::$connection);
1059
        $data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id'], 1);
1060
1061
        $this->assertNotFalse($data);
1062
        $this->assertInternalType('array', $data);
1063
1064
        $testPostData = array_slice($testPostData, 1, 1);
1065
1066
        $this->assertCount(count($testPostData), $data);
1067
1068
        $testIds = array_column($testPostData, 'ids');
1069
        $dataIds = array_column($data, 'ids');
1070
1071
        $this->assertEmpty(array_merge(
1072
            array_diff($testIds, $dataIds),
1073
            array_diff($dataIds, $testIds)
1074
        ));
1075
    }
1076
 
1077
    public function testGetActivePostsByRelatedTagsInactive()
1078
    {