From 191d6aec4549a7fa8892fdb949c4f36a7c4803eb Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 18 Aug 2017 11:45:10 +0200 Subject: [PATCH] support PHPunit 6.0+ and older 5.7 for PHP 5.6 --- .travis.yml | 2 +- api/src/Mail/test/CredentialsTest.php | 4 ++-- api/src/loader/test/SecurityTest.php | 11 ++++++----- api/src/test/CacheTest.php | 2 +- api/src/test/DateTimeTest.php | 11 +++++------ api/src/test/EtemplateTest.php | 22 +++++++++------------- api/src/test/IncludeMgrTest.php | 4 ++-- api/src/test/LoggedInTest.php | 6 +++--- doc/phpunit_bootstrap.php | 9 ++++++++- 9 files changed, 37 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index 058681f8c2..5b3957663e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ before_script: yes "" | pecl install apcu; echo "extension=memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; phpenv config-rm xdebug.ini; - composer require 'phpunit/phpunit'; + composer require 'phpunit/phpunit:~6.3'; ;; "hhvm") ;; diff --git a/api/src/Mail/test/CredentialsTest.php b/api/src/Mail/test/CredentialsTest.php index b1dbcd25a2..7c0d62872c 100644 --- a/api/src/Mail/test/CredentialsTest.php +++ b/api/src/Mail/test/CredentialsTest.php @@ -17,7 +17,7 @@ namespace EGroupware\Api\Mail; require_once realpath(__DIR__.'/../../loader/common.php'); // autoloader & check_load_extension use EGroupware\Api; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use ReflectionClass; use EGroupware\Api\Mail\Credentials; @@ -27,7 +27,7 @@ use EGroupware\Api\Mail\Credentials; * Only testing en&decryption of mail passwords so far. * Further tests would need database. */ -class CredentialsTest extends PHPUnit_Framework_TestCase +class CredentialsTest extends TestCase { /** * Test new 16.1 AES password encryption with OpenSSL diff --git a/api/src/loader/test/SecurityTest.php b/api/src/loader/test/SecurityTest.php index e4c0e90d8d..c6da0cb65a 100644 --- a/api/src/loader/test/SecurityTest.php +++ b/api/src/loader/test/SecurityTest.php @@ -16,8 +16,7 @@ require_once realpath(__DIR__.'/../common.php'); // autoloader & check_load_exte // We're testing 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 { @@ -38,13 +37,13 @@ class SecurityTest extends TestCase { // Must remember to clear this, or other tests may break unset($GLOBALS['egw']); } - + /** * Test some strings for bad stuff - * + * * @param String $pattern String to check * @param boolean $should_fail If we expect this string to fail - * + * * @dataProvider patternProvider */ public function testPatterns($pattern, $should_fail) @@ -129,6 +128,7 @@ class SecurityTest extends TestCase { } catch (Exception $e) { + unset($e); return false; } $replace = array( @@ -175,6 +175,7 @@ class SecurityTest extends TestCase { { if (PHP_VERSION >= 7) { + $matches = null; if (preg_match_all('/([^ ]+) Object\(/', array2string($r), $matches)) { foreach($matches[1] as $class) diff --git a/api/src/test/CacheTest.php b/api/src/test/CacheTest.php index 464c9a7cad..6b2cf9591a 100644 --- a/api/src/test/CacheTest.php +++ b/api/src/test/CacheTest.php @@ -17,7 +17,7 @@ namespace EGroupware\Api; 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; use ReflectionClass; /** diff --git a/api/src/test/DateTimeTest.php b/api/src/test/DateTimeTest.php index 70bd47d564..2e103ea1d5 100644 --- a/api/src/test/DateTimeTest.php +++ b/api/src/test/DateTimeTest.php @@ -13,8 +13,7 @@ namespace EGroupware\Api; 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 @@ -80,8 +79,8 @@ class DateTimeTest extends TestCase { $ts = DateTime::to(array('full' => '20091027', 'hour' => 10, 'minute' => 0),'ts'); $this->assertEquals(DateTime::user2server($ts,''), DateTime::server2user(DateTime::user2server($ts),'')); - $ts = DateTime::to(array('full' => '20090627', 'hour' => 10, 'minute' => 0),'ts'); - $this->assertEquals(DateTime::user2server($ts,''), DateTime::server2user(DateTime::user2server($ts),'')); + $ts2 = DateTime::to(array('full' => '20090627', 'hour' => 10, 'minute' => 0),'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) DateTime::setUserPrefs('Atlantic/Cape_Verde'); - $ts = 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')); + $ts2 = DateTime::to(array('full' => '20091027', 'hour' => 10, 'minute' => 0),'ts'); + $this->assertEquals('2009-10-27 11:00:00', DateTime::user2server($ts2,'Y-m-d H:i:s')); date_default_timezone_set($server_tz); } diff --git a/api/src/test/EtemplateTest.php b/api/src/test/EtemplateTest.php index 330d7616bf..52da834db4 100644 --- a/api/src/test/EtemplateTest.php +++ b/api/src/test/EtemplateTest.php @@ -14,9 +14,6 @@ namespace EGroupware\Api; require_once realpath(__DIR__.'/../Etemplate/test/WidgetBaseTest.php'); -use EGroupware\Api; -use PHPUnit_Framework_TestCase as TestCase; - /** * Test the main class of Etemplate * @@ -34,11 +31,11 @@ class EtemplateTest extends Etemplate\WidgetBaseTest { protected $content = array('value' => 'test content'); protected $sel_options = array(array('value' => 0, 'label' => 'label')); protected $readonlys = array('value' => true); - + /** * 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() { @@ -136,7 +133,7 @@ class EtemplateTest extends Etemplate\WidgetBaseTest { $etemplate->read(static::TEST_TEMPLATE); $this->readonlys['value'] = false; - + $result = $this->mockedRoundTrip($etemplate, $this->content, $this->sel_options, $this->readonlys); $this->assertEquals($this->content, $result); @@ -188,18 +185,18 @@ class EtemplateTest extends Etemplate\WidgetBaseTest { // Now try with widget $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 - $this->assertArraySubset($this->content, $result); - $this->assertArraySubset($preserve, $result); + $this->assertArraySubset($this->content, $result2); + $this->assertArraySubset($preserve, $result2); } public function testReadonlyPreserve() { $etemplate = new Etemplate(); $etemplate->read(static::TEST_TEMPLATE); - + $this->readonlys['value'] = true; $preserve['value'] = 'preserved_value'; @@ -209,10 +206,9 @@ class EtemplateTest extends Etemplate\WidgetBaseTest { $this->assertEquals($preserve['value'], $result['value']); $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 - $this->assertEquals($this->content['value'], $result['value']); - + $this->assertEquals($this->content['value'], $result2['value']); } } diff --git a/api/src/test/IncludeMgrTest.php b/api/src/test/IncludeMgrTest.php index 6d09efc948..ea583f5c44 100644 --- a/api/src/test/IncludeMgrTest.php +++ b/api/src/test/IncludeMgrTest.php @@ -16,11 +16,11 @@ namespace EGroupware\Api; require_once realpath(__DIR__.'/../loader/common.php'); // autoloader & check_load_extension use EGroupware\Api\Framework; -use PHPUnit_Framework_TestCase as TestCase; +use PHPUnit\Framework\TestCase as TestCase; /** * Tests for IncludeMgr - * + * */ class IncludeMgrTest extends TestCase { diff --git a/api/src/test/LoggedInTest.php b/api/src/test/LoggedInTest.php index a9d57c38c5..8df878928e 100644 --- a/api/src/test/LoggedInTest.php +++ b/api/src/test/LoggedInTest.php @@ -16,8 +16,8 @@ namespace EGroupware\Api; require_once realpath(__DIR__.'/../loader/common.php'); // autoloader & check_load_extension -use PHPUnit_Framework_TestCase as TestCase; -use PHPUnit_Framework_ExpectationFailedException as PHPUnitException; +use PHPUnit\Framework\TestCase as TestCase; +use PHPUnit\Framework\ExpectationFailedException as PHPUnitException; use EGroupware\Api; /** @@ -167,7 +167,7 @@ abstract class LoggedInTest extends TestCase $GLOBALS['egw'] = new Api\Egw(array_keys($GLOBALS['egw_domain'])); } - + // Disable asyc while we test $GLOBALS['egw_info']['server']['asyncservice'] = 'off'; } diff --git a/doc/phpunit_bootstrap.php b/doc/phpunit_bootstrap.php index 77000cfb0f..02d6889b32 100644 --- a/doc/phpunit_bootstrap.php +++ b/doc/phpunit_bootstrap.php @@ -7,7 +7,7 @@ * * @link http://www.egroupware.org * @author Nathan Gray - * @package + * @package * @copyright (c) 2017 Nathan Gray * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License */ @@ -15,6 +15,13 @@ // autoloader & check_load_extension 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 $GLOBALS['egw_info']['server']['temp_dir'] = '/tmp'; $GLOBALS['egw_info']['server']['install_id'] = 'PHPUnit test'; \ No newline at end of file