support PHPunit 6.0+ and older 5.7 for PHP 5.6

This commit is contained in:
Ralf Becker 2017-08-18 11:45:10 +02:00
parent 7e416b12f4
commit 191d6aec45
9 changed files with 37 additions and 34 deletions

View File

@ -39,7 +39,7 @@ before_script:
yes "" | pecl install apcu; yes "" | pecl install apcu;
echo "extension=memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; echo "extension=memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini;
phpenv config-rm xdebug.ini; phpenv config-rm xdebug.ini;
composer require 'phpunit/phpunit'; composer require 'phpunit/phpunit:~6.3';
;; ;;
"hhvm") "hhvm")
;; ;;

View File

@ -17,7 +17,7 @@ namespace EGroupware\Api\Mail;
require_once realpath(__DIR__.'/../../loader/common.php'); // autoloader & check_load_extension require_once realpath(__DIR__.'/../../loader/common.php'); // autoloader & check_load_extension
use EGroupware\Api; use EGroupware\Api;
use PHPUnit_Framework_TestCase; use PHPUnit\Framework\TestCase;
use ReflectionClass; use ReflectionClass;
use EGroupware\Api\Mail\Credentials; use EGroupware\Api\Mail\Credentials;
@ -27,7 +27,7 @@ use EGroupware\Api\Mail\Credentials;
* Only testing en&decryption of mail passwords so far. * Only testing en&decryption of mail passwords so far.
* Further tests would need database. * Further tests would need database.
*/ */
class CredentialsTest extends PHPUnit_Framework_TestCase class CredentialsTest extends TestCase
{ {
/** /**
* Test new 16.1 AES password encryption with OpenSSL * Test new 16.1 AES password encryption with OpenSSL

View File

@ -16,8 +16,7 @@ require_once realpath(__DIR__.'/../common.php'); // autoloader & check_load_exte
// We're testing security.php // We're testing security.php
require_once realpath(__DIR__.'/../security.php'); require_once realpath(__DIR__.'/../security.php');
use EGroupware\Api; use PHPUnit\Framework\TestCase as TestCase;
use PHPUnit_Framework_TestCase as TestCase;
class SecurityTest extends TestCase { class SecurityTest extends TestCase {
@ -129,6 +128,7 @@ class SecurityTest extends TestCase {
} }
catch (Exception $e) catch (Exception $e)
{ {
unset($e);
return false; return false;
} }
$replace = array( $replace = array(
@ -175,6 +175,7 @@ class SecurityTest extends TestCase {
{ {
if (PHP_VERSION >= 7) if (PHP_VERSION >= 7)
{ {
$matches = null;
if (preg_match_all('/([^ ]+) Object\(/', array2string($r), $matches)) if (preg_match_all('/([^ ]+) Object\(/', array2string($r), $matches))
{ {
foreach($matches[1] as $class) foreach($matches[1] as $class)

View File

@ -17,7 +17,7 @@ namespace EGroupware\Api;
require_once realpath(__DIR__.'/../loader/common.php'); // autoloader & check_load_extension require_once realpath(__DIR__.'/../loader/common.php'); // autoloader & check_load_extension
use EGroupware\Api; use EGroupware\Api;
use PHPUnit_Framework_TestCase as TestCase; use PHPUnit\Framework\TestCase as TestCase;
use ReflectionClass; use ReflectionClass;
/** /**

View File

@ -13,8 +13,7 @@ namespace EGroupware\Api;
require_once realpath(__DIR__.'/../loader/common.php'); // autoloader & check_load_extension require_once realpath(__DIR__.'/../loader/common.php'); // autoloader & check_load_extension
use EGroupware\Api; use PHPUnit\Framework\TestCase as TestCase;
use PHPUnit_Framework_TestCase as TestCase;
/** /**
* Testing the Egroupware extension of DateTime * Testing the Egroupware extension of DateTime
@ -80,8 +79,8 @@ class DateTimeTest extends TestCase {
$ts = DateTime::to(array('full' => '20091027', 'hour' => 10, 'minute' => 0),'ts'); $ts = DateTime::to(array('full' => '20091027', 'hour' => 10, 'minute' => 0),'ts');
$this->assertEquals(DateTime::user2server($ts,''), DateTime::server2user(DateTime::user2server($ts),'')); $this->assertEquals(DateTime::user2server($ts,''), DateTime::server2user(DateTime::user2server($ts),''));
$ts = DateTime::to(array('full' => '20090627', 'hour' => 10, 'minute' => 0),'ts'); $ts2 = DateTime::to(array('full' => '20090627', 'hour' => 10, 'minute' => 0),'ts');
$this->assertEquals(DateTime::user2server($ts,''), DateTime::server2user(DateTime::user2server($ts),'')); $this->assertEquals(DateTime::user2server($ts2,''), DateTime::server2user(DateTime::user2server($ts),''));
} }
/** /**
@ -100,8 +99,8 @@ class DateTimeTest extends TestCase {
// Set user to Cape Verde (UTC+1) // Set user to Cape Verde (UTC+1)
DateTime::setUserPrefs('Atlantic/Cape_Verde'); DateTime::setUserPrefs('Atlantic/Cape_Verde');
$ts = DateTime::to(array('full' => '20091027', 'hour' => 10, 'minute' => 0),'ts'); $ts2 = DateTime::to(array('full' => '20091027', 'hour' => 10, 'minute' => 0),'ts');
$this->assertEquals('2009-10-27 11:00:00', DateTime::user2server($ts,'Y-m-d H:i:s')); $this->assertEquals('2009-10-27 11:00:00', DateTime::user2server($ts2,'Y-m-d H:i:s'));
date_default_timezone_set($server_tz); date_default_timezone_set($server_tz);
} }

View File

@ -14,9 +14,6 @@ namespace EGroupware\Api;
require_once realpath(__DIR__.'/../Etemplate/test/WidgetBaseTest.php'); require_once realpath(__DIR__.'/../Etemplate/test/WidgetBaseTest.php');
use EGroupware\Api;
use PHPUnit_Framework_TestCase as TestCase;
/** /**
* Test the main class of Etemplate * Test the main class of Etemplate
* *
@ -188,11 +185,11 @@ class EtemplateTest extends Etemplate\WidgetBaseTest {
// Now try with widget // Now try with widget
$this->readonlys['value'] = false; $this->readonlys['value'] = false;
$result = $this->mockedRoundTrip($etemplate, $this->content, $this->sel_options, $this->readonlys, $preserve); $result2 = $this->mockedRoundTrip($etemplate, $this->content, $this->sel_options, $this->readonlys, $preserve);
// The only input widget is readonly, expect preserve + content back // The only input widget is readonly, expect preserve + content back
$this->assertArraySubset($this->content, $result); $this->assertArraySubset($this->content, $result2);
$this->assertArraySubset($preserve, $result); $this->assertArraySubset($preserve, $result2);
} }
public function testReadonlyPreserve() public function testReadonlyPreserve()
@ -209,10 +206,9 @@ class EtemplateTest extends Etemplate\WidgetBaseTest {
$this->assertEquals($preserve['value'], $result['value']); $this->assertEquals($preserve['value'], $result['value']);
$this->readonlys['value'] = false; $this->readonlys['value'] = false;
$result = $this->mockedRoundTrip($etemplate, $this->content, $this->sel_options, $this->readonlys, $preserve); $result2 = $this->mockedRoundTrip($etemplate, $this->content, $this->sel_options, $this->readonlys, $preserve);
// The only input widget is editable, expect content back, not preserve // The only input widget is editable, expect content back, not preserve
$this->assertEquals($this->content['value'], $result['value']); $this->assertEquals($this->content['value'], $result2['value']);
} }
} }

View File

@ -16,7 +16,7 @@ namespace EGroupware\Api;
require_once realpath(__DIR__.'/../loader/common.php'); // autoloader & check_load_extension require_once realpath(__DIR__.'/../loader/common.php'); // autoloader & check_load_extension
use EGroupware\Api\Framework; use EGroupware\Api\Framework;
use PHPUnit_Framework_TestCase as TestCase; use PHPUnit\Framework\TestCase as TestCase;
/** /**
* Tests for IncludeMgr * Tests for IncludeMgr

View File

@ -16,8 +16,8 @@ namespace EGroupware\Api;
require_once realpath(__DIR__.'/../loader/common.php'); // autoloader & check_load_extension require_once realpath(__DIR__.'/../loader/common.php'); // autoloader & check_load_extension
use PHPUnit_Framework_TestCase as TestCase; use PHPUnit\Framework\TestCase as TestCase;
use PHPUnit_Framework_ExpectationFailedException as PHPUnitException; use PHPUnit\Framework\ExpectationFailedException as PHPUnitException;
use EGroupware\Api; use EGroupware\Api;
/** /**

View File

@ -15,6 +15,13 @@
// autoloader & check_load_extension // autoloader & check_load_extension
require_once realpath(__DIR__.'/../api/src/loader/common.php'); require_once realpath(__DIR__.'/../api/src/loader/common.php');
// backward compatibility with PHPunit 5.7
if (!class_exists('\PHPUnit\Framework\TestCase') && class_exists('\PHPUnit_Framework_TestCase'))
{
class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');
class_alias('\PHPUnit_Framework_ExpectationFailedException', '\PHPUnit\Framework\ExpectationFailedException');
}
// Needed to let Cache work // Needed to let Cache work
$GLOBALS['egw_info']['server']['temp_dir'] = '/tmp'; $GLOBALS['egw_info']['server']['temp_dir'] = '/tmp';
$GLOBALS['egw_info']['server']['install_id'] = 'PHPUnit test'; $GLOBALS['egw_info']['server']['install_id'] = 'PHPUnit test';