Completed
Push — master ( 3e0714...50ebf9 )
by Gabriel
09:17
created

PdfLetterTraitTest::testGenerateFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ByTIC\DocumentGenerator\Tests\PdfLetters;
4
5
use ByTIC\DocumentGenerator\Tests\AbstractTest;
6
use ByTIC\DocumentGenerator\Tests\Fixtures\Models\PdfLetters\PdfLetter;
7
use ByTIC\DocumentGenerator\Tests\Fixtures\Models\Recipients\Recipient;
8
use ByTIC\MediaLibrary\Media\Media;
9
use Symfony\Component\HttpFoundation\File\UploadedFile;
10
11
/**
12
 * Class PdfLetterTraitTest
13
 * @package ByTIC\DocumentGenerator\Tests\PdfLetters
14
 */
15
class PdfLetterTraitTest extends AbstractTest
16
{
17
    /**
18
     *
19
     */
20 View Code Duplication
    public function testUploadFromRequestValid()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        $letter = new PdfLetter();
23
        $letter->id = 10;
24
25
        $uploadedFile = new UploadedFile(
26
            TEST_FIXTURE_PATH . '/files/file.pdf',
27
            'test original name.pdf',
28
            'application/pdf',
29
            null,
30
            null,
31
            true
32
        );
33
34
        $response = $letter->uploadFromRequest($uploadedFile);
35
        parent::assertInstanceOf(Media::class, $response);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertInstanceOf() instead of testUploadFromRequestValid()). Are you sure this is correct? If so, you might want to change this to $this->assertInstanceOf().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
36
        self::assertFileExists(TEST_FIXTURE_PATH . '/files/pdf_letters/10/file.pdf');
37
    }
38
39 View Code Duplication
    public function testUploadFromRequestWithInvalidFileType()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        $letter = new PdfLetter();
42
        $letter->id = 10;
43
44
        $uploadedFile = new UploadedFile(
45
            TEST_FIXTURE_PATH . '/files/file.pdf',
46
            'test original name.doc',
47
            null,
48
            null,
49
            null,
50
            true
51
        );
52
53
        $response = $letter->uploadFromRequest($uploadedFile);
54
        parent::assertSame('INVALID_MIME_TYPE_ERROR', $response);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertSame() instead of testUploadFromRequestWithInvalidFileType()). Are you sure this is correct? If so, you might want to change this to $this->assertSame().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
55
    }
56
57
    public function testGenerateFile()
58
    {
59
        $letter = new PdfLetter();
60
        $letter->id = 99;
61
62
        $pdf = $letter->generateNewPdfObj();
63
        $output = $pdf->Output('output.pdf', 'S');
64
65
        parent::assertStringStartsWith('%PDF-1.7', $output);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertStringStartsWith() instead of testGenerateFile()). Are you sure this is correct? If so, you might want to change this to $this->assertStringStartsWith().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
66
        parent::assertStringContainsString('%%EOF', $output);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (assertStringContainsString() instead of testGenerateFile()). Are you sure this is correct? If so, you might want to change this to $this->assertStringContainsString().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
67
    }
68
}
69