CollectionTest.php 2.11 KB
Newer Older
1 2 3 4 5
<?php

namespace yiiunit\extensions\authclient;

use yii\authclient\Collection;
6
use yii\authclient\BaseClient;
7 8 9

class CollectionTest extends TestCase
{
10
    // Tests :
11

12 13 14
    public function testSetGet()
    {
        $collection = new Collection();
15

16 17 18 19 20 21 22
        $clients = [
            'testClient1' => new TestClient(),
            'testClient2' => new TestClient(),
        ];
        $collection->setClients($clients);
        $this->assertEquals($clients, $collection->getClients(), 'Unable to setup clients!');
    }
23

24 25 26 27 28 29
    /**
     * @depends testSetGet
     */
    public function testGetProviderById()
    {
        $collection = new Collection();
30

31 32 33 34 35 36
        $clientId = 'testClientId';
        $client = new TestClient();
        $clients = [
            $clientId => $client
        ];
        $collection->setClients($clients);
37

38 39
        $this->assertEquals($client, $collection->getClient($clientId), 'Unable to get client by id!');
    }
40

41 42 43 44 45 46
    /**
     * @depends testGetProviderById
     */
    public function testCreateProvider()
    {
        $collection = new Collection();
47

48 49 50 51 52 53 54 55
        $clientId = 'testClientId';
        $clientClassName = TestClient::className();
        $clients = [
            $clientId => [
                'class' => $clientClassName
            ]
        ];
        $collection->setClients($clients);
56

57 58 59 60
        $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!');
    }
61

62 63 64 65 66 67
    /**
     * @depends testSetGet
     */
    public function testHasProvider()
    {
        $collection = new Collection();
68

69 70 71 72 73 74 75
        $clientName = 'testClientName';
        $clients = [
            $clientName => [
                'class' => 'TestClient1'
            ],
        ];
        $collection->setClients($clients);
76

77 78 79
        $this->assertTrue($collection->hasClient($clientName), 'Existing client check fails!');
        $this->assertFalse($collection->hasClient('unExistingClientName'), 'Not existing client check fails!');
    }
80 81
}

82
class TestClient extends BaseClient
83
{
AlexGx committed
84
}