Completed
Push — master ( 3af4ba...2384d0 )
by Avtandil
05:20
created

MiddlewareTest::getEnvironmentSetUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Tests\Unit;
5
6
use Longman\LaravelLodash\Middlewares\AllowCorsRequests;
7
8
class MiddlewareTest extends TestCase
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
9
{
10
    protected function getEnvironmentSetUp($app)
11
    {
12
        /** @var \Illuminate\Routing\Router $router */
13
        $router = $app['router'];
14
15
        $router->get('url1', function () {
16
            return 'ok';
17
        })->middleware(AllowCorsRequests::class);
18
    }
19
20
    /** @test */
21
    public function it_should_return_error_on_invalid_origin()
22
    {
23
        config()->set('lodash.cors.allow_origins', ['domain.com']);
24
25
        // Invalid domain
26
        $response = $this->call('GET', 'url1', [], [], [], ['HTTP_Origin' => 'safsagsafsadsadsa']);
0 ignored issues
show
Documentation introduced by
array('HTTP_Origin' => 'safsagsafsadsadsa') is of type array<string,string,{"HTTP_Origin":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
27
        $response->assertStatus(400); // Bad request
0 ignored issues
show
Bug introduced by
The method assertStatus() does not exist on Illuminate\Http\Response. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
28
29
        // Without http://
30
        $response = $this->call('GET', 'url1', [], [], [], ['HTTP_Origin' => 'google.com']);
0 ignored issues
show
Documentation introduced by
array('HTTP_Origin' => 'google.com') is of type array<string,string,{"HTTP_Origin":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
        $response->assertStatus(400); // Bad request
0 ignored issues
show
Bug introduced by
The method assertStatus() does not exist on Illuminate\Http\Response. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
32
33
        // Valid domain, but not whitelisted
34
        $response = $this->call('GET', 'url1', [], [], [], ['HTTP_Origin' => 'http://google.com']);
0 ignored issues
show
Documentation introduced by
array('HTTP_Origin' => 'http://google.com') is of type array<string,string,{"HTTP_Origin":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
        $response->assertStatus(405); // Method not allowed
0 ignored issues
show
Bug introduced by
The method assertStatus() does not exist on Illuminate\Http\Response. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
36
37
        // Valid similar domain, but not whitelisted
38
        $response = $this->call('GET', 'url1', [], [], [], ['HTTP_Origin' => 'http://mydomain.com']);
0 ignored issues
show
Documentation introduced by
array('HTTP_Origin' => 'http://mydomain.com') is of type array<string,string,{"HTTP_Origin":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
        $response->assertStatus(405); // Method not allowed
0 ignored issues
show
Bug introduced by
The method assertStatus() does not exist on Illuminate\Http\Response. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
40
    }
41
42
    /** @test */
43
    public function it_should_return_success_on_valid_origin()
44
    {
45
        config()->set('lodash.cors.allow_origins', ['domain.com']);
46
47
        $origins = config('lodash.cors.allow_origins');
48
49
        // Whitelisted origin
50
        $response = $this->call('GET', 'url1', [], [], [], ['HTTP_Origin' => 'http://' . $origins[0]]);
0 ignored issues
show
Documentation introduced by
array('HTTP_Origin' => 'http://' . $origins[0]) is of type array<string,string,{"HTTP_Origin":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
51
        $response->assertStatus(200);
0 ignored issues
show
Bug introduced by
The method assertStatus() does not exist on Illuminate\Http\Response. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
52
53
        // Whitelisted subdomain origin
54
        $response = $this->call('GET', 'url1', [], [], [], ['HTTP_Origin' => 'http://sub.' . $origins[0]]);
0 ignored issues
show
Documentation introduced by
array('HTTP_Origin' => '...://sub.' . $origins[0]) is of type array<string,string,{"HTTP_Origin":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
        $response->assertStatus(200);
0 ignored issues
show
Bug introduced by
The method assertStatus() does not exist on Illuminate\Http\Response. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
56
    }
57
58
    /** @test */
59
    public function it_should_return_success_on_project_url()
60
    {
61
        config()->set('lodash.cors.allow_origins', ['domain.com']);
62
63
        // Whitelisted origin
64
        $response = $this->call('GET', 'url1', [], [], [], ['HTTP_Origin' => config('app.url', 'http://localhost')]);
0 ignored issues
show
Documentation introduced by
array('HTTP_Origin' => c...', 'http://localhost')) is of type array<string,*,{"HTTP_Origin":"*"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65
        $response->assertStatus(200);
0 ignored issues
show
Bug introduced by
The method assertStatus() does not exist on Illuminate\Http\Response. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
66
    }
67
}
68