Passed
Push — main ( 47f0cd...b1d2fe )
by Dylan
01:56
created

AppTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 20
c 1
b 0
f 0
dl 0
loc 53
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testChallenge() 0 10 1
A testConstruct() 0 10 1
A testAuthURL() 0 10 1
1
<?php
2
3
namespace Lifeboat\Tests;
4
5
use Lifeboat\App;
6
use Lifeboat\Client;
7
use Lifeboat\Exceptions\InvalidArgumentException;
8
use Lifeboat\Utils\Utils;
9
10
class AppTest extends Connector {
11
12
    /**
13
     * @test
14
     * @covers \Lifeboat\App::__construct
15
     * @covers \Lifeboat\App::getAppID
16
     * @covers \Lifeboat\App::getAppSecret
17
     * @covers \Lifeboat\App::setAppID
18
     * @covers \Lifeboat\App::setAppSecret
19
     */
20
    public function testConstruct()
21
    {
22
        $app = new App('app_id', 'secret');
23
        $this->assertInstanceOf(App::class, $app);
24
25
        $this->assertEquals('app_id', $app->getAppID());
26
        $this->assertEquals('secret', $app->getAppSecret());
27
28
        $this->expectException(InvalidArgumentException::class);
29
        new App('', '');
30
    }
31
32
    /**
33
     * @test
34
     * @covers \Lifeboat\App::getAPIChallenge
35
     * @covers \Lifeboat\App::setAPIChallenge
36
     */
37
    public function testChallenge()
38
    {
39
        $app = new App('mock', 'mock');
40
41
        $challenge = '123';
42
        $app->setAPIChallenge($challenge);
43
        $this->assertEquals($challenge, $app->getAPIChallenge());
44
45
        $app->setAPIChallenge('');
46
        $this->assertEquals(128, strlen($app->getAPIChallenge()));
47
    }
48
49
    /**
50
     * @test
51
     * @covers \Lifeboat\App::getAuthURL
52
     */
53
    public function testAuthURL()
54
    {
55
        $app    = new App('id', 'secret', 'http://test.domain');
56
        $url    = $app->getAuthURL('process.php', 'error.php', 'challenge');
57
        $expect = 'http://test.domain/oauth/code?app_id=id&process_url=' .
58
            urlencode('process.php') .
59
            '&error_url=' . urlencode('error.php') .
60
            '&challenge=' . Utils::pack('challenge');
61
62
        $this->assertEquals($expect, $url);
63
    }
64
}
65