Skip to content

Commit

Permalink
PHP8 Related Changes
Browse files Browse the repository at this point in the history
- acl-config
  - `join` function signature has changed in PHP8
- RealmManager.php
  - The order in which these values were being returned differed between PHP7.2
    and PHP8.0. I've just added code to force the ordering to be as we expect.
- ExportBuilder.php
  - PHP8 is more strict in what it allows in function signatures and optional
    arguments (arguments with default values) cannot come before required
    arguments (arguments without default values).
- Visualization.php
  - HSVtoRGB: PHP7.2 did more coercing of types than PHP8 does so we needed an
    explicit cast to int here.
- pdoAggregator.php
  - The previous code here expected that `current` would always return an
    `array` when it can also return a `bool`. I've just updated the code to take
    this into account.
- HpcdbHostsIngestor.php
  - updated the function signature of `transform` so that it matches it's parent
    `pdoIngestor`
- aRdbmsDestinationAction.php
  - This code previously assumed that `$item['alias']` was going to be an array
    and that it would contain a key 'as'. I just made it explicit.
- composer.json
  - Added PHP8.0 to the list of supported PHP's.
  - Updated phpoffice/phpword's version to * because the previous version
    doesn't support PHP8
  - Updated PHPUnit to 9+ as it was the most recent version that supported
    PHP8.0

PHPUnit9+ changes

The "types" of changes in this commit are all related to PHPUnit9+ and PHP8:
- PHP8 reports a larger mantissa than in PHP7.2 so a few values have been
updated to reflect that.
- PHPUnit9+ uses actual namespacing so anywhere there was
  `PHPUnit_Framework_TestCase` has been changed to
  `\PHPUnit\Framework\TestCase`. The same basic idea was applied to Errors and
  Exceptions as well.
- PHPUnit9+ has added some new functions, deprecated others, and removed yet
  others. There are numerous locations where substitutions for curently
  recommended functions were made.
- phpunit.xml.dist files have been updated
  • Loading branch information
eiffel777 authored and spark0r committed May 16, 2024
1 parent 14a6d2e commit 9380376
Show file tree
Hide file tree
Showing 128 changed files with 2,051 additions and 1,450 deletions.
30 changes: 26 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ jobs:
#- setup_remote_docker:
# docker_layer_caching: true
# Download and cache dependencies
- run:
name: Update php module
command: dnf module -y reset php && dnf module -y enable php:8.0
- run:
name: Install PHP 8.0
command: dnf install -y php
- run:
name: Install PHP module pre-reqs & an updated version of PHP Pear
command: dnf install -y libzip-devel php-pear
- run:
name: Install MongoDB Pear module
command: yes '' | pecl install mongodb || true
- run:
name: install the composer dependencies
command: composer install
Expand All @@ -43,7 +55,13 @@ jobs:
command: |
mkdir ~/phpunit
mkdir /tmp/screenshots
- run: ~/bin/buildrpm xdmod
- run:
name: 'Fixup Simplesaml'
command: |
sed -i 's/SimpleSAML_Error_Assertion::installHandler();//g' vendor/simplesamlphp/simplesamlphp/www/_include.php
- run:
name: Build XDMoD RPM
command: ~/bin/buildrpm xdmod
- run:
name: Install / Upgrade XDMoD from RPM
command: ./tests/ci/bootstrap.sh
Expand Down Expand Up @@ -82,20 +100,24 @@ jobs:
chown root:root -R /usr/local/node-v10.24.1-linux-x64
- run: pushd ./tests/ui && PATH=/usr/local/node-v10.24.1-linux-x64/bin:$PATH /usr/local/node-v10.24.1-linux-x64/bin/npm install && popd
- run: PATH=/usr/local/node-v10.24.1-linux-x64/bin:$PATH ./tests/ui/runtests.sh --headless --log-junit ~/phpunit

- run:
name: 'Run SSO Tests'
command: |
PATH=/usr/local/node-v10.24.1-linux-x64/bin:$PATH ./tests/ci/samlSetup.sh
PATH=/usr/local/node-v10.24.1-linux-x64/bin:$PATH ./tests/ui/runtests.sh --headless --log-junit ~/phpunit --sso
./vendor/phpunit/phpunit/phpunit -c ./tests/integration/phpunit.xml.dist --testsuite sso --log-junit ~/phpunit/xdmod-sso-integration.xml
- run:
name: Ensure that no unexpected Apache errors were generated
command: test ! -e /var/log/php-fpm/www-error.log
name: Ensure that no unexpected Apache errors were generated ( We expect PHP Deprecated )
command: >
if [ -e /var/log/php-fpm/www-error.log ]; then
test `fgrep -v 'PHP Deprecated' /var/log/php-fpm/www-error.log | wc -l` = 0;
fi
- run:
name: Ensure that no PHP command-line errors were generated
command: >
if [ -e /var/log/php_errors.log ]; then
test `fgrep -v 'vendor/phpunit/phpunit/src' /var/log/php_errors.log | wc -l` = 0;
test `egrep -v 'vendor/phpunit/phpunit/src|PHP Deprecated|PHP Notice: fread()' /var/log/php_errors.log | wc -l` = 0;
fi
- store_artifacts:
path: /tmp/screenshots
Expand Down
2 changes: 1 addition & 1 deletion bin/acl-config
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ SQL;
$inserted = 0;
while ($row = $statement->fetch(PDO::FETCH_NUM) ) {
$inserted += 1;
if (fwrite($bulkdatafile, join($row, ',') . "\n") === false) {
if (fwrite($bulkdatafile, join(',', $row) . "\n") === false) {
throw new \Exception('Error writing to temporary file');
}
}
Expand Down
2 changes: 1 addition & 1 deletion classes/CCR/MailWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MailWrapper

public static function initPHPMailer($properties)
{
$mail = new \PHPMailer(true);
$mail = new \PHPMailer\PHPMailer\PHPMailer(true);
$mail->isSendMail();
$address = \xd_utilities\getConfiguration('mailer', 'sender_email');
$mail->Sender = $address;
Expand Down
2 changes: 1 addition & 1 deletion classes/DB/PDODBMultiIngestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class PDODBMultiIngestor implements Ingestor
function __construct(
$dest_db,
$source_db,
$pre_ingest_update_statements = array(),
$source_query,
$insert_table,
$pre_ingest_update_statements = array(),
$insert_fields = array(),
$post_ingest_update_statements = array(),
$delete_statement = null,
Expand Down
2 changes: 1 addition & 1 deletion classes/DB/PDODBUnbufferedMultiIngestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public function __construct(
parent::__construct(
$dest_db,
$source_db,
$pre_ingest_update_statements,
$source_query,
$insert_table,
$pre_ingest_update_statements,
$insert_fields,
$post_ingest_update_statements,
$delete_statement,
Expand Down
2 changes: 1 addition & 1 deletion classes/DataWarehouse/ExportBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public static function getFormat(
* @return array(headers => array of http headers, results => the encoded data to send)
*/
public static function export(
array $exportedDatas = array(),
array $exportedDatas,
$format,
$inline = true,
$filename = 'data'
Expand Down
6 changes: 3 additions & 3 deletions classes/DataWarehouse/Visualization.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public static function getColors($count = NULL, $palleteIndex = 0, $includeWhite
srand();
return $ret;
}

public static function HSVtoRGB(array $hsv)
{
list($H, $S, $V) = $hsv;
//1
$H *= 6;
//2
$I = floor($H);
//2 NOTE: we cast to int so that the switch below works as intended in PHP8
$I = (int)floor($H);
$F = $H - $I;
//3
$M = $V * (1 - $S);
Expand Down
9 changes: 8 additions & 1 deletion classes/ETL/Aggregator/pdoAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,14 @@ protected function _execute($aggregationUnit)
$aggregationPeriodList = $this->getDirtyAggregationPeriods($aggregationUnit);
$numAggregationPeriods = count($aggregationPeriodList);
$firstPeriod = current($aggregationPeriodList);
$periodSize = $firstPeriod['period_end_day_id'] - $firstPeriod['period_start_day_id'];

// There are instances where $firstPeriod is a bool not an array ( when $aggregationPeriodList is empty or at the end of the array)
// the following code takes that into account.
$periodSize = 1;
if (!is_bool($firstPeriod)) {
$periodSize = $firstPeriod['period_end_day_id'] - $firstPeriod['period_start_day_id'];
}

$batchSliceSize = $this->options->batch_aggregation_periods_per_batch;
$tmpTableName = null;
$qualifiedTmpTableName = null;
Expand Down
2 changes: 1 addition & 1 deletion classes/ETL/DataEndpoint/aStructuredFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected function attachFilters()
$this->logger->warning(
sprintf("Skipping filter '%s': %s", $config->name, implode(", ", $messages))
);
continue;
continue 2;
}
$filterName = 'xdmod.external_process';
$resource = @stream_filter_prepend($fd, $filterName, STREAM_FILTER_READ, $config);
Expand Down
2 changes: 1 addition & 1 deletion classes/ETL/Ingestor/HpcdbHostsIngestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HpcdbHostsIngestor extends pdoIngestor implements iAction
/**
* @see ETL\Ingestor\pdoIngestor::transform
*/
public function transform(array $srcRecord, $orderId)
public function transform(array $srcRecord, &$orderId)
{
$srcRecord = parent::transform($srcRecord, $orderId);
$transformedRecord = array();
Expand Down
2 changes: 2 additions & 0 deletions classes/ETL/aRdbmsDestinationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,8 @@ public function getSqlColumnNames($sql)

foreach ( $parsedSql['SELECT'] as $item ) {
if ( array_key_exists('alias', $item)
&& is_array($item['alias'])
&& array_key_exists('as', $item['alias'])
&& $item['alias']['as']
&& array_key_exists('name', $item['alias'])
) {
Expand Down
2 changes: 1 addition & 1 deletion classes/OpenXdmod/Shredder.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,9 @@ public function getJobIngestor($ingestAll = false)
$ingestor = new PDODBMultiIngestor(
$this->db,
$this->db,
array(),
$sourceQuery,
'shredded_job',
array(),
$insertFields,
array(),
$deleteStatement
Expand Down
4 changes: 2 additions & 2 deletions classes/Realm/GroupBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public function __construct($shortName, \stdClass $config, Realm $realm, LoggerI
break;
case 'dataset_display_type':
if ( ! is_object($optionValue) ) {
continue;
continue 2;
}
foreach ($optionValue as $datasetType => $chartDisplayValue ) {
if ( ! array_key_exists($datasetType, $this->chartOptions[$optionKey]) ) {
Expand All @@ -388,7 +388,7 @@ public function __construct($shortName, \stdClass $config, Realm $realm, LoggerI
break;
case 'limit':
if ( ! is_object($optionValue) ) {
continue;
continue 2;
}
foreach ($optionValue as $pageType => $limitValue ) {
if ( ! array_key_exists($pageType, $this->chartOptions[$optionKey]) ) {
Expand Down
5 changes: 5 additions & 0 deletions classes/Rest/Utilities/Conversions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public static function toInt($value)
*/
public static function toString($value)
{
// If no value was provided, then return an empty string.
if (is_null($value)) {
return '';
}

$isObject = is_object($value);
$hasToString = method_exists($value, '__toString');
$isArray = is_array($value);
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"COMMENT": "If kassner/log-parser is updated to version >2.1.1, then the call to web_parser->addPattern in classes/ETL/DataEndpoint/WebServerLogFile.php (added in https://github.com/ubccr/xdmod/pull/1816) can be removed along with this 'extra' section."
},
"require": {
"php": "^5.4 || ^7.2",
"php": "^8.0",
"egulias/email-validator": "^1.2",
"google/recaptcha": "~1.1",
"greenlion/php-sql-parser": "~4.2",
Expand All @@ -12,27 +12,27 @@
"moment/moment-min-file": "^2.13.0",
"moment/moment-timezone-min-file": "^0.5.4",
"paragonie/random_compat": "~2.0",
"phpmailer/phpmailer": "^5.2",
"phpmailer/phpmailer": "*",
"robrichards/xmlseclibs": "~3.0",
"sencha/extjs-gpl": "3.4.*",
"silex/silex": "~1.2",
"simplesamlphp/simplesamlphp": "~1",
"simplesamlphp/simplesamlphp": "^1.16",
"symfony/polyfill-php56": "~1.11",
"symfony/process": "~2.0",
"taq/pdooci": "^1.0",
"tildeio/rsvpjs-min-file": "^3.0.18",
"ubccr/simplesamlphp-module-authglobus": "^1.3",
"ubccr/simplesamlphp-module-authoidcoauth2": "^1.1",
"phpoffice/phpword": "^0.17.0",
"phpoffice/phpword": "*",
"monolog/monolog": "^1.25",
"plotly/plotly": "^2.29.1",
"kassner/log-parser": "~1.5",
"geoip2/geoip2": "~2.0",
"ua-parser/uap-php": "^3.9",
"mongodb/mongodb": "^1.11"
"mongodb/mongodb": "^1.14"
},
"require-dev": {
"phpunit/phpunit": "~4.8",
"phpunit/phpunit": "^9.0",
"ccampbell/chromephp": "^4.1",
"swaggest/json-schema": "^0.12.41"
},
Expand Down
Loading

0 comments on commit 9380376

Please sign in to comment.