diff --git a/test-run.py b/test-run.py index 153fd4c..7d9a31f 100755 --- a/test-run.py +++ b/test-run.py @@ -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') @@ -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') diff --git a/test.sh b/test.sh index 8f84361..c538751 100755 --- a/test.sh +++ b/test.sh @@ -56,6 +56,36 @@ if [ "${ACTUAL_TARANTOOL_VERSION}" != "${TARANTOOL_VERSION}" ]; then exit 1 fi +# 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_DIR="/usr/local/phpunit-${PHPUNIT_VERSION}" +PHPUNIT_FILE="${PHPUNIT_DIR}/phpunit" +${SUDO} mkdir -p "${PHPUNIT_DIR}" +${SUDO} curl -SsLf -o "${PHPUNIT_FILE}" "${PHPUNIT_URL}" +${SUDO} chmod a+x "${PHPUNIT_FILE}" +export PATH="${PHPUNIT_DIR}:${PATH}" +phpunit --version + phpize && ./configure make make install diff --git a/test/AssertTest.php b/test/AssertTest.php index 6063866..901f51b 100644 --- a/test/AssertTest.php +++ b/test/AssertTest.php @@ -1,5 +1,8 @@ select("test"); } + /** + * @doesNotPerformAssertions + */ public function test_01_closed_connection() { for ($i = 0; $i < 20000; $i++) { try { diff --git a/test/CreateTest.php b/test/CreateTest.php index 8ce5031..07b07c1 100644 --- a/test/CreateTest.php +++ b/test/CreateTest.php @@ -1,11 +1,12 @@ close(); } + /** + * @doesNotPerformAssertions + */ public function test_01_01_double_disconnect() { $a = new Tarantool('localhost', self::$port); $a->disconnect(); diff --git a/test/DMLTest.php b/test/DMLTest.php index e18809e..47e9342 100644 --- a/test/DMLTest.php +++ b/test/DMLTest.php @@ -1,5 +1,8 @@ assertEquals($result_tuple, $tuple[0]); } + /** + * @doesNotPerformAssertions + */ public function test_07_update_no_error() { self::$tarantool->update("test", 0, array()); } @@ -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)); @@ -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)); diff --git a/test/MockTest.php b/test/MockTest.php index 5850291..41bbbfd 100644 --- a/test/MockTest.php +++ b/test/MockTest.php @@ -1,9 +1,12 @@ getMock('Tarantool'); + $tnt = $this->createMock(Tarantool::class); $tnt->expects($this->once())->method('ping'); $tnt->ping(); } diff --git a/test/MsgPackTest.php b/test/MsgPackTest.php index 0b66e67..5fec22f 100644 --- a/test/MsgPackTest.php +++ b/test/MsgPackTest.php @@ -1,5 +1,8 @@ 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", @@ -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]); + } } diff --git a/test/RandomTest.php b/test/RandomTest.php index 34d942a..3779dcf 100644 --- a/test/RandomTest.php +++ b/test/RandomTest.php @@ -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; @@ -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"); }