AppTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 22
c 1
b 0
f 0
dl 0
loc 58
rs 10

3 Methods

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