1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Hello\Tests\Models\Clients\PersonalAccess; |
4
|
|
|
|
5
|
|
|
use ByTIC\Hello\Models\Clients\Client; |
6
|
|
|
use ByTIC\Hello\Models\Clients\Clients; |
7
|
|
|
use ByTIC\Hello\Models\Clients\PersonalAccess\ClientsManager; |
8
|
|
|
use ByTIC\Hello\Tests\AbstractTest; |
9
|
|
|
use ByTIC\Hello\Utility\ClientsHelper; |
10
|
|
|
use ByTIC\Hello\Utility\ModelsHelper; |
11
|
|
|
use Nip\Collections\Collection; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class ClientsManagerTest |
15
|
|
|
* @package ByTIC\Hello\Tests\Models\Clients\PersonalAccess |
16
|
|
|
*/ |
17
|
|
|
class ClientsManagerTest extends AbstractTest |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
public function testGetWithPersonalAccessClientId() |
21
|
|
|
{ |
22
|
|
|
$client = new Client(); |
23
|
|
|
|
24
|
|
|
ClientsHelper::personalAccessClientId(99); |
25
|
|
|
|
26
|
|
|
$clientsManager = \Mockery::mock(Clients::class)->makePartial(); |
27
|
|
|
$clientsManager->shouldReceive('findOne')->with(99)->andReturn($client); |
28
|
|
|
ModelsHelper::useClientsManager($clientsManager); |
|
|
|
|
29
|
|
|
|
30
|
|
|
$getClient = ClientsManager::get(); |
31
|
|
|
|
32
|
|
|
self::assertSame($getClient, $client); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetWithFindByRedirect() |
36
|
|
|
{ |
37
|
|
|
$client = new Client(); |
38
|
|
|
|
39
|
|
|
$clientsManager = \Mockery::mock(Clients::class)->makePartial(); |
40
|
|
|
$clientsManager->shouldReceive('findByRedirect') |
41
|
|
|
->with(ClientsHelper::PERSONAL_ACCESS_REDIRECT_URI) |
42
|
|
|
->andReturn(new Collection([$client])); |
43
|
|
|
ModelsHelper::useClientsManager($clientsManager); |
|
|
|
|
44
|
|
|
|
45
|
|
|
$getClient = ClientsManager::get(); |
46
|
|
|
|
47
|
|
|
self::assertSame($getClient, $client); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testGetWithCreate() |
51
|
|
|
{ |
52
|
|
|
$clientsManager = \Mockery::mock(Clients::class)->makePartial(); |
53
|
|
|
$clientsManager->shouldReceive('getPrimaryKey')->andReturn('id'); |
|
|
|
|
54
|
|
|
$clientsManager->shouldReceive('getModel')->andReturn(Client::class); |
55
|
|
|
$clientsManager->shouldReceive('findByRedirect') |
56
|
|
|
->with(ClientsHelper::PERSONAL_ACCESS_REDIRECT_URI) |
57
|
|
|
->andReturn(new Collection()); |
58
|
|
|
$clientsManager->shouldReceive('save'); |
59
|
|
|
|
60
|
|
|
ModelsHelper::useClientsManager($clientsManager); |
|
|
|
|
61
|
|
|
|
62
|
|
|
$client = ClientsManager::get(); |
63
|
|
|
|
64
|
|
|
self::assertInstanceOf(Client::class, $client); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param null|string $name |
|
|
|
|
70
|
|
|
* @dataProvider createDataProvider |
71
|
|
|
*/ |
72
|
|
|
public function testCreate($nameIn, $nameOut) |
73
|
|
|
{ |
74
|
|
|
$clientsManager = \Mockery::mock(Clients::class)->makePartial(); |
75
|
|
|
$clientsManager->shouldReceive('getPrimaryKey')->andReturn('id'); |
|
|
|
|
76
|
|
|
$clientsManager->shouldReceive('getModel')->andReturn(Client::class); |
77
|
|
|
$clientsManager->shouldReceive('save'); |
78
|
|
|
|
79
|
|
|
ModelsHelper::useClientsManager($clientsManager); |
|
|
|
|
80
|
|
|
$client = ClientsManager::create($nameIn); |
81
|
|
|
|
82
|
|
|
self::assertInstanceOf(Client::class, $client); |
83
|
|
|
self::assertSame($nameOut, $client->getName()); |
84
|
|
|
self::assertSame(32, strlen($client->getIdentifier())); |
85
|
|
|
self::assertGreaterThan(40, strlen($client->getSecret())); |
86
|
|
|
self::assertSame('INTERNAL_API', $client->getRedirectUri()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
public function createDataProvider() |
93
|
|
|
{ |
94
|
|
|
return [ |
95
|
|
|
[null, 'Personal Access Client'], |
96
|
|
|
['', 'Personal Access Client'], |
97
|
|
|
['test1', 'test1'], |
98
|
|
|
]; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function setUp() |
102
|
|
|
{ |
103
|
|
|
parent::setUp(); |
104
|
|
|
|
105
|
|
|
ClientsHelper::personalAccessClientId(null); |
106
|
|
|
ClientsManager::resetClient(); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
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: