Skip to content

Commit f0fe8fa

Browse files
committed
travis-ci: install appropriate phpunit version
We should use different phpunit versions on different php versions (see [1]). Since we going to enable php from 7.0 to 7.4, the logic of test-run.py is changed to find `phpunit` command in PATH directories, but the Travis-CI script (test.sh) installs appropriate phpunit version to /usr/local/bin. Note: On the first glance it looks that we can skip phpunit installing on Travis-CI, because it is provided already. However it ships phpunit-7.5.0 for php-7.0 environment, but it works only on php-7.1+. Note: We can not just save downloaded phpunit into /usr/local/bin, because Travis CI have a directory with its own phpunit executable in PATH prior standard directories. So we create our own directory and add it to PATH at beginning. Tests are changed to be compatible with phpunit-6+, see [2] and [3]. Aside of this, removed some dead code from test-run.py. The next commit will remove test/phpunit.phar file, it is not used anymore. [1]: https://phpunit.de/supported-versions.html [2]: https://thephp.cc/news/2017/02/migrating-to-phpunit-6 [3]: sebastianbergmann/phpunit#2898
1 parent aaa53fc commit f0fe8fa

File tree

8 files changed

+95
-20
lines changed

8 files changed

+95
-20
lines changed

test-run.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,19 @@ def find_php_bin():
3030
return '~/.phpenv/versions/{0}/bin/php'.format(version.strip())
3131
return path
3232

33+
def find_phpunit_bin():
34+
path = read_popen('which phpunit').strip()
35+
if not path:
36+
raise RuntimeError('Unable to find phpunit binary in PATH: ' +
37+
os.environ['PATH'])
38+
return path
39+
3340
def prepare_env(php_ini):
3441
if os.path.isdir('var'):
3542
shutil.rmtree('var')
3643
if not os.path.isdir('var') and not os.path.exists('var'):
3744
os.mkdir('var')
3845
shutil.copy('test/shared/phpunit.xml', 'var')
39-
test_dir_path = os.path.abspath(os.path.join(os.getcwd(), 'test'))
40-
test_lib_path = os.path.join(test_dir_path, 'phpunit.phar')
41-
# shutil.copy('test/shared/tarantool.ini', 'var')
4246
shutil.copy(php_ini, 'var')
4347
shutil.copy('modules/tarantool.so', 'var')
4448

@@ -54,13 +58,15 @@ def main():
5458
srv = TarantoolServer()
5559
srv.script = 'test/shared/box.lua'
5660
srv.start()
57-
test_dir_path = os.path.abspath(os.path.join(os.getcwd(), 'test'))
5861
test_cwd = os.path.dirname(srv.vardir)
59-
test_lib_path = ""
6062
try:
6163
shutil.copy('test/shared/phpunit.xml', os.path.join(test_cwd, 'phpunit.xml'))
6264
shutil.copy('modules/tarantool.so', test_cwd)
63-
test_lib_path = os.path.join(test_dir_path, 'phpunit.phar')
65+
try:
66+
test_lib_path = find_phpunit_bin()
67+
except RuntimeError as e:
68+
print(str(e))
69+
return 1
6470

6571
version = read_popen_config('--version').strip(' \n\t') + '.'
6672
version1 = read_popen_config('--extension-dir').strip(' \n\t')

test.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,36 @@ if [ "${ACTUAL_TARANTOOL_VERSION}" != "${TARANTOOL_VERSION}" ]; then
5656
exit 1
5757
fi
5858

59+
# Determine PHP interpreter version.
60+
PHP_VERSION_PATTERN='^PHP \([0-9]\+\.[0-9]\+\)\.[0-9]\+ .*$'
61+
PHP_VERSION="$(php --version | head -n 1 | sed "s/${PHP_VERSION_PATTERN}/\\1/")"
62+
63+
# Choose maximal phpunit version supported by installed PHP
64+
# interpreter.
65+
#
66+
# https://phpunit.de/supported-versions.html
67+
case "${PHP_VERSION}" in
68+
7.0) PHPUNIT_VERSION=6 ;;
69+
7.1) PHPUNIT_VERSION=7 ;;
70+
7.2) PHPUNIT_VERSION=8 ;;
71+
7.3) PHPUNIT_VERSION=9 ;;
72+
7.4) PHPUNIT_VERSION=9 ;;
73+
*)
74+
echo "Unable to choose phpunit version for PHP ${PHP_VERSION}"
75+
exit 1
76+
;;
77+
esac
78+
79+
# Install phpunit.
80+
PHPUNIT_URL="https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar"
81+
PHPUNIT_DIR="/usr/local/phpunit-${PHPUNIT_VERSION}"
82+
PHPUNIT_FILE="${PHPUNIT_DIR}/phpunit"
83+
${SUDO} mkdir -p "${PHPUNIT_DIR}"
84+
${SUDO} curl -SsLf -o "${PHPUNIT_FILE}" "${PHPUNIT_URL}"
85+
${SUDO} chmod a+x "${PHPUNIT_FILE}"
86+
export PATH="${PHPUNIT_DIR}:${PATH}"
87+
phpunit --version
88+
5989
phpize && ./configure
6090
make
6191
make install

test/AssertTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
2-
class AssertTest extends PHPUnit_Framework_TestCase
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
class AssertTest extends TestCase
36
{
47
protected static $tarantool, $tm;
58

@@ -39,6 +42,9 @@ function assert_f()
3942
self::$tarantool->select("test");
4043
}
4144

45+
/**
46+
* @doesNotPerformAssertions
47+
*/
4248
public function test_01_closed_connection() {
4349
for ($i = 0; $i < 20000; $i++) {
4450
try {

test/CreateTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
class CreateTest extends PHPUnit_Framework_TestCase
3+
use PHPUnit\Framework\TestCase;
4+
5+
class CreateTest extends TestCase
46
{
57
protected static $port, $tm;
68

@@ -34,6 +36,9 @@ public function test_01_create_test_ping_and_close() {
3436
$c->close();
3537
}
3638

39+
/**
40+
* @doesNotPerformAssertions
41+
*/
3742
public function test_01_01_double_disconnect() {
3843
$a = new Tarantool('localhost', self::$port);
3944
$a->disconnect();

test/DMLTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
2-
class DMLTest extends PHPUnit_Framework_TestCase
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
class DMLTest extends TestCase
36
{
47
protected static $tarantool;
58

@@ -158,6 +161,9 @@ public function test_06_update() {
158161
$this->assertEquals($result_tuple, $tuple[0]);
159162
}
160163

164+
/**
165+
* @doesNotPerformAssertions
166+
*/
161167
public function test_07_update_no_error() {
162168
self::$tarantool->update("test", 0, array());
163169
}
@@ -439,6 +445,9 @@ public static function provideIteratorGood() {
439445
];
440446
}
441447

448+
/**
449+
* @doesNotPerformAssertions
450+
*/
442451
public function test_18_01_delete_loop() {
443452
for ($i = 0; $i <= 1000; $i++) {
444453
self::$tarantool->replace("pstring", array("test2" . $i, $i));
@@ -451,6 +460,9 @@ public function test_18_01_delete_loop() {
451460
gc_collect_cycles();
452461
}
453462

463+
/**
464+
* @doesNotPerformAssertions
465+
*/
454466
public function test_18_02_delete_loop() {
455467
for ($i = 0; $i <= 1000; $i++) {
456468
self::$tarantool->replace("pstring", array("test2" . $i, $i));

test/MockTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
2-
class MockTest extends \PHPUnit_Framework_TestCase
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
class MockTest extends TestCase
36
{
47
public function testFoo()
58
{
6-
$tnt = $this->getMock('Tarantool');
9+
$tnt = $this->createMock(Tarantool::class);
710
$tnt->expects($this->once())->method('ping');
811
$tnt->ping();
912
}

test/MsgPackTest.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
2-
class MsgPackTest extends PHPUnit_Framework_TestCase
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
class MsgPackTest extends TestCase
36
{
47
protected static $tarantool;
58

@@ -48,6 +51,9 @@ public function test_03_msgpack_array_of_float_as_key() {
4851
self::$tarantool->select("msgpack", array(3));
4952
}
5053

54+
/**
55+
* @doesNotPerformAssertions
56+
*/
5157
public function test_04_msgpack_integer_keys_arrays() {
5258
self::$tarantool->replace("msgpack", array(4,
5359
"Integer keys causing server to error",
@@ -70,11 +76,12 @@ public function test_05_msgpack_string_keys() {
7076
$this->assertTrue(True);
7177
}
7278

73-
public function test_06_msgpack_array_reference() {
74-
$data = [
75-
'key1' => 'value1',
76-
];
77-
$link = &$data['key1'];
78-
self::$tarantool->call('test_4', [$data]);
79-
}
79+
/**
80+
* @doesNotPerformAssertions
81+
*/
82+
public function test_06_msgpack_array_reference() {
83+
$data = array('key1' => 'value1');
84+
$link = &$data['key1'];
85+
self::$tarantool->call('test_4', [$data]);
86+
}
8087
}

test/RandomTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ function generateRandomString($length = 10) {
1010
return $randomString;
1111
}
1212

13-
class RandomTest extends PHPUnit_Framework_TestCase
13+
use PHPUnit\Framework\TestCase;
14+
15+
class RandomTest extends TestCase
1416
{
1517
protected static $tarantool;
1618

@@ -39,6 +41,10 @@ public function test_03_another_big_response() {
3941
$this->assertEquals($i, count($result));
4042
}
4143
}
44+
45+
/**
46+
* @doesNotPerformAssertions
47+
*/
4248
public function test_04_get_strange_response() {
4349
self::$tarantool->select("_schema", "12345");
4450
}

0 commit comments

Comments
 (0)