1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the silex-annotation-provider package. |
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
5
|
|
|
* file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @license MIT License |
8
|
|
|
* @copyright (c) 2018, Dana Desrosiers <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace DDesrosiers\Test\SilexAnnotations\Annotations; |
12
|
|
|
|
13
|
|
|
use DDesrosiers\Test\SilexAnnotations\AnnotationTestBase; |
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
15
|
|
|
|
16
|
|
View Code Duplication |
class RequireHttpsTest extends AnnotationTestBase |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
public function testHttps() |
19
|
|
|
{ |
20
|
|
|
$this->assertEndPointStatus(self::GET_METHOD, "/test/requirehttps", self::STATUS_OK); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @throws \Exception |
25
|
|
|
*/ |
26
|
|
|
public function testHttp() |
27
|
|
|
{ |
28
|
|
|
// we make the request as http, but it should be redirected to a https request |
29
|
|
|
$this->registerProviders(); |
30
|
|
|
$_SERVER['REQUEST_URI'] = '/test/requirehttps'; |
31
|
|
|
$request = Request::create('https://test.com/test/requirehttps'); |
32
|
|
|
$response = $this->app->handle($request); |
33
|
|
|
$this->assertEquals(301, $response->getStatusCode()); |
34
|
|
|
$this->assertTrue($response->isRedirect('http://test.com/test/requirehttps')); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testHttpsCollection() |
38
|
|
|
{ |
39
|
|
|
$this->assertEndPointStatus(self::GET_METHOD, "/test/requirehttps", self::STATUS_OK); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @throws \Exception |
44
|
|
|
*/ |
45
|
|
|
public function testHttpCollection() |
46
|
|
|
{ |
47
|
|
|
// we make the request as http, but it should be redirected to a https request |
48
|
|
|
$this->registerProviders(); |
49
|
|
|
$_SERVER['REQUEST_URI'] = '/test/requirehttps'; |
50
|
|
|
$request = Request::create('https://test.com/test/requirehttps'); |
51
|
|
|
$response = $this->app->handle($request); |
52
|
|
|
$this->assertEquals(301, $response->getStatusCode()); |
53
|
|
|
$this->assertTrue($response->isRedirect('http://test.com/test/requirehttps')); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
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.