UsersSpec   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_provides_lazy_lookup_by_id() 0 8 1
A it_accepts_additional_parameters() 0 8 1
A it_provides_lookup_by_id() 0 12 1
A it_provides_search() 0 12 1
1
<?php
2
3
namespace spec\Scriptotek\Alma\Users;
4
5
use PhpSpec\ObjectBehavior;
6
use Prophecy\Argument;
7
use Scriptotek\Alma\Client as AlmaClient;
8
use Scriptotek\Alma\Users\User;
9
use Scriptotek\Alma\Users\Users;
10
use spec\Scriptotek\Alma\SpecHelper;
11
12
class UsersSpec extends ObjectBehavior
13
{
14
    public function let(AlmaClient $client)
15
    {
16
        $this->beConstructedWith($client);
17
    }
18
19
    public function it_is_initializable()
20
    {
21
        $this->shouldHaveType(Users::class);
22
    }
23
24
    public function it_provides_lazy_lookup_by_id(AlmaClient $client)
25
    {
26
        $client->getJSON('/users/12345', [])
27
            ->shouldNotBeCalled();
28
29
        $user = $this->get('12345');
30
        $user->shouldHaveType(User::class);
31
    }
32
33
    public function it_accepts_additional_parameters(AlmaClient $client)
34
    {
35
        $client->getJSON('/users/12345?expand=fees')
36
            ->shouldBeCalled()
37
            ->willReturn(SpecHelper::getDummyData('user_response.json'));
38
39
        $this->get('12345', ['expand' => 'fees'])->init();
40
    }
41
42
    public function it_provides_lookup_by_id(AlmaClient $client)
43
    {
44
        $client->getJSON('/users/12345')
45
            ->shouldBeCalled()
46
            ->willReturn(SpecHelper::getDummyData('user_response.json'));
47
48
        $user = $this->get('12345');
49
50
        $user->shouldHaveType(User::class);
51
        $user->primary_id->shouldBe('12345');
52
        $user->primaryId->shouldBe('12345');
53
    }
54
55
    public function it_provides_search(AlmaClient $client)
56
    {
57
        $client->getJSON(Argument::containingString('users'), Argument::any())
58
            ->willReturn(SpecHelper::getDummyData('users_response.json'));
59
60
        $users = $this->search('last_name~banan');
61
        $first = $users->current();
62
63
        $first->shouldHaveType(User::class);
64
        $first->primary_id->shouldBe('1234567');
65
        $first->primaryId->shouldBe('1234567');
66
    }
67
}
68