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() |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
|
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.