Code Duplication    Length = 45-45 lines in 2 locations

tests/ArchangelTest.php 2 locations

@@ 645-689 (lines=45) @@
642
        $this->assertEquals($expectedMessage, $builtMessage);
643
    }
644
645
    public function testBuildMessageWithAttachmentsPlain()
646
    {
647
        $path = __DIR__ . '/test.txt';
648
        $textContent = 'Dummy Content';
649
        $this->makeTmpFile($path, $textContent);
650
651
        $encodedContent = chunk_split(base64_encode($textContent));
652
        $type = 'text/plain';
653
        $title = 'Test File';
654
        $message = 'Plain text message';
655
656
        $archangel = new Archangel();
657
658
        $boundaryMixedProperty = $this->getProtectedProperty('boundaryMixed');
659
        $boundaryMixed = $boundaryMixedProperty->getValue($archangel);
660
        $plainMsgMethod = $this->getProtectedMethod('buildPlainMessageHeader');
661
        $plainMsgHeaders = $plainMsgMethod->invoke($archangel);
662
663
        $expectedMessage = array();
664
        array_push($expectedMessage, "--{$boundaryMixed}");
665
        $expectedMessage = array_merge($expectedMessage, $plainMsgHeaders);
666
        array_push($expectedMessage, $message);
667
        array_push($expectedMessage, "--{$boundaryMixed}");
668
        array_push($expectedMessage, "Content-Type: {$type}; name=\"{$title}\"");
669
        array_push($expectedMessage, 'Content-Transfer-Encoding: base64');
670
        array_push($expectedMessage, 'Content-Disposition: attachment');
671
        array_push($expectedMessage, '');
672
        array_push($expectedMessage, $encodedContent);
673
        array_push($expectedMessage, "--{$boundaryMixed}--");
674
        $expectedMessage = implode(Archangel::LINE_BREAK, $expectedMessage);
675
676
        $plainMessageProperty = $this->getProtectedProperty('plainMessage');
677
        $plainMessageProperty->setValue($archangel, $message);
678
        $htmlMessageProperty = $this->getProtectedProperty('htmlMessage');
679
        $htmlMessageProperty->setValue($archangel, '');
680
        $attachmentProperty = $this->getProtectedProperty('attachments');
681
        $attachmentProperty->setValue($archangel, array(
682
            array('path' => $path, 'type' => $type, 'title' => $title)
683
        ));
684
        $buildMethod = $this->getProtectedMethod('buildMessageWithAttachments');
685
        $builtMessage = $buildMethod->invoke($archangel);
686
687
        unlink($path);
688
        $this->assertEquals($expectedMessage, $builtMessage);
689
    }
690
691
    public function testBuildMessageWithAttachmentsHtml()
692
    {
@@ 691-735 (lines=45) @@
688
        $this->assertEquals($expectedMessage, $builtMessage);
689
    }
690
691
    public function testBuildMessageWithAttachmentsHtml()
692
    {
693
        $path = __DIR__ . '/test.txt';
694
        $textContent = 'Dummy Content';
695
        $this->makeTmpFile($path, $textContent);
696
697
        $encodedContent = chunk_split(base64_encode($textContent));
698
        $type = 'text/plain';
699
        $title = 'Test File';
700
        $message = '<p>HTML Message.</p>';
701
702
        $archangel = new Archangel();
703
704
        $boundaryMixedProperty = $this->getProtectedProperty('boundaryMixed');
705
        $boundaryMixed = $boundaryMixedProperty->getValue($archangel);
706
        $htmlMsgMethod = $this->getProtectedMethod('buildHtmlMessageHeader');
707
        $htmlMsgHeaders = $htmlMsgMethod->invoke($archangel);
708
709
        $expectedMessage = array();
710
        array_push($expectedMessage, "--{$boundaryMixed}");
711
        $expectedMessage = array_merge($expectedMessage, $htmlMsgHeaders);
712
        array_push($expectedMessage, $message);
713
        array_push($expectedMessage, "--{$boundaryMixed}");
714
        array_push($expectedMessage, "Content-Type: {$type}; name=\"{$title}\"");
715
        array_push($expectedMessage, 'Content-Transfer-Encoding: base64');
716
        array_push($expectedMessage, 'Content-Disposition: attachment');
717
        array_push($expectedMessage, '');
718
        array_push($expectedMessage, $encodedContent);
719
        array_push($expectedMessage, "--{$boundaryMixed}--");
720
        $expectedMessage = implode(Archangel::LINE_BREAK, $expectedMessage);
721
722
        $plainMessageProperty = $this->getProtectedProperty('plainMessage');
723
        $plainMessageProperty->setValue($archangel, '');
724
        $htmlMessageProperty = $this->getProtectedProperty('htmlMessage');
725
        $htmlMessageProperty->setValue($archangel, $message);
726
        $attachmentProperty = $this->getProtectedProperty('attachments');
727
        $attachmentProperty->setValue($archangel, array(
728
            array('path' => $path, 'type' => $type, 'title' => $title)
729
        ));
730
        $buildMethod = $this->getProtectedMethod('buildMessageWithAttachments');
731
        $builtMessage = $buildMethod->invoke($archangel);
732
733
        unlink($path);
734
        $this->assertEquals($expectedMessage, $builtMessage);
735
    }
736
737
    public function testBuildMessageWithAttachmentsMultipart()
738
    {