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 {
@ -38,13 +37,13 @@ class SecurityTest extends TestCase {
// Must remember to clear this, or other tests may break // Must remember to clear this, or other tests may break
unset($GLOBALS['egw']); unset($GLOBALS['egw']);
} }
/** /**
* Test some strings for bad stuff * Test some strings for bad stuff
* *
* @param String $pattern String to check * @param String $pattern String to check
* @param boolean $should_fail If we expect this string to fail * @param boolean $should_fail If we expect this string to fail
* *
* @dataProvider patternProvider * @dataProvider patternProvider
*/ */
public function testPatterns($pattern, $should_fail) public function testPatterns($pattern, $should_fail)
@ -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
* *
@ -34,11 +31,11 @@ class EtemplateTest extends Etemplate\WidgetBaseTest {
protected $content = array('value' => 'test content'); protected $content = array('value' => 'test content');
protected $sel_options = array(array('value' => 0, 'label' => 'label')); protected $sel_options = array(array('value' => 0, 'label' => 'label'));
protected $readonlys = array('value' => true); protected $readonlys = array('value' => true);
/** /**
* Test reading xml files * Test reading xml files
* *
* This really just tests that the files can be found and executed. * This really just tests that the files can be found and executed.
*/ */
public function testRead() public function testRead()
{ {
@ -136,7 +133,7 @@ class EtemplateTest extends Etemplate\WidgetBaseTest {
$etemplate->read(static::TEST_TEMPLATE); $etemplate->read(static::TEST_TEMPLATE);
$this->readonlys['value'] = false; $this->readonlys['value'] = false;
$result = $this->mockedRoundTrip($etemplate, $this->content, $this->sel_options, $this->readonlys); $result = $this->mockedRoundTrip($etemplate, $this->content, $this->sel_options, $this->readonlys);
$this->assertEquals($this->content, $result); $this->assertEquals($this->content, $result);
@ -188,18 +185,18 @@ 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()
{ {
$etemplate = new Etemplate(); $etemplate = new Etemplate();
$etemplate->read(static::TEST_TEMPLATE); $etemplate->read(static::TEST_TEMPLATE);
$this->readonlys['value'] = true; $this->readonlys['value'] = true;
$preserve['value'] = 'preserved_value'; $preserve['value'] = 'preserved_value';
@ -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,11 +16,11 @@ 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
* *
*/ */
class IncludeMgrTest extends TestCase class IncludeMgrTest extends TestCase
{ {

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;
/** /**
@ -167,7 +167,7 @@ abstract class LoggedInTest extends TestCase
$GLOBALS['egw'] = new Api\Egw(array_keys($GLOBALS['egw_domain'])); $GLOBALS['egw'] = new Api\Egw(array_keys($GLOBALS['egw_domain']));
} }
// Disable asyc while we test // Disable asyc while we test
$GLOBALS['egw_info']['server']['asyncservice'] = 'off'; $GLOBALS['egw_info']['server']['asyncservice'] = 'off';
} }

View File

@ -7,7 +7,7 @@
* *
* @link http://www.egroupware.org * @link http://www.egroupware.org
* @author Nathan Gray * @author Nathan Gray
* @package * @package
* @copyright (c) 2017 Nathan Gray * @copyright (c) 2017 Nathan Gray
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
*/ */
@ -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';