From 4e7cb02a78f915f37fe14455ff1040d4b1d822b0 Mon Sep 17 00:00:00 2001 From: Spuds Date: Wed, 24 Jan 2024 15:39:41 -0600 Subject: [PATCH] ! Its php8+ now, update deps as the testbase does not have to support 7.x --- .github/phpunit-webtest.xml | 2 +- .github/setup-elkarte.sh | 6 +- .github/setup-selenium.sh | 3 +- .github/workflows/tests.yaml | 2 +- composer.json | 6 +- tests/ExitHandler.php | 43 +++++---- tests/phpunit_coverage.php | 95 ------------------- tests/prepend.php | 5 +- .../sources/controllers/ElkArteWebSupport.php | 3 +- 9 files changed, 39 insertions(+), 126 deletions(-) delete mode 100644 tests/phpunit_coverage.php diff --git a/.github/phpunit-webtest.xml b/.github/phpunit-webtest.xml index c861236ba0..732bbf7148 100644 --- a/.github/phpunit-webtest.xml +++ b/.github/phpunit-webtest.xml @@ -11,7 +11,7 @@ beStrictAboutTestsThatDoNotTestAnything="false" bootstrap="bootstrapInstall.php"> - + ../tests diff --git a/.github/setup-elkarte.sh b/.github/setup-elkarte.sh index fc7b39926a..ab36109ff2 100755 --- a/.github/setup-elkarte.sh +++ b/.github/setup-elkarte.sh @@ -25,8 +25,10 @@ fi # Phpunit and support # composer config --file=composer2.json && composer install --no-interaction --quiet composer install --no-interaction --quiet -if [[ "$PHP_VERSION" =~ ^8 ]] + +# phpunit-selenium is compatible with phpunit 9.3.x, past that it runs all methods not just test methods +if [[ "$WEBSERVER" != "none" ]] then composer remove phpunit/phpunit phpunit/phpunit-selenium --dev - composer require phpunit/phpunit:^9.0 --dev --update-with-all-dependencies --ignore-platform-reqs + composer require phpunit/phpunit:~9.3 --dev --update-with-all-dependencies --ignore-platform-reqs fi diff --git a/.github/setup-selenium.sh b/.github/setup-selenium.sh index 535dc61f72..fe8aa5f8cf 100755 --- a/.github/setup-selenium.sh +++ b/.github/setup-selenium.sh @@ -71,8 +71,7 @@ else echo "Selenium Success" # Copy phpunit_coverage.php into the webserver's document root directory. - # cp ./vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumCommon/phpunit_coverage.php . - cp ./tests/phpunit_coverage.php . + cp ./vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumCommon/phpunit_coverage.php . # Run the phpunit selenium tests vendor/bin/phpunit --verbose --debug --configuration .github/phpunit-webtest.xml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a284400ae1..37a88f584c 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -19,7 +19,7 @@ jobs: matrix: include: - db: "mysql:5.7" - php: '8.2' + php: '8.1' name: WebTest (PHP ${{ matrix.php }} - DB ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }}) diff --git a/composer.json b/composer.json index 78d00290ff..fe754dca74 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "replace": { }, "require": { - "php": ">=7.2.0", + "php": ">=8.0.0", "ext-json": "*", "ext-gd": "*", "ext-curl": "*", @@ -50,8 +50,8 @@ "ext-imagick": "*" }, "require-dev": { - "phpunit/phpunit-selenium": "8.*", - "phpunit/phpunit": "~8", + "phpunit/phpunit-selenium": "9.0.1", + "phpunit/phpunit": "9.6.*", "myclabs/deep-copy": "1.11.0" }, "autoload": { diff --git a/tests/ExitHandler.php b/tests/ExitHandler.php index 4284cf5e48..42d625b631 100644 --- a/tests/ExitHandler.php +++ b/tests/ExitHandler.php @@ -1,4 +1,7 @@ * */ -class PHPUnit_Extensions_SeleniumCommon_ExitHandler +class ExitHandler { - /** - * Register handler. - * If project have own shutdown hanldler user have to add function to handler - * - */ - public static function init() - { - register_shutdown_function( array( 'PHPUnit_Extensions_SeleniumCommon_ExitHandler', 'handle' ) ); - } + /** + * Register handler. + * If project have own shutdown hanldler user have to add function to handler + * + */ + public static function init() + { + register_shutdown_function(array(ExitHandler::class, 'handle')); + } - /** - * Manual include apendable files - */ - public static function handle() - { - $execFile = ini_get('auto_append_file'); - if ($execFile!=='') { - include_once ($execFile); - } - } + /** + * Manual include apendable files + */ + public static function handle() + { + $execFile = ini_get('auto_append_file'); + if ($execFile!=='') { + include_once ($execFile); + } + } } diff --git a/tests/phpunit_coverage.php b/tests/phpunit_coverage.php deleted file mode 100644 index eba7e43f0a..0000000000 --- a/tests/phpunit_coverage.php +++ /dev/null @@ -1,95 +0,0 @@ -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.0.0 - */ - -$directory = realpath(__DIR__); -while ($directory != '/') { - $autoloadCandidate = $directory . '/vendor/autoload.php'; - if (file_exists($autoloadCandidate)) { - require_once $autoloadCandidate; - break; - } - $directory = realpath($directory . '/..'); -} - -// Set this to the directory that contains the code coverage files. -// It defaults to getcwd(). If you have configured a different directory -// in prepend.php, you need to configure the same directory here. -$GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = getcwd(); - -if (isset($_GET['PHPUNIT_SELENIUM_TEST_ID'])) { - $facade = new \SebastianBergmann\FileIterator\Facade(); - $sanitizedCookieName = str_replace(array('\\'), '_', $_GET['PHPUNIT_SELENIUM_TEST_ID']); - $files = $facade->getFilesAsArray( - $GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'], - $sanitizedCookieName - ); - - $coverage = array(); - - foreach ($files as $file) { - $data = unserialize(file_get_contents($file)); - unlink($file); - unset($file); - $filter = new \SebastianBergmann\CodeCoverage\Filter(); - - foreach ($data as $file => $lines) { - if ($filter->isFile($file)) { - if (!isset($coverage[$file])) { - $coverage[$file] = array( - 'md5' => md5_file($file), 'coverage' => $lines - ); - } else { - foreach ($lines as $line => $flag) { - if (!isset($coverage[$file]['coverage'][$line]) || - $flag > $coverage[$file]['coverage'][$line]) { - $coverage[$file]['coverage'][$line] = $flag; - } - } - } - } - } - } - - print serialize($coverage); -} diff --git a/tests/prepend.php b/tests/prepend.php index a4ab9cdadc..91f25d99c0 100644 --- a/tests/prepend.php +++ b/tests/prepend.php @@ -42,12 +42,15 @@ * @since File available since Release 1.0.0 */ +use PHPUnit\Extensions\SeleniumCommon\ExitHandler; + // By default the code coverage files are written to the same directory // that contains the covered sourcecode files. Use this setting to change // the default behaviour and set a specific directory to write the files to. // If you change the default setting, please make sure to also configure // the same directory in phpunit_coverage.php. Also note that the webserver // needs write access to the directory. + if (!isset($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'])) { $GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = FALSE; } @@ -61,4 +64,4 @@ } include ('ExitHandler.php'); -PHPUnit_Extensions_SeleniumCommon_ExitHandler::init(); +ExitHandler::init(); diff --git a/tests/sources/controllers/ElkArteWebSupport.php b/tests/sources/controllers/ElkArteWebSupport.php index bfc99a6757..62af88b771 100644 --- a/tests/sources/controllers/ElkArteWebSupport.php +++ b/tests/sources/controllers/ElkArteWebSupport.php @@ -21,7 +21,8 @@ */ abstract class ElkArteWebSupport extends Selenium2TestCase { - protected $coverageScriptUrl = 'http://127.0.0.1/phpunit_coverage.php'; + //protected $coverageScriptUrl = 'http://127.0.0.1/phpunit_coverage.php'; + protected $coverageScriptUrl = ''; protected $backupGlobalsExcludeList = ['user_info']; protected $width = 2560; protected $height = 1440;