GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Push — master ( 06bc6c...e92c95 )
by Mewes
03:57
created

DefaultControllerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 110
Duplicated Lines 36.36 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 40
loc 110
rs 10
c 0
b 0
f 0

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 MewesK\TwigSpreadsheetBundle\Tests\Functional;
4
5
use Symfony\Component\HttpFoundation\Response;
6
7
/**
8
 * Class DefaultControllerTest.
9
 *
10
 * @coversNothing
11
 */
12
class DefaultControllerTest extends AbstractControllerTest
13
{
14
    protected static $ENVIRONMENT = 'controller';
15
    protected static $TEMP_PATH = '/../../tmp/functional/controller/';
16
17
    //
18
    // PhpUnit
19
    //
20
21
    /**
22
     * @return array
23
     */
24
    public function formatProvider()
25
    {
26
        return [['ods'], ['xls'], ['xlsx']];
27
    }
28
29
    //
30
    // Tests
31
    //
32
33
    /**
34
     * @param string $format
35
     *
36
     * @throws \Exception
37
     *
38
     * @dataProvider formatProvider
39
     */
40
    public function testSimple($format)
41
    {
42
        $document = $this->getDocument(static::$router->generate('test_default', ['templateName' => 'simple', '_format' => $format]), $format);
43
        static::assertNotNull($document, 'Document does not exist');
44
45
        $sheet = $document->getSheetByName('Test');
46
        static::assertNotNull($sheet, 'Sheet does not exist');
47
48
        static::assertEquals(100270, $sheet->getCell('B22')->getValue(), 'Unexpected value in B22');
49
50
        static::assertEquals('=SUM(B2:B21)', $sheet->getCell('B23')->getValue(), 'Unexpected value in B23');
51
        static::assertTrue($sheet->getCell('B23')->isFormula(), 'Unexpected value in isFormula');
52
        static::assertEquals(100270, $sheet->getCell('B23')->getCalculatedValue(), 'Unexpected calculated value in B23');
53
    }
54
55
    /**
56
     * @param string $format
57
     *
58
     * @throws \Exception
59
     *
60
     * @dataProvider formatProvider
61
     */
62
    public function testCustomResponse($format)
63
    {
64
        // Generate URI
65
        $uri = static::$router->generate('test_custom_response', ['templateName' => 'simple', '_format' => $format]);
66
67
        // Generate source
68
        static::$client->request('GET', $uri);
69
70
        /**
71
         * @var Response
72
         */
73
        $response = static::$client->getResponse();
74
75
        static::assertNotNull($response, 'Response does not exist');
76
        static::assertEquals('attachment; filename="foobar.bin"', $response->headers->get('Content-Disposition'), 'Unexpected or missing header "Content-Disposition"');
77
        static::assertEquals(600, $response->getMaxAge(), 'Unexpected value in maxAge');
78
    }
79
80
    /**
81
     * @param string $format
82
     *
83
     * @throws \Exception
84
     *
85
     * @dataProvider formatProvider
86
     */
87
    public function testDocumentTemplatePath1($format)
88
    {
89
        $document = $this->getDocument(static::$router->generate('test_default', ['templateName' => 'documentTemplatePath1', '_format' => $format]), $format);
90
        static::assertNotNull($document, 'Document does not exist');
91
92
        $sheet = $document->getSheet(0);
93
        static::assertNotNull($sheet, 'Sheet does not exist');
94
95
        static::assertEquals('Hello', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1');
96
        static::assertEquals('World', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1');
97
        static::assertEquals('Foo', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2');
98
        static::assertEquals('Bar', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2');
99
    }
100
101
    /**
102
     * @param string $format
103
     *
104
     * @throws \Exception
105
     *
106
     * @dataProvider formatProvider
107
     */
108
    public function testDocumentTemplatePath2($format)
109
    {
110
        $document = $this->getDocument(static::$router->generate('test_default', ['templateName' => 'documentTemplatePath2', '_format' => $format]), $format);
111
        static::assertNotNull($document, 'Document does not exist');
112
113
        $sheet = $document->getSheet(0);
114
        static::assertNotNull($sheet, 'Sheet does not exist');
115
116
        static::assertEquals('Hello', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1');
117
        static::assertEquals('World', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1');
118
        static::assertEquals('Foo', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2');
119
        static::assertEquals('Bar', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2');
120
    }
121
}
122