Completed
Push — master ( 6cab55...c82b86 )
by Roman
02:16
created

ServiceProviderTokensTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 50
rs 10
wmc 3
lcom 1
cbo 6
1
<?php
2
3
use Mockery as m;
4
5
if (!function_exists('env')) {
6
    function env($name, $default = null) {
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);
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);
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