Code Duplication    Length = 51-53 lines in 2 locations

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

@@ 428-480 (lines=53) @@
425
       }
426
    }
427
428
    public function testGetActivePostsByTagInactive()
429
    {
430
        $testPostData = [
431
            [
432
                'id'      => rand(1, 100),
433
                'display' => 1,
434
            ],
435
            [
436
                'id'      => rand(101, 200),
437
                'display' => 0,
438
            ],
439
            [
440
                'id'      => rand(201, 300),
441
                'display' => 1,
442
            ],
443
        ];
444
445
        $testTagData = [
446
            'id' => rand(1, 100),
447
        ];
448
449
        $testPTLinkData = [];
450
        foreach ($testPostData as $testPostRow) {
451
            array_push($testPTLinkData, [
452
                'post_id' => $testPostRow['id'],
453
                'tag_id' => $testTagData['id'],
454
            ]);
455
        }
456
457
        array_walk($testPostData, [$this, 'insertPostData']);
458
        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
459
        $this->insertTagData($testTagData);
460
461
        $repository = new MysqlPostRepository(self::$connection);
462
        $data = $repository->getActivePostsByTag($testTagData['id']);
463
464
        $this->assertNotFalse($data);
465
        $this->assertInternalType('array', $data);
466
467
        $testPostData = array_filter($testPostData, function ($row) {
468
            return ($row['display'] == 1);
469
        });
470
471
        $this->assertCount(count($testPostData), $data);
472
473
        $testIds = array_column($testPostData, 'ids');
474
        $dataIds = array_column($data, 'ids');
475
476
        $this->assertEmpty(array_merge(
477
            array_diff($testIds, $dataIds),
478
            array_diff($dataIds, $testIds)
479
        ));
480
    }
481
 
482
    public function testGetActivePostsByTagFailure()
483
    {
@@ 495-545 (lines=51) @@
492
        $this->assertInternalType('array', $data);
493
    }
494
495
    public function testGetActivePostsByTagRange()
496
    {
497
        $testPostData = [
498
            [
499
                'id'      => rand(1, 100),
500
                'display' => 1,
501
            ],
502
            [
503
                'id'      => rand(101, 200),
504
                'display' => 1,
505
            ],
506
            [
507
                'id'      => rand(201, 300),
508
                'display' => 1,
509
            ],
510
        ];
511
512
        $testTagData = [
513
            'id' => rand(1, 100),
514
        ];
515
516
        $testPTLinkData = [];
517
        foreach ($testPostData as $testPostRow) {
518
            array_push($testPTLinkData, [
519
                'post_id' => $testPostRow['id'],
520
                'tag_id' => $testTagData['id'],
521
            ]);
522
        }
523
524
        array_walk($testPostData, [$this, 'insertPostData']);
525
        array_walk($testPTLinkData, [$this, 'insertPTLinkData']);
526
        $this->insertTagData($testTagData);
527
528
        $repository = new MysqlPostRepository(self::$connection);
529
        $data = $repository->getActivePostsByTag($testTagData['id'], 2, 1);
530
531
        $this->assertNotFalse($data);
532
        $this->assertInternalType('array', $data);
533
534
        $testPostData = array_slice($testPostData, 1, 2);
535
536
        $this->assertCount(count($testPostData), $data);
537
538
        $testIds = array_column($testPostData, 'ids');
539
        $dataIds = array_column($data, 'ids');
540
541
        $this->assertEmpty(array_merge(
542
            array_diff($testIds, $dataIds),
543
            array_diff($dataIds, $testIds)
544
        ));
545
    }
546
547
    public function testGetActivePostsByTagRangeFailure()
548
    {