Completed
Branch master (5105da)
by Stefano
02:21
created

TokenTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 43
rs 10
c 1
b 0
f 1
1
<?php
2
3
class TokenTest extends PHPUnit_Framework_TestCase {
4
5
    public function testEncode(){
6
				$results = Token::encode("TEST","1234");
7
        $this->assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.IlRFU1Qi.zPCpn5hHX3CdtmvSDt_apcanyuDjGT9W8KcCgTMyrXE", $results);
8
    }
9
10
    public function testDecode(){
11
12
				try {
13
					$results = Token::decode("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.IlRFU1Qi.zPCpn5hHX3CdtmvSDt_apcanyuDjGT9W8KcCgTMyrXE","1234");
14
				} catch(Exception $e) {
15
					$this->fail("Exception throwed");
16
				}
17
18
        $this->assertEquals("TEST", $results);
19
    }
20
21
    public function testWrongSecret(){
22
23
				try {
24
					$results = Token::decode("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.IlRFU1Qi.zPCpn5hHX3CdtmvSDt_apcanyuDjGT9W8KcCgTMyrXE","41231");
25
					$this->fail("Expected exception 'WrongSecret' not thrown");
26
				} catch(Exception $e) {
27
					$results = false;
28
				}
29
30
        $this->assertFalse($results);
31
    }
32
33
    public function testInvalidToken(){
34
35
				try {
36
					$results = Token::decode("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.IlRFU1Qi","1234");
37
					$this->fail("Expected exception 'InvalidToken' not thrown");
38
				} catch(Exception $e) {
39
					$results = false;
40
				}
41
42
        $this->assertFalse($results);
43
    }
44
45
}
46
47