forked from doctrine/couchdb-client
/
CouchDBClientTest.php
91 lines (79 loc) · 2.86 KB
/
CouchDBClientTest.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
90
91
<?php
namespace Doctrine\Tests\CouchDB;
use Doctrine\CouchDB\CouchDBClient;
use Doctrine\CouchDB\HTTP\SocketClient;
class CouchDBClientTest extends \PHPUnit_Framework_TestCase
{
public function testConstants()
{
$this->assertEquals("\xEF\xBF\xB0", CouchDBClient::COLLATION_END);
}
public function testCreateClient()
{
$client = CouchDBClient::create(array('dbname' => 'test'));
$this->assertEquals('test', $client->getDatabase());
$this->assertInstanceOf('\Doctrine\CouchDB\HTTP\Client', $client->getHttpClient());
$httpClient = new SocketClient();
$client->setHttpClient($httpClient);
$this->assertEquals($httpClient, $client->getHttpClient());
}
public function testCreateClientFromUrl()
{
$client = CouchDBClient::create(array('url' => 'https://foo:bar@localhost:5555/baz'));
$this->assertEquals('baz', $client->getDatabase());
$this->assertEquals(
array(
'host' => 'localhost',
'port' => 5555,
'ip' => '127.0.0.1',
'username' => 'foo',
'password' => 'bar',
'ssl' => true,
'timeout' => 0.01,
'keep-alive' => true,
'path' => null,
),
$client->getHttpClient()->getOptions()
);
}
public function testCreateClientFromUrlWithPath()
{
$client = CouchDBClient::create(array('url' => 'https://foo:bar@localhost:5555/baz/qux/norf'));
$this->assertEquals('norf', $client->getDatabase());
$this->assertEquals(
array(
'host' => 'localhost',
'port' => 5555,
'ip' => '127.0.0.1',
'username' => 'foo',
'password' => 'bar',
'ssl' => true,
'timeout' => 0.01,
'keep-alive' => true,
'path' => 'baz/qux',
),
$client->getHttpClient()->getOptions()
);
}
public function testCreateClientWithLogging()
{
$client = CouchDBClient::create(array('dbname' => 'test', 'logging' => true));
$this->assertInstanceOf('\Doctrine\CouchDB\HTTP\LoggingClient', $client->getHttpClient());
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage 'dbname' is a required option to create a CouchDBClient
*/
public function testCreateClientDBNameException()
{
CouchDBClient::create(array());
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage There is no client implementation registered for foo, valid options are: socket, stream
*/
public function testCreateClientMissingClientException()
{
CouchDBClient::create(array('dbname' => 'test', 'type' => 'foo'));
}
}