Completed
Push — master ( eac4d5...ebfc2c )
by Daniel
11s
created

testWriteReturnsFalseWithNoHandlers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SilverStripe\HybridSessions\Tests;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverStripe\HybridSessions\HybridSession;
7
use SilverStripe\HybridSessions\Store\BaseStore;
8
use SilverStripe\HybridSessions\Tests\Store\TestCookieStore;
9
10
class HybridSessionTest extends SapphireTest
11
{
12
    /**
13
     * @var BaseStore
14
     */
15
    protected $handler;
16
17
    /**
18
     * @var HybridSession
19
     */
20
    protected $instance;
21
22
    protected function setUp()
23
    {
24
        parent::setUp();
25
26
        $this->handler = $this->createMock(TestCookieStore::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Silve...TestCookieStore::class) of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<SilverStripe\Hybr...ssions\Store\BaseStore> of property $handler.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
28
        $this->instance = new HybridSession();
29
    }
30
31
    public function testSetHandlersAlsoSetsKeyToEachHandler()
32
    {
33
        $this->instance->setKey('foobar');
34
        $this->handler->expects($this->once())->method('setKey')->with('foobar');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<SilverStripe\Hybr...ssions\Store\BaseStore>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
        $this->instance->setHandlers([$this->handler]);
36
    }
37
38
    public function testOpenDelegatesToAllHandlers()
39
    {
40
        $this->handler->expects($this->once())->method('open')->with('foo', 'bar');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<SilverStripe\Hybr...ssions\Store\BaseStore>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
        $this->instance->setHandlers([$this->handler]);
42
        $this->assertTrue($this->instance->open('foo', 'bar'), 'Method returns true after delegation');
43
    }
44
45
    public function testCloseDelegatesToAllHandlers()
46
    {
47
        $this->handler->expects($this->once())->method('close');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<SilverStripe\Hybr...ssions\Store\BaseStore>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
        $this->instance->setHandlers([$this->handler]);
49
        $this->assertTrue($this->instance->close(), 'Method returns true after delegation');
50
    }
51
52
    public function testReadReturnsEmptyStringWithNoHandlers()
53
    {
54
        $this->handler->expects($this->once())->method('read')->with('foosession')->willReturn(false);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<SilverStripe\Hybr...ssions\Store\BaseStore>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
        $this->instance->setHandlers([$this->handler]);
56
        $this->assertSame('', $this->instance->read('foosession'));
57
    }
58
59
    public function testReadReturnsHandlerDelegateResult()
60
    {
61
        $this->handler->expects($this->once())->method('read')->with('foo.session')->willReturn('success!');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<SilverStripe\Hybr...ssions\Store\BaseStore>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
        $this->instance->setHandlers([$this->handler]);
63
        $this->assertSame('success!', $this->instance->read('foo.session'));
64
    }
65
66
    public function testWriteDelegatesToHandlerAndReturnsTrue()
67
    {
68
        $this->handler->expects($this->once())->method('write')->with('foo', 'bar')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<SilverStripe\Hybr...ssions\Store\BaseStore>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
        $this->instance->setHandlers([$this->handler]);
70
        $this->assertTrue($this->instance->write('foo', 'bar'));
71
    }
72
73
    public function testWriteReturnsFalseWithNoHandlers()
74
    {
75
        $this->assertFalse($this->instance->write('no', 'handlers'));
76
    }
77
78
    public function testDestroyDelegatesToHandler()
79
    {
80
        $this->handler->expects($this->once())->method('destroy')->with('sessid1234');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<SilverStripe\Hybr...ssions\Store\BaseStore>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
81
        $this->instance->setHandlers([$this->handler]);
82
        $this->assertTrue($this->instance->destroy('sessid1234'), 'Method returns true after delegation');
83
    }
84
85
    public function testGcDelegatesToHandlers()
86
    {
87
        $this->handler->expects($this->once())->method('gc')->with(12345);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<SilverStripe\Hybr...ssions\Store\BaseStore>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
88
        $this->instance->setHandlers([$this->handler]);
89
        $this->instance->gc(12345);
90
    }
91
}
92