Passed
Push — master ( 139939...b4b8e8 )
by Arthur
21:54 queued 17s
created

HttpTest::httpNoAuth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 09.10.18
6
 * Time: 21:56.
7
 */
8
9
namespace Foundation\Abstracts\Tests;
10
11
use Illuminate\Foundation\Testing\TestResponse;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Foundation\Abstracts\Tests\TestResponse. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
12
13
abstract class HttpTest extends \Foundation\Abstracts\Tests\TestCase
14
{
15
16
    protected function decodeHttpResponse($content, $unwrap = true)
17
    {
18
        if ($content instanceof TestResponse) {
19
            $content = $content->content();
20
        }
21
22
        if ($unwrap) {
23
            return json_decode($content, true)['data'] ?? json_decode($content, true);
24
        }
25
26
        return json_decode($content, true);
27 35
    }
28
29 35
    protected function http(string $method, string $route, array $payload = [], array $headers = []) : \Foundation\Abstracts\Tests\TestResponse
30 35
    {
31
        if(!in_array($method,['GET','POST','PATCH','DELETE','PUT']))
32 33
            throw new \Exception("Invalid Http Method");
33
34 33
        return new \Foundation\Abstracts\Tests\TestResponse($this->json($method, env('API_URL').$route, $payload, $headers)->baseResponse);
35 33
    }
36
}
37