Completed
Push — master ( 1f3e01...3b63e9 )
by Roman
10:06
created

ServiceProviderTest.php ➔ env()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
use Mockery as m;
4
5
if (!function_exists('env')) {
6
    function env($name, $default = null) {
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
7
        return $default;
8
    }
9
}
10
11
if (!function_exists('config_path')) {
12
    function config_path($path) {
13
        return $path;
14
    }
15
}
16
17
class ServiceProviderTokensTest extends PHPUnit_Framework_TestCase
18
{
19
    public function testRegister()
20
    {
21
        $app = $this->mockApplication();
22
23
        $provider = new \Framgia\Jwt\JwtServiceProvider($app);
0 ignored issues
show
Documentation introduced by
$app is of type object<Mockery\Mock>, but the function expects a object<Illuminate\Contra...Foundation\Application>.

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...
24
        $provider->register();
25
26
        $this->assertInstanceOf(\Framgia\Jwt\Storage\CacheStorage::class, $app->make(\Framgia\Jwt\Storage\CacheStorage::class));
27
        $this->assertInstanceOf(\Framgia\Jwt\Contracts\Storage::class, $app->make(\Framgia\Jwt\Contracts\Storage::class));
28
        $this->assertInstanceOf(\Framgia\Jwt\Blacklist::class, $app->make(\Framgia\Jwt\Blacklist::class));
29
        $this->assertInstanceOf(\Framgia\Jwt\Signers\Factory::class, $app->make(\Framgia\Jwt\Signers\Factory::class));
30
        $this->assertInstanceOf(\Framgia\Jwt\Contracts\Signer::class, $app->make(\Framgia\Jwt\Contracts\Signer::class));
31
    }
32
33
    public function testBoot()
34
    {
35
        $app = $this->mockApplication();
36
37
        $provider = new \Framgia\Jwt\JwtServiceProvider($app);
0 ignored issues
show
Documentation introduced by
$app is of type object<Mockery\Mock>, but the function expects a object<Illuminate\Contra...Foundation\Application>.

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...
38
        $provider->register();
39
40
        $auth = m::mock(\Illuminate\Auth\AuthManager::class);
41
        $auth->shouldReceive('extend')->once();
42
43
        $app->singleton(\Illuminate\Auth\AuthManager::class, function () use ($auth) {
44
            return $auth;
45
        });
46
47
        $provider->boot();
48
    }
49
50
    protected function mockApplication()
51
    {
52
        $app = m::mock(ApplicationStub::class)->makePartial();
53
54
        $app->singleton('config', function() {
55
            $repo = new \Illuminate\Config\Repository();
56
            $repo->set('jwt', include __DIR__.'/../config/jwt.php');
57
            return $repo;
58
        });
59
60
        $app->singleton(\Illuminate\Contracts\Cache\Repository::class, function() {
61
            return m::mock(\Illuminate\Contracts\Cache\Repository::class);
62
        });
63
64
        return $app;
65
    }
66
}
67
68
abstract class ApplicationStub extends \Illuminate\Container\Container implements \Illuminate\Contracts\Foundation\Application
69
{
70
}
71