LegacyScriptControllerTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 88
Duplicated Lines 21.59 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 19
loc 88
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A phpSelfShouldBeRequestPath() 0 9 1
A doRunLegacyScript() 0 14 1
A shouldRunPrependSriptIfGiven() 9 9 1
A shouldRunAppendScriptIfGiven() 10 10 1
A setUp() 0 10 1
A getLegacyFile() 0 4 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 Basster\LegacyBridgeBundle\Tests\Controller;
4
5
use Basster\LegacyBridgeBundle\Controller\LegacyScriptController;
6
use Symfony\Component\DependencyInjection\Container;
7
use Symfony\Component\Finder\SplFileInfo;
8
9
class LegacyScriptControllerTest extends \PHPUnit_Framework_TestCase
10
{
11
    /** @var  Container */
12
    private $container;
13
14
    /** @var  LegacyScriptController */
15
    private $controller;
16
17
    /** @var  \Symfony\Component\Finder\SplFileInfo */
18
    private $legacyFile;
19
20
    /** @var  string */
21
    private $legacyScript;
22
23
    /**
24
     * @test
25
     */
26
    public function phpSelfShouldBeRequestPath()
27
    {
28
        $this->doRunLegacyScript();
29
30
        self::assertEquals(__FILE__, $_SERVER['PHP_SELF']);
31
        self::assertEquals(__FILE__, $_SERVER['SCRIPT_NAME']);
32
        self::assertEquals($this->legacyScript, $_SERVER['SCRIPT_FILENAME']);
33
        self::assertEquals($this->container, $_SERVER['SYMFONY_CONTAINER']);
34
    }
35
36
    private function doRunLegacyScript()
37
    {
38
        $streamedResponse = $this->controller->runLegacyScript(
39
          $this->legacyFile->getPathname(),
40
          $this->legacyFile->getRelativePathname()
41
        );
42
43
        self::assertInstanceOf(
44
          'Symfony\Component\HttpFoundation\StreamedResponse',
45
          $streamedResponse
46
        );
47
48
        $streamedResponse->sendContent();
49
    }
50
51
    /**
52
     * @test
53
     */
54 View Code Duplication
    public function shouldRunPrependSriptIfGiven()
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...
55
    {
56
        $this->controller->setPrependScript(__DIR__ . '/_files/prepend.php');
57
58
        $this->doRunLegacyScript();
59
60
        self::assertArrayHasKey('prepend_something', $_SERVER);
61
        self::assertEquals('something', $_SERVER['prepend_something']);
62
    }
63
64
    /**
65
     * @test
66
     */
67 View Code Duplication
    public function shouldRunAppendScriptIfGiven()
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...
68
    {
69
        $this->controller->setAppendScript(__DIR__ . '/_files/append.php');
70
71
        $this->doRunLegacyScript();
72
73
        self::assertArrayHasKey('append_foo', $_SERVER);
74
        self::assertEquals('foo', $_SERVER['append_foo']);
75
76
    }
77
78
    protected function setUp()
79
    {
80
        $this->legacyScript = __DIR__ . '/_files/hello.php';
81
        $this->legacyFile   = $this->getLegacyFile();
82
83
        $this->container = new Container();
84
85
        $this->controller = new LegacyScriptController();
86
        $this->controller->setContainer($this->container);
87
    }
88
89
    /**
90
     * @return \Symfony\Component\Finder\SplFileInfo
91
     */
92
    private function getLegacyFile()
93
    {
94
        return new SplFileInfo(__FILE__, __DIR__, $this->legacyScript);
95
    }
96
}
97