Skip to content

Commit

Permalink
travis-ci: choose phpunit depending of php version
Browse files Browse the repository at this point in the history
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.

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
  • Loading branch information
Totktonada committed Mar 18, 2020
1 parent 4df972a commit ffe88c9
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 20 deletions.
18 changes: 12 additions & 6 deletions test-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ def find_php_bin():
return '~/.phpenv/versions/{0}/bin/php'.format(version.strip())
return path

def find_phpunit_bin():
path = read_popen('which phpunit').strip()
if not path:
raise RuntimeError('Unable to find phpunit binary in PATH: ' +
os.environ['PATH'])
return path

def prepare_env(php_ini):
if os.path.isdir('var'):
shutil.rmtree('var')
if not os.path.isdir('var') and not os.path.exists('var'):
os.mkdir('var')
shutil.copy('test/shared/phpunit.xml', 'var')
test_dir_path = os.path.abspath(os.path.join(os.getcwd(), 'test'))
test_lib_path = os.path.join(test_dir_path, 'phpunit.phar')
# shutil.copy('test/shared/tarantool.ini', 'var')
shutil.copy(php_ini, 'var')
shutil.copy('modules/tarantool.so', 'var')

Expand All @@ -54,13 +58,15 @@ def main():
srv = TarantoolServer()
srv.script = 'test/shared/box.lua'
srv.start()
test_dir_path = os.path.abspath(os.path.join(os.getcwd(), 'test'))
test_cwd = os.path.dirname(srv.vardir)
test_lib_path = ""
try:
shutil.copy('test/shared/phpunit.xml', os.path.join(test_cwd, 'phpunit.xml'))
shutil.copy('modules/tarantool.so', test_cwd)
test_lib_path = os.path.join(test_dir_path, 'phpunit.phar')
try:
test_lib_path = find_phpunit_bin()
except RuntimeError as e:
print(str(e))
return 1

version = read_popen_config('--version').strip(' \n\t') + '.'
version1 = read_popen_config('--extension-dir').strip(' \n\t')
Expand Down
29 changes: 29 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,35 @@ deb https://download.tarantool.org/tarantool/${TARANTOOL_VERSION}/${OS}/ ${DIST}
EOF
${SUDO} apt-get update > /dev/null

# Install phpunit if it is not installed.
if ! which phpunit >/dev/null 2>&1; then
# Determine PHP interpreter version.
PHP_VERSION_PATTERN='^PHP \([0-9]\+\.[0-9]\+\)\.[0-9]\+ .*$'
PHP_VERSION="$(php --version | head -n 1 | sed "s/${PHP_VERSION_PATTERN}/\\1/")"

# Choose maximal phpunit version supported by installed PHP
# interpreter.
#
# https://phpunit.de/supported-versions.html
case "${PHP_VERSION}" in
7.0) PHPUNIT_VERSION=6 ;;
7.1) PHPUNIT_VERSION=7 ;;
7.2) PHPUNIT_VERSION=8 ;;
7.3) PHPUNIT_VERSION=9 ;;
7.4) PHPUNIT_VERSION=9 ;;
*)
echo "Unable to choose phpunit version for PHP ${PHP_VERSION}"
exit 1
;;
esac

# Install phpunit.
PHPUNIT_URL="https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar"
PHPUNIT_PATH="/usr/local/bin/phpunit"
${SUDO} curl -SsLf -o "${PHPUNIT_PATH}" "${PHPUNIT_URL}"
${SUDO} chmod a+x "${PHPUNIT_PATH}"
fi

${SUDO} apt-get -qy install tarantool tarantool-dev > /dev/null
tarantool --version
phpize && ./configure
Expand Down
8 changes: 7 additions & 1 deletion test/AssertTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
class AssertTest extends PHPUnit_Framework_TestCase

use PHPUnit\Framework\TestCase;

final class AssertTest extends TestCase
{
protected static $tarantool, $tm;

Expand Down Expand Up @@ -39,6 +42,9 @@ function assert_f()
self::$tarantool->select("test");
}

/**
* @doesNotPerformAssertions
*/
public function test_01_closed_connection() {
for ($i = 0; $i < 20000; $i++) {
try {
Expand Down
6 changes: 5 additions & 1 deletion test/CreateTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

use PHPUnit\Framework\TestCase;

class TarantoolExt extends Tarantool {
public $property = 42;
}

class CreateTest extends PHPUnit_Framework_TestCase
final class CreateTest extends TestCase
{
protected static $port, $tm;

Expand Down Expand Up @@ -39,6 +40,9 @@ public function test_01_create_test_ping_and_close() {
$c->close();
}

/**
* @doesNotPerformAssertions
*/
public function test_01_01_double_disconnect() {
$a = new Tarantool('localhost', self::$port);
$a->disconnect();
Expand Down
14 changes: 13 additions & 1 deletion test/DMLTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
class DMLTest extends PHPUnit_Framework_TestCase

use PHPUnit\Framework\TestCase;

final class DMLTest extends TestCase
{
protected static $tarantool;

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

/**
* @doesNotPerformAssertions
*/
public function test_07_update_no_error() {
self::$tarantool->update("test", 0, array());
}
Expand Down Expand Up @@ -439,6 +445,9 @@ public static function provideIteratorGood() {
];
}

/**
* @doesNotPerformAssertions
*/
public function test_18_01_delete_loop() {
for ($i = 0; $i <= 1000; $i++) {
self::$tarantool->replace("pstring", array("test2" . $i, $i));
Expand All @@ -451,6 +460,9 @@ public function test_18_01_delete_loop() {
gc_collect_cycles();
}

/**
* @doesNotPerformAssertions
*/
public function test_18_02_delete_loop() {
for ($i = 0; $i <= 1000; $i++) {
self::$tarantool->replace("pstring", array("test2" . $i, $i));
Expand Down
7 changes: 5 additions & 2 deletions test/MockTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php
class MockTest extends \PHPUnit_Framework_TestCase

use PHPUnit\Framework\TestCase;

final class MockTest extends TestCase
{
public function testFoo()
{
$tnt = $this->getMock('Tarantool');
$tnt = $this->createMock(Tarantool::class);
$tnt->expects($this->once())->method('ping');
$tnt->ping();
}
Expand Down
23 changes: 15 additions & 8 deletions test/MsgPackTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
class MsgPackTest extends PHPUnit_Framework_TestCase

use PHPUnit\Framework\TestCase;

final class MsgPackTest extends TestCase
{
protected static $tarantool;

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

/**
* @doesNotPerformAssertions
*/
public function test_04_msgpack_integer_keys_arrays() {
self::$tarantool->replace("msgpack", array(4,
"Integer keys causing server to error",
Expand All @@ -70,11 +76,12 @@ public function test_05_msgpack_string_keys() {
$this->assertTrue(True);
}

public function test_06_msgpack_array_reference() {
$data = [
'key1' => 'value1',
];
$link = &$data['key1'];
self::$tarantool->call('test_4', [$data]);
}
/**
* @doesNotPerformAssertions
*/
public function test_06_msgpack_array_reference() {
$data = array('key1' => 'value1');
$link = &$data['key1'];
self::$tarantool->call('test_4', [$data]);
}
}
8 changes: 7 additions & 1 deletion test/RandomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ function generateRandomString($length = 10) {
return $randomString;
}

class RandomTest extends PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

final class RandomTest extends TestCase
{
protected static $tarantool;

Expand Down Expand Up @@ -39,6 +41,10 @@ public function test_03_another_big_response() {
$this->assertEquals($i, count($result));
}
}

/**
* @doesNotPerformAssertions
*/
public function test_04_get_strange_response() {
self::$tarantool->select("_schema", "12345");
}
Expand Down

0 comments on commit ffe88c9

Please sign in to comment.