-
Notifications
You must be signed in to change notification settings - Fork 11
/
ConnectionTest.php
89 lines (74 loc) · 2.26 KB
/
ConnectionTest.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
88
89
<?php
/*
* This file is part of the NNTP library.
*
* (c) Robin van der Vleuten <robinvdvleuten@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Rvdv\Nntp\Tests\Connection;
use Rvdv\Nntp\Connection\Connection;
use Rvdv\Nntp\Connection\ConnectionInterface;
use Rvdv\Nntp\Exception\RuntimeException;
use Rvdv\Nntp\Exception\SocketException;
/**
* @author Robin van der Vleuten <robinvdvleuten@gmail.com>
*/
class ConnectionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ConnectionInterface
*/
private $connection;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $socket;
/**
* {@inheritdoc}
*/
public function setup()
{
$this->socket = $this->getMockBuilder('Rvdv\Nntp\Socket\Socket')
->disableOriginalConstructor()
->getMock();
$this->socket->expects($this->once())
->method('connect')
->with('tcp://localhost:5000')
->willReturnSelf();
$this->connection = new Connection('localhost', 5000, false, $this->socket);
}
public function testConnectionCanBeEstablishedThroughSocket()
{
$this->socket->expects($this->atLeastOnce())
->method('eof')
->willReturn(false);
$this->socket->expects($this->once())
->method('gets')
->with(1024)
->willReturn("200 server ready - posting allowed\r\n");
$response = $this->connection->connect();
$this->assertInstanceof('Rvdv\Nntp\Response\Response', $response);
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('server ready - posting allowed', $response->getMessage());
}
/**
* @expectedException RuntimeException
*/
public function testErrorIsThrownWhenConnectionCannotBeEstablished()
{
$this->socket->expects($this->once())
->method('connect')
->with('tcp://localhost:5000')
->willThrowException(new SocketException());
$this->connection->connect();
}
/**
* {@inheritdoc}
*/
public function teardown()
{
unset($this->socket);
}
}