1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Scriptotek\Alma\Users; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
use Prophecy\Argument; |
7
|
|
|
use Psr\Http\Message\UriInterface; |
8
|
|
|
use Scriptotek\Alma\Client as AlmaClient; |
9
|
|
|
use Scriptotek\Alma\Users\User; |
10
|
|
|
use Scriptotek\Alma\Users\Users; |
11
|
|
|
use spec\Scriptotek\Alma\SpecHelper; |
12
|
|
|
|
13
|
|
|
class UsersSpec extends ObjectBehavior |
14
|
|
|
{ |
15
|
|
|
public function let(AlmaClient $client) |
16
|
|
|
{ |
17
|
|
|
$this->beConstructedWith($client); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function it_is_initializable() |
21
|
|
|
{ |
22
|
|
|
$this->shouldHaveType(Users::class); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function it_provides_lazy_lookup_by_id(AlmaClient $client) |
26
|
|
|
{ |
27
|
|
|
$client->buildUrl('/users/12345', []) |
28
|
|
|
->shouldNotBeCalled(); |
29
|
|
|
|
30
|
|
|
$user = $this->get('12345'); |
31
|
|
|
$user->shouldHaveType(User::class); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
View Code Duplication |
public function it_accepts_additional_parameters(AlmaClient $client, UriInterface $url) |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
$client->buildUrl('/users/12345', ['expand' => 'fees']) |
37
|
|
|
->shouldBeCalled() |
38
|
|
|
->willReturn($url); |
39
|
|
|
|
40
|
|
|
$client->getJSON($url) |
41
|
|
|
->shouldBeCalled() |
42
|
|
|
->willReturn(SpecHelper::getDummyData('user_response.json')); |
43
|
|
|
|
44
|
|
|
$this->get('12345', ['expand' => 'fees'])->init(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function it_provides_lookup_by_id(AlmaClient $client, UriInterface $url) |
48
|
|
|
{ |
49
|
|
|
$client->buildUrl('/users/12345', []) |
50
|
|
|
->shouldBeCalled() |
51
|
|
|
->willReturn($url); |
52
|
|
|
|
53
|
|
|
$client->getJSON($url) |
54
|
|
|
->shouldBeCalled() |
55
|
|
|
->willReturn(SpecHelper::getDummyData('user_response.json')); |
56
|
|
|
|
57
|
|
|
$user = $this->get('12345'); |
58
|
|
|
|
59
|
|
|
$user->shouldHaveType(User::class); |
60
|
|
|
$user->primary_id->shouldBe('12345'); |
61
|
|
|
$user->primaryId->shouldBe('12345'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
public function it_provides_search(AlmaClient $client) |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$client->getJSON(Argument::containingString('users'), Argument::any()) |
67
|
|
|
->willReturn(SpecHelper::getDummyData('users_response.json')); |
68
|
|
|
|
69
|
|
|
$users = $this->search('last_name~banan'); |
70
|
|
|
$first = $users->current(); |
71
|
|
|
|
72
|
|
|
$first->shouldHaveType(User::class); |
73
|
|
|
$first->primary_id->shouldBe('1234567'); |
74
|
|
|
$first->primaryId->shouldBe('1234567'); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.