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

PdfLetterTraitTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 64.81 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 35
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testUploadFromRequestValid() 18 18 1
A testUploadFromRequestWithInvalidFileType() 17 17 1
A testGenerateFile() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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