Passed
Push — master ( 7bc374...cf39f3 )
by Arthur
05:05
created

HttpTest::getHttpUser()   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 0
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 Auth0\Login\Contract\Auth0UserRepository;
0 ignored issues
show
Bug introduced by
The type Auth0\Login\Contract\Auth0UserRepository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Illuminate\Contracts\Auth\Authenticatable;
13
use Modules\Auth0\Services\Auth0Service;
14
use Modules\User\Entities\User;
15
16
abstract class HttpTest extends \Foundation\Abstracts\Tests\TestCase
17
{
18
    /**
19
     * @var Auth0Service
20
     */
21
    protected $service;
22
23 10
    public function setUp()
24
    {
25 10
        parent::setUp();
26 10
        $this->service = $this->app->make(Auth0UserRepository::class);
27 10
    }
28
29
    /**
30
     * @return User | Authenticatable
31
     */
32 7
    protected function getHttpUser()
33
    {
34 7
        return $this->service->getPredefinedUser();
35
    }
36
37 2
    protected function decodeHttpContent($content, $unwrap = true)
38
    {
39 2
        if ($unwrap) {
40 2
            return json_decode($content, true)['data'];
41
        }
42
43
        return json_decode($content, true);
44
    }
45
46 6
    protected function http(string $method, string $route, array $payload = [])
47
    {
48 6
        return $this->sendRequest($method, $route, $payload, true);
49
    }
50
51 7
    private function sendRequest(string $method, string $route, array $payload = [], $authenticated = true): \Illuminate\Foundation\Testing\TestResponse
52
    {
53 7
        return $this->json($method, env('API_URL').'/'.$route, $payload, $authenticated ? [
54 6
            'Authorization' => 'Bearer '.$this->service->getPredefinedUserTokenData()->id_token,
55 7
        ] : []);
56
    }
57
58
    protected function sendRequestWithToken($token, string $method, string $route, array $payload = [], $authenticated = true): \Illuminate\Foundation\Testing\TestResponse
59
    {
60
        return $this->json($method, env('API_URL').'/'.$route, $payload, $authenticated ? [
61
            'Authorization' => 'Bearer '.$token,
62
        ] : []);
63
    }
64
65 1
    protected function httpNoAuth(string $method, string $route, array $payload = [])
66
    {
67 1
        return $this->sendRequest($method, $route, $payload, false);
68
    }
69
}
70