Test Failed
Push — master ( 195aca...671b4b )
by Gabriel
09:39
created

tests/src/PdfLetters/PdfLetterTraitTest.php (6 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace ByTIC\DocumentGenerator\Tests\PdfLetters;
4
5
use ByTIC\DocumentGenerator\Tests\AbstractTest;
6
use ByTIC\DocumentGenerator\Tests\Fixtures\Models\MediaRecords\MediaRecord;
7
use ByTIC\DocumentGenerator\Tests\Fixtures\Models\PdfLetters\PdfLetter;
8
use ByTIC\DocumentGenerator\Tests\Fixtures\Models\PdfLetters\PdfLetters;
9
use ByTIC\DocumentGenerator\Tests\Fixtures\Models\Recipients\Recipient;
10
use ByTIC\MediaLibrary\Media\Media;
11
use Mockery;
12
use Symfony\Component\HttpFoundation\File\UploadedFile;
13
use const setasign\Fpdi\TcpdfFpdi;
14
use setasign\Fpdi\Tcpdf\Fpdi;
15
16
/**
17
 * Class PdfLetterTraitTest
18
 * @package ByTIC\DocumentGenerator\Tests\PdfLetters
19
 */
20
class PdfLetterTraitTest extends AbstractTest
21
{
22
23 View Code Duplication
    public function testUploadFromRequestValid()
24
    {
25
        $letter = new PdfLetter();
26
        $letter->id = 10;
27
28
        $uploadedFile = new UploadedFile(
29
            TEST_FIXTURE_PATH . '/files/file.pdf',
30
            'test original name.pdf',
31
            'application/pdf',
32
            null,
33
            null,
34
            true
35
        );
36
37
        $response = $letter->uploadFromRequest($uploadedFile);
38
        parent::assertInstanceOf(Media::class, $response);
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<ByTIC\DocumentGen...tor\Tests\AbstractTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
        self::assertFileExists(TEST_FIXTURE_PATH . '/files/pdf_letters/10/file.pdf');
0 ignored issues
show
The method assertFileExists() does not seem to exist on object<ByTIC\DocumentGen...ers\PdfLetterTraitTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
    }
41
42 View Code Duplication
    public function testUploadFromRequestWithInvalidFileType()
43
    {
44
        $letter = new PdfLetter();
45
        $letter->id = 10;
46
47
        $uploadedFile = new UploadedFile(
48
            TEST_FIXTURE_PATH . '/files/file.pdf',
49
            'test original name.doc',
50
            null,
51
            null,
52
            null,
53
            true
54
        );
55
56
        $response = $letter->uploadFromRequest($uploadedFile);
57
        parent::assertSame('INVALID_MIME_TYPE_ERROR', $response);
0 ignored issues
show
The method assertSame() does not seem to exist on object<ByTIC\DocumentGen...tor\Tests\AbstractTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
    }
59
60
    public function testGenerateNewPdfObj()
61
    {
62
        $letter = new PdfLetter();
63
        $letter->id = 99;
64
65
        $pdf = $letter->generateNewPdfObj();
66
        $output = $pdf->Output('output.pdf', 'S');
67
68
        parent::assertStringStartsWith('%PDF-1.7', $output);
0 ignored issues
show
The method assertStringStartsWith() does not seem to exist on object<ByTIC\DocumentGen...tor\Tests\AbstractTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
        parent::assertStringContainsString('%%EOF', $output);
0 ignored issues
show
The method assertStringContainsString() does not seem to exist on object<ByTIC\DocumentGen...tor\Tests\AbstractTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
    }
71
72
    public function testGenerateFileWithMediaObject()
73
    {
74
        $letter = Mockery::mock(PdfLetter::class);
75
        $letter->shouldReceive('getCustomFields')->andReturn([]);
76
        $letter = $letter->makePartial();
77
78
        $letter->setManagerName(PdfLetters::class);
79
        $letter->id = 99;
80
81
        $recipient = new Recipient();
82
        $mediaRecord = Mockery::mock(MediaRecord::class);
83
        $mediaRecord->shouldReceive('addFileFromContent');
84
85
        $pdf = $letter->generateFile($recipient, $mediaRecord);
86
        self::assertInstanceOf(Fpdi::class, $pdf);
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<ByTIC\DocumentGen...ers\PdfLetterTraitTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
    }
88
}
89