-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathCreateTest.php
More file actions
156 lines (137 loc) · 3.97 KB
/
CreateTest.php
File metadata and controls
156 lines (137 loc) · 3.97 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
use PHPUnit\Framework\TestCase;
final class CreateTest extends TestCase
{
protected static $port, $tm;
public static function setUpBeforeClass() {
self::$port = getenv('PRIMARY_PORT');
self::$tm = ini_get("tarantool.timeout");
// error_log("before setting tarantool timeout");
ini_set("tarantool.timeout", "0.1");
// error_log("after setting tarantool timeout");
}
public static function tearDownAfterClass() {
ini_set("tarantool.timeout", self::$tm);
}
public function test_00_create_basic() {
$c = new Tarantool('localhost', self::$port);
$c->connect();
$this->assertTrue($c->ping());
$c->close();
}
public function test_01_create_test_ping_and_close() {
$c = new Tarantool('localhost', self::$port);
$c->connect();
$c->connect();
$this->assertTrue($c->ping());
$c->close();
$this->assertTrue($c->ping());
$c->close();
$c->close();
}
/**
* @doesNotPerformAssertions
*/
public function test_01_01_double_disconnect() {
$a = new Tarantool('localhost', self::$port);
$a->disconnect();
$a->disconnect();
}
/**
* @expectedException TarantoolException
* @expectedExceptionMessageRegExp /Name or service not known|nodename nor servname provided|getaddrinfo/
*/
public function test_02_create_error_host() {
(new Tarantool('very_bad_host'))->connect();
}
/**
* @expectedException TarantoolException
* @expectedExceptionMessageRegExp /Connection refused|Network is unreachable/
*/
public function test_03_00_create_error_port() {
(new Tarantool('localhost', 65500))->connect();
}
/**
* @expectedException TarantoolException
* @expectedExceptionMessage Invalid primary port value
*/
public function test_03_01_create_error_port() {
new Tarantool('localhost', 123456);
}
public function test_04_create_many_conns() {
$a = 1;
while ($a < 10) {
$this->assertTrue((new Tarantool('127.0.0.1', self::$port))->ping());
$a++;
}
}
public function test_05_flush_authenticate() {
$c = new Tarantool('localhost', self::$port);
$c->connect();
$this->assertTrue($c->ping());
$c->authenticate('test', 'test');
$c->select("test");
$c->flushSchema();
$c->select("test");
$c->flush_schema();
}
public function test_05_flush_construct() {
$c = new Tarantool('localhost', self::$port, 'test', 'test');
$this->assertTrue($c->ping());
$c->select("test");
$c->flushSchema();
$c->select("test");
$c->flush_schema();
}
/**
* @expectedException TarantoolClientError
* @expectedExceptionMessage Incorrect password supplied for user
*/
public function test_06_bad_credentials() {
$c = new Tarantool('localhost', self::$port);
$c->connect();
$this->assertTrue($c->ping());
$c->authenticate('test', 'bad_password');
}
/**
* @expectedException TarantoolClientError
* @expectedExceptionMessage Incorrect password supplied for user
*/
public function test_07_bad_guest_credentials() {
$c = new Tarantool('localhost', self::$port);
$c->connect();
$this->assertTrue($c->ping());
$c->authenticate('guest', 'guest');
}
/**
* @expectedException TarantoolClientError
* @expectedExceptionMessage Incorrect password supplied for user
*/
/**
* Comment this, since behaviour of authentication with 'empty password' has changed
public function test_07_01_bad_guest_credentials() {
$c = new Tarantool('localhost', self::$port);
$c->connect();
$this->assertTrue($c->ping());
$c->authenticate('guest', '');
}
*/
/**
* @dataProvider provideGoodCredentials
*/
public function test_08_good_credentials_construct($username, $password = null) {
if (func_num_args() === 1) {
$c = new Tarantool('localhost', self::$port, $username);
} else {
$c = new Tarantool('localhost', self::$port, $username, $password);
}
$this->assertTrue($c->ping());
}
public static function provideGoodCredentials()
{
return [
['guest'],
['guest', null],
];
}
}