Code Duplication    Length = 51-53 lines in 3 locations

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

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