FacebookCakeSessionPersistentDataHandlerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 47
c 2
b 0
f 0
dl 0
loc 74
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanSetAValue() 0 15 1
A testInactiveSessionsWillThrowFacebooksdkxception() 0 17 1
A testGettingAValueThatDoesntExistWillReturnNull() 0 14 1
A testCanGetAValue() 0 15 1
1
<?php
2
3
namespace WrDX\Facebook\Tests;
4
5
use WrDX\Facebook\FacebookCakeSessionPersistentDataHandler;
6
7
class FacebookCakeSessionPersistentDataHandlerTest extends \PHPUnit_Framework_TestCase {
8
9
    /**
10
     * @expectedException \Facebook\Exceptions\FacebookSDKException
11
     */
12
    public function testInactiveSessionsWillThrowFacebooksdkxception() {
13
        $CakeSession = $this
14
            ->getMockBuilder('CakeSession')
15
            ->setMethods(['valid', 'started'])
16
            ->getMock();
17
18
        $CakeSession
19
            ->expects($this->once())
20
            ->method('valid')
21
            ->will($this->returnValue(true));
22
23
        $CakeSession
24
            ->expects($this->once())
25
            ->method('started')
26
            ->will($this->returnValue(false));
27
28
        new FacebookCakeSessionPersistentDataHandler($CakeSession);
29
    }
30
31
    public function testCanSetAValue() {
32
33
        $CakeSession = $this
34
            ->getMockBuilder('CakeSession')
35
            ->setMethods(['write'])
36
            ->getMock();
37
38
        $CakeSession
39
            ->expects($this->once())
40
            ->method('write')
41
            ->will($this->returnValue(true));
42
43
        $handler = new FacebookCakeSessionPersistentDataHandler($CakeSession, $enableSessionCheck = false, 'Test');
44
        $value = $handler->set('foo', 'bar');
45
        $this->assertTrue($value);
46
47
    }
48
49
    public function testCanGetAValue() {
50
51
        $CakeSession = $this
52
            ->getMockBuilder('CakeSession')
53
            ->setMethods(['read'])
54
            ->getMock();
55
56
        $CakeSession
57
            ->expects($this->once())
58
            ->method('read')
59
            ->will($this->returnValue('baz'));
60
61
        $handler = new FacebookCakeSessionPersistentDataHandler($CakeSession, $enableSessionCheck = false, 'Test');
62
        $value = $handler->get('faz');
63
        $this->assertEquals('baz', $value);
64
65
    }
66
67
    public function testGettingAValueThatDoesntExistWillReturnNull() {
68
        $CakeSession = $this
69
            ->getMockBuilder('CakeSession')
70
            ->setMethods(['read'])
71
            ->getMock();
72
73
        $CakeSession
74
            ->expects($this->once())
75
            ->method('read')
76
            ->will($this->returnValue(null));
77
78
        $handler = new FacebookCakeSessionPersistentDataHandler($CakeSession, $enableSessionCheck = false);
79
        $value = $handler->get('does_not_exist');
80
        $this->assertNull($value);
81
    }
82
83
}
84
85