Completed
Push — master ( b91597...be19b0 )
by Mitchel
02:09
created

TokenServiceTest::itReturnsASessionToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Bunq\Tests\Service;
4
5
use Bunq\Certificate\CertificateType;
6
use Bunq\Certificate\DefaultCertificate;
7
use Bunq\Certificate\Storage\CertificateStorage;
8
use Bunq\Service\InstallationService;
9
use Bunq\Service\DefaultTokenService;
10
use Bunq\Token\DefaultToken;
11
use Bunq\Token\Storage\TokenNotFoundException;
12
use Bunq\Token\Storage\TokenStorage;
13
use Bunq\Token\TokenType;
14
use PHPUnit\Framework\TestCase;
15
use Prophecy\Argument;
16
use Prophecy\Prophecy\ObjectProphecy;
17
18
final class TokenServiceTest extends TestCase
19
{
20
    /**
21
     * @var InstallationService|ObjectProphecy
22
     */
23
    private $installationService;
24
25
    /**
26
     * @var TokenStorage|ObjectProphecy
27
     */
28
    private $tokenStorage;
29
30
    /**
31
     * @var CertificateStorage|ObjectProphecy
32
     */
33
    private $certificateStorage;
34
35
    /**
36
     * @var DefaultTokenService
37
     */
38
    private $service;
39
40
    public function setUp()
41
    {
42
        $this->installationService = $this->prophesize(InstallationService::class);
43
        $this->tokenStorage        = $this->prophesize(TokenStorage::class);
44
        $this->certificateStorage  = $this->prophesize(CertificateStorage::class);
45
46
        $this->service = new DefaultTokenService(
47
            $this->installationService->reveal(),
48
            $this->tokenStorage->reveal(),
49
            $this->certificateStorage->reveal()
50
        );
51
    }
52
53
    /**
54
     * @test
55
     */
56
    public function itReturnsASessionToken()
57
    {
58
        $token = new DefaultToken('someToken');
59
        $this->tokenStorage->load(TokenType::SESSION_TOKEN())->willReturn($token);
0 ignored issues
show
Bug introduced by
The method load does only exist in Bunq\Token\Storage\TokenStorage, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
60
        $this->installationService->createSession(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The method createSession does only exist in Bunq\Service\InstallationService, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
61
62
        $result = $this->service->sessionToken();
63
64
        $this->assertEquals($token, $result);
65
    }
66
67
    /**
68
     * @test
69
     */
70
    public function itCreatesANewSessionTokenWhenItDoesNotExist()
71
    {
72
        $this->tokenStorage->load(TokenType::SESSION_TOKEN())->willThrow(
0 ignored issues
show
Bug introduced by
The method load does only exist in Bunq\Token\Storage\TokenStorage, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
73
            new TokenNotFoundException(TokenType::SESSION_TOKEN(), 'path')
74
        );
75
76
        $installationToken = new DefaultToken('installation_token');
77
        $this->tokenStorage->load(TokenType::INSTALLATION_TOKEN())->willReturn($installationToken);
78
79
        $this->installationService->install()->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The method install does only exist in Bunq\Service\InstallationService, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
80
        $this->installationService->createSession($installationToken)->willReturn('a-long-new-session-token');
0 ignored issues
show
Bug introduced by
The method createSession does only exist in Bunq\Service\InstallationService, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
81
        $this->installationService->registerDevice(Argument::any())->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The method registerDevice does only exist in Bunq\Service\InstallationService, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
82
83
        $sessionToken = DefaultToken::fromString('a-long-new-session-token');
84
85
        $this->tokenStorage->save($sessionToken, TokenType::SESSION_TOKEN())->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method save does only exist in Bunq\Token\Storage\TokenStorage, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
86
87
        $this->assertEquals($sessionToken, $this->service->sessionToken());
88
    }
89
90
    /**
91
     * @test
92
     */
93
    public function itCreatesANewSessionTokenAndInstallationTokenWithThePublicKey()
94
    {
95
        $this->tokenStorage->load(TokenType::SESSION_TOKEN())->willThrow(
0 ignored issues
show
Bug introduced by
The method load does only exist in Bunq\Token\Storage\TokenStorage, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
96
            new TokenNotFoundException(TokenType::SESSION_TOKEN(), 'path')
97
        );
98
        $this->tokenStorage->load(TokenType::INSTALLATION_TOKEN())->willThrow(
99
            new TokenNotFoundException(TokenType::INSTALLATION_TOKEN(), 'path')
100
        );
101
102
        $this->installationService->install()->willReturn(
0 ignored issues
show
Bug introduced by
The method install does only exist in Bunq\Service\InstallationService, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
103
            [
104
                'token'      => 'a-long-new-installation-token',
105
                'public_key' => '-----BEGIN PUBLIC KEY-----KEY-----END PUBLIC KEY-----'
106
            ]
107
        );
108
109
        $installationToken = DefaultToken::fromString('a-long-new-installation-token');
110
        $this->tokenStorage->save($installationToken, TokenType::INSTALLATION_TOKEN())->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method save does only exist in Bunq\Token\Storage\TokenStorage, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
111
112
        $certificate = DefaultCertificate::fromString('-----BEGIN PUBLIC KEY-----KEY-----END PUBLIC KEY-----');
113
        $this->certificateStorage->save($certificate, CertificateType::BUNQ_SERVER_KEY())->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method save does only exist in Bunq\Certificate\Storage\CertificateStorage, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
114
115
        $this->installationService->registerDevice($installationToken)->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method registerDevice does only exist in Bunq\Service\InstallationService, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
116
117
        $this->installationService->createSession($installationToken)->willReturn('a-long-new-session-token');
0 ignored issues
show
Bug introduced by
The method createSession does only exist in Bunq\Service\InstallationService, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
118
119
        $sessionToken = DefaultToken::fromString('a-long-new-session-token');
120
121
        $this->tokenStorage->save($sessionToken, TokenType::SESSION_TOKEN())->shouldBeCalled();
122
123
        $this->assertEquals($sessionToken, $this->service->sessionToken());
124
    }
125
}
126
127