1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace yiiunit\extensions\authclient;
use yii\authclient\Collection;
use yii\authclient\BaseClient;
class CollectionTest extends TestCase
{
// Tests :
public function testSetGet()
{
$collection = new Collection();
$clients = [
'testClient1' => new TestClient(),
'testClient2' => new TestClient(),
];
$collection->setClients($clients);
$this->assertEquals($clients, $collection->getClients(), 'Unable to setup clients!');
}
/**
* @depends testSetGet
*/
public function testGetProviderById()
{
$collection = new Collection();
$clientId = 'testClientId';
$client = new TestClient();
$clients = [
$clientId => $client
];
$collection->setClients($clients);
$this->assertEquals($client, $collection->getClient($clientId), 'Unable to get client by id!');
}
/**
* @depends testGetProviderById
*/
public function testCreateProvider()
{
$collection = new Collection();
$clientId = 'testClientId';
$clientClassName = TestClient::className();
$clients = [
$clientId => [
'class' => $clientClassName
]
];
$collection->setClients($clients);
$provider = $collection->getClient($clientId);
$this->assertTrue(is_object($provider), 'Unable to create client by config!');
$this->assertTrue(is_a($provider, $clientClassName), 'Client has wrong class name!');
}
/**
* @depends testSetGet
*/
public function testHasProvider()
{
$collection = new Collection();
$clientName = 'testClientName';
$clients = [
$clientName => [
'class' => 'TestClient1'
],
];
$collection->setClients($clients);
$this->assertTrue($collection->hasClient($clientName), 'Existing client check fails!');
$this->assertFalse($collection->hasClient('unExistingClientName'), 'Not existing client check fails!');
}
}
class TestClient extends BaseClient
{
}