-
Notifications
You must be signed in to change notification settings - Fork 0
/
SessionTest.php
87 lines (68 loc) · 2.24 KB
/
SessionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace Phipe;
use Phipe\Connection\Prober;
class SessionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Session
*/
protected $session;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $pool;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $prober;
/**
* @var \PHPUnit_Framework_MockObject_MockObject[]
*/
protected $strategies = [];
protected function setUp()
{
$this->pool = $this->getMock(Pool::CLASS);
$this->prober = $this->getMock(Prober::CLASS);
$this->strategies = [
'connect' => $this->getMock(Strategy\Connect::CLASS),
'reconnect' => $this->getMock(Strategy\Reconnect::CLASS),
'disconnect' => $this->getMock(Strategy\Disconnect::CLASS),
'activity_detect' => $this->getMock(Strategy\ActivityDetect::CLASS)
];
$this->session = new Session($this->pool, $this->prober, $this->strategies);
}
public function testInitialise()
{
$this->strategies['connect']->expects($this->once())
->method('performConnect')
->with($this->equalTo($this->pool));
$this->session->initialise();
}
public function testWork()
{
$this->strategies['reconnect']->expects($this->once())
->method('performReconnect')
->with($this->equalTo($this->pool));
$this->strategies['disconnect']->expects($this->once())
->method('performDisconnect')
->with($this->equalTo($this->pool));
$this->strategies['activity_detect']->expects($this->once())
->method('performDetect')
->with($this->equalTo($this->pool), $this->equalTo($this->prober));
$this->session->work();
}
public function testHasWork()
{
$this->pool->expects($this->once())
->method('count')
->will($this->returnValue(1));
$this->assertTrue($this->session->hasWork());
}
public function testHasWorkWithNoneAvailable()
{
$this->pool->expects($this->once())
->method('count')
->will($this->returnValue(0));
$this->assertFalse($this->session->hasWork());
}
}