From 87928371de8a316c9880a451fae04d9785c32840 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 14 Sep 2021 13:47:31 +0300 Subject: Merge pull request #6045 from gxgpet/develop_fixtravis Fixes Travis pipeline. Adding PHPUnit 8. --- tests/Bootstrap.php | 7 +++++++ tests/codeigniter/Setup_test.php | 2 +- tests/codeigniter/core/Input_test.php | 10 +++++++++- .../codeigniter/database/query_builder/select_test.php | 2 +- tests/codeigniter/helpers/file_helper_test.php | 5 +---- tests/codeigniter/helpers/text_helper_test.php | 7 +------ tests/mocks/ci_testcase.php | 18 ++++++++++++++++-- tests/phpunit.xml | 3 ++- 8 files changed, 38 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index b4e56bdae..ada6a5998 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -65,6 +65,13 @@ else is_php('5.6') && ini_set('php.internal_encoding', 'UTF-8'); +if (is_php('7.0')) +{ + $test_case_code = file_get_contents(PROJECT_BASE.'vendor/phpunit/phpunit/src/Framework/TestCase.php'); + $test_case_code = preg_replace('/^\s+((?:protected|public)(?: static)? function \w+\(\)): void/m', '$1', $test_case_code); + file_put_contents(PROJECT_BASE.'vendor/phpunit/phpunit/src/Framework/TestCase.php', $test_case_code); +} + include_once SYSTEM_PATH.'core/compat/mbstring.php'; include_once SYSTEM_PATH.'core/compat/hash.php'; include_once SYSTEM_PATH.'core/compat/password.php'; diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php index 5317c56c7..43545822a 100644 --- a/tests/codeigniter/Setup_test.php +++ b/tests/codeigniter/Setup_test.php @@ -1,6 +1,6 @@ assertSame(array(), $this->input->get()); @@ -136,7 +144,7 @@ class Input_test extends CI_TestCase { $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless); $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST['foo']['bar'] = 'baz'; + $_POST['foo'] = array('bar' => 'baz'); $barArray = array('bar' => 'baz'); $this->assertEquals('baz', $this->input->post('foo[bar]')); diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index 93b5c3d46..facda791f 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -74,7 +74,7 @@ class Select_test extends CI_TestCase { ->row(); // Average should be 2.5 - $this->assertEquals('2.5', $job_avg->id); + $this->assertEquals(2.5, (float) $job_avg->id); } // ------------------------------------------------------------------------ diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php index ad56beb28..0d7ae96ee 100644 --- a/tests/codeigniter/helpers/file_helper_test.php +++ b/tests/codeigniter/helpers/file_helper_test.php @@ -6,10 +6,7 @@ class File_helper_Test extends CI_TestCase { { $this->helper('file'); - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); - - $this->_test_dir = vfsStreamWrapper::getRoot(); + $this->_test_dir = vfsStream::setup(''); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index b6902c016..7a7dc0a12 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -64,12 +64,7 @@ class Text_helper_test extends CI_TestCase { public function test_convert_accented_characters() { - $path = 'application/config/foreign_chars.php'; - $this->ci_vfs_clone($path); - if (is_php('7.4')) - { - copy(PROJECT_BASE.$path, APPPATH.'../'.$path); - } + $this->ci_vfs_clone('application/config/foreign_chars.php'); $this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÏÔŒÙÛÜŸ')); $this->assertEquals('a e i o u n ue', convert_accented_characters('á é í ó ú ñ ü')); } diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php index 8dc4682ef..de46f6df6 100644 --- a/tests/mocks/ci_testcase.php +++ b/tests/mocks/ci_testcase.php @@ -1,6 +1,6 @@ ci_vfs_root = vfsStream::setup(); + $this->ci_vfs_root = vfsStream::setup(''); $this->ci_app_root = vfsStream::newDirectory('application')->at($this->ci_vfs_root); $this->ci_base_root = vfsStream::newDirectory('system')->at($this->ci_vfs_root); $this->ci_view_root = vfsStream::newDirectory('views')->at($this->ci_app_root); @@ -381,4 +381,18 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { return parent::__call($method, $args); } + public function setExpectedException($exception_class, $exception_message = '', $exception_code = null) + { + $use_expect_exception = method_exists($this, 'expectException'); + + if ($use_expect_exception) + { + $this->expectException($exception_class); + $exception_message !== '' && $this->expectExceptionMessage($exception_message); + } + else + { + parent::setExpectedException($exception_class, $exception_message, $exception_code); + } + } } diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 875198c4e..a1626ce91 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -8,7 +8,8 @@ stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" - stopOnSkipped="false"> + stopOnSkipped="false" + beStrictAboutTestsThatDoNotTestAnything="false"> ./codeigniter/core -- cgit v1.2.3-24-g4f1b