Skip to content

Commit dc72b6c

Browse files
committed
Make testsuite run once for 'Connection: Close' and once for 'Connection: Keep-Alive'
1 parent 069cbe9 commit dc72b6c

6 files changed

+96
-5
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ before_script:
1212
- ./tests/travis/setup_arangodb.sh
1313

1414
script:
15-
- phpunit --configuration ./tests/phpunit.xml
15+
- phpunit --configuration ./tests/phpunit-connection-close.xml
16+
- phpunit --configuration ./tests/phpunit-connection-keep-alive.xml
1617

1718
after_script:
1819
- ./tests/travis/teardown_arangodb.sh

tests/ConnectionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testGetOptions()
6767
static::assertEquals(12, $value);
6868

6969
$value = $connection->getOption(ConnectionOptions::OPTION_CONNECTION);
70-
static::assertEquals('Close', $value);
70+
static::assertEquals(getenv('ArangoDB-PHP-Connection'), $value);
7171

7272
$value = $connection->getOption(ConnectionOptions::OPTION_RECONNECT);
7373
static::assertFalse($value);

tests/bootstrap.php renamed to tests/bootstrap-connection-close.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* ArangoDB PHP client testsuite
4-
* File: bootstrap.php
4+
* File: bootstrap-connection-close.php
55
*
66
* @package ArangoDBClient
77
* @author Frank Mayer
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* ArangoDB PHP client
4+
* File: bootstrap_connection_keep_alive.php
5+
*
6+
* @package ArangoDBClient
7+
* @author Frank Mayer
8+
*/
9+
10+
namespace ArangoDBClient;
11+
12+
require __DIR__ . '/../autoload.php';
13+
14+
if (class_exists('\PHPUnit\Framework\TestCase')) {
15+
class_alias(\PHPUnit\Framework\TestCase::class, 'PHPUnit_Framework_TestCase');
16+
}
17+
18+
/* set up a trace function that will be called for each communication with the server */
19+
20+
function isCluster(Connection $connection)
21+
{
22+
static $isCluster = null;
23+
24+
if ($isCluster === null) {
25+
$adminHandler = new AdminHandler($connection);
26+
try {
27+
$role = $adminHandler->getServerRole();
28+
$isCluster = ($role === 'COORDINATOR' || $role === 'DBSERVER');
29+
} catch (\Exception $e) {
30+
// maybe server version is too "old"
31+
$isCluster = false;
32+
}
33+
}
34+
35+
return $isCluster;
36+
}
37+
38+
function getConnectionOptions()
39+
{
40+
$traceFunc = function ($type, $data) {
41+
print 'TRACE FOR ' . $type . PHP_EOL;
42+
};
43+
44+
return [
45+
ConnectionOptions::OPTION_ENDPOINT => 'tcp://localhost:8529',
46+
// endpoint to connect to
47+
ConnectionOptions::OPTION_CONNECTION => 'Keep-Alive',
48+
// can use either 'Close' (one-time connections) or 'Keep-Alive' (re-used connections)
49+
ConnectionOptions::OPTION_AUTH_TYPE => 'Basic',
50+
// use basic authorization
51+
ConnectionOptions::OPTION_AUTH_USER => 'root',
52+
// user for basic authorization
53+
ConnectionOptions::OPTION_AUTH_PASSWD => '',
54+
// password for basic authorization
55+
ConnectionOptions::OPTION_TIMEOUT => 12,
56+
// timeout in seconds
57+
//ConnectionOptions::OPTION_TRACE => $traceFunc, // tracer function, can be used for debugging
58+
ConnectionOptions::OPTION_CREATE => false,
59+
// do not create unknown collections automatically
60+
ConnectionOptions::OPTION_UPDATE_POLICY => UpdatePolicy::LAST,
61+
// last update wins
62+
ConnectionOptions::OPTION_CHECK_UTF8_CONFORM => true
63+
// force UTF-8 checks for data
64+
];
65+
}
66+
67+
68+
function getConnection()
69+
{
70+
return new Connection(getConnectionOptions());
71+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
2-
<phpunit bootstrap="bootstrap.php" colors="true" verbose="true" backupGlobals="false">
2+
<phpunit bootstrap="bootstrap-connection-close.php" colors="true" verbose="true" backupGlobals="false">
33
<testsuites>
4-
<testsuite name="ArangoDB-PHP">
4+
<testsuite name="ArangoDB-PHP-Connection-Close">
55
<directory>.</directory>
66
</testsuite>
77
</testsuites>
@@ -10,4 +10,7 @@
1010
<directory suffix=".php">../lib</directory>
1111
</whitelist>
1212
</filter>
13+
<php>
14+
<env name="ArangoDB-PHP-Connection" value="Close"/>
15+
</php>
1316
</phpunit>
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
2+
<phpunit bootstrap="bootstrap_connection_keep_alive.php" colors="true" verbose="true" backupGlobals="false">
3+
<testsuites>
4+
<testsuite name="ArangoDB-PHP-Connection-Keep-Alive">
5+
<directory>.</directory>
6+
</testsuite>
7+
</testsuites>
8+
<filter>
9+
<whitelist processUncoveredFilesFromWhitelist="true">
10+
<directory suffix=".php">../lib</directory>
11+
</whitelist>
12+
</filter>
13+
<php>
14+
<env name="ArangoDB-PHP-Connection" value="Keep-Alive"/>
15+
</php>
16+
</phpunit>

0 commit comments

Comments
 (0)