Skip to content

Commit

Permalink
feat(php): make PHP 8 compatible
Browse files Browse the repository at this point in the history
Commit 1 from fossology#1925
style(php):upgrade fossology from PHP7 to PHP8

Array and string offset access syntax with curly braces is no longer
supported in PHP 8 so made replaced curly braces with [].

Commit 2 from fossology#1925
refactor(syntaxtest.sh): Exclude testdata folder from syntax test

Signed-off-by: Sarita Singh <saritasingh.0425@gmail.com>
Signed-off-by: Gaurav Mishra <mishra.gaurav@siemens.com>
  • Loading branch information
GMishx committed Aug 2, 2022
1 parent b5d428f commit 73d5604
Show file tree
Hide file tree
Showing 63 changed files with 647 additions and 585 deletions.
42 changes: 27 additions & 15 deletions .github/workflows/static-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,28 @@ jobs:
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y php7.4-cli
export PATH="/usr/lib/ccache/:$PATH"
export COMPOSER_HOME="$HOME/.composer/"
sudo update-alternatives --set php /usr/bin/php7.4
- uses: actions/checkout@v2
with:
fetch-depth: 50
- name: Syntax Check
run: |
bash src/testing/syntax/syntaxtest.sh
composer validate --no-check-all --working-dir=src --strict
- name: Setup PHP 7.4
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: gettext, mbstring, gd, json, xml, zip, pgsql, curl, uuid, posix, sqlite3
- name: Composer check on PHP 7.4
run: composer validate --no-check-all --working-dir=src --strict
- name: Setup PHP 8.1
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: gettext, mbstring, json, xml, pgsql, curl, uuid, posix, sqlite3
- name: Composer check on PHP 8.1
run: composer validate --no-check-all --working-dir=src --strict

code-analysis:
runs-on: ubuntu-20.04
Expand All @@ -47,34 +58,35 @@ jobs:
codesniffer:
runs-on: ubuntu-20.04
steps:
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y php-cli
export PATH="/usr/lib/ccache/:$PATH"
export COMPOSER_HOME="$HOME/.composer/"
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: gettext, mbstring, gd, json, xml, zip, pgsql, curl, uuid, posix, sqlite3
- uses: actions/checkout@v2
with:
fetch-depth: 50
- name: PHP Codesniffer
run: |
export COMPOSER_HOME="$HOME/.composer/"
composer install --prefer-dist --working-dir=src
src/vendor/bin/phpcs --standard=src/fossy-ruleset.xml -p
composer --working-dir=src run-script phpcs
copy-paste:
runs-on: ubuntu-20.04
continue-on-error: true
steps:
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y php-cli
export PATH="/usr/lib/ccache/:$PATH"
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: gettext, mbstring, gd, json, xml, zip, pgsql, curl, uuid, posix, sqlite3
- uses: actions/checkout@v2
with:
fetch-depth: 50
- name: Copy/Paste detector
run: |
export COMPOSER_HOME="$HOME/.composer/"
composer install --prefer-dist --working-dir=src
sudo phpdismod -v ALL -s ALL xdebug
src/vendor/bin/phpcpd src/cli/ src/copyright/ src/decider*/ src/lib/ src/monk/ src/nomos/ src/readmeoss/ src/spdx2/ src/www/ || echo -e "\033[0;31mDuplication detected: Task Failed"
Expand Down
66 changes: 63 additions & 3 deletions .github/workflows/test-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4'] # Can be extended in future
php: ['7.4', '8.1']
services:
postgres:
image: postgres:12
Expand All @@ -32,7 +32,6 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -49,7 +48,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, gd, xml, zip, json, sqlite3, curl
extensions: gettext, mbstring, gd, json, xml, zip, pgsql, curl, uuid, posix, sqlite3
env:
fail-fast: true

Expand All @@ -69,3 +68,64 @@ jobs:
make test-cli test-copyright test-lib test-monk \
test-nomos test-ojo test-reuser test-scheduler test-spdx2 \
test-unifiedreport test-www
php-unit:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.1']
services:
postgres:
image: postgres:12
env:
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 50
- name: Install Dependencies
run: |
sudo ./utils/fo-installdeps -y -e
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: gettext, mbstring, gd, json, xml, zip, pgsql, curl, uuid, posix, sqlite3
env:
fail-fast: true
- name: Enable coverage for PHP < 8
if: ! contains(matrix.php, '8')
run: |
echo "XDEBUG_MODE=coverage" >> $GITHUB_ENV
- name: Setup test database and build
env:
PGHOST: 127.0.0.1
PGPORT: 5432
run: |
./utils/prepare-test -afty
make
find . -type d -name 'agent_tests' -exec make -C {} all \;
composer update --ignore-platform-reqs --with-dependencies --prefer-dist --working-dir=src phpunit/phpunit
mkdir coverage
- name: PHPUnit test suit
env:
PGHOST: 127.0.0.1
PGPORT: 5432
run: |
./src/vendor/bin/phpunit -csrc/phpunit.xml --testsuite="Fossology PhpUnit Test Suite" --colors=always --coverage-clover ./coverage/unit-clover.xml
- name: PHPUnit agent test suit
env:
PGHOST: 127.0.0.1
PGPORT: 5432
run: |
./src/vendor/bin/phpunit -csrc/phpunit.xml --testsuite="Fossology PhpUnit Agent Test Suite" --colors=always --coverage-clover ./coverage/agent-clover.xml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,4 @@ ubuntu-*

# PHPUnit cache
.phpunit.result.cache
/phpenv/
11 changes: 6 additions & 5 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Build-Depends: debhelper (>=9~), libglib2.0-dev, libmagic-dev, libxml2-dev,
libmxml-dev, libtext-template-perl, librpm-dev, subversion, rpm, libpcre3-dev,
libssl-dev, postgresql-server-dev-all, libboost-regex-dev, libicu-dev,
libboost-program-options-dev, libjsoncpp-dev, libjson-c-dev, libpq-dev,
php7.0-cli|php7.2-cli|php7.3-cli|php7.4-cli, php-mbstring, php-zip,
php-xml, libboost-system-dev, libboost-filesystem-dev, libgcrypt20-dev,
composer
php7.0-cli|php7.2-cli|php7.3-cli|php7.4-cli, php-mbstring, php-zip, php-curl,
php-gd, php-pgsql, php-uuid, php-xml, libboost-system-dev,
libboost-filesystem-dev, libgcrypt20-dev, composer
Standards-Version: 3.9.1
Homepage: https://fossology.org

Expand Down Expand Up @@ -48,8 +48,9 @@ Description: open and modular architecture for analyzing software
Package: fossology-common
Architecture: any
Depends: php7.0-pgsql|php7.2-pgsql|php7.3-pgsql|php7.4-pgsql, php-pear,
php7.0-cli|php7.2-cli|php7.3-cli|php7.4-cli, php-mbstring,
php7.0-json|php7.2-json|php7.3-json|php7.4-json, php-zip, php-xml,
php7.0-cli|php7.2-cli|php7.3-cli|php7.4-cli, php-mbstring, php-zip, php-xml,
php7.0-gd|php7.2-gd|php7.3-gd|php7.4-gd, php-uuid,
php7.0-json|php7.2-json|php7.3-json|php7.4-json,
php7.0-curl|php7.2-curl|php7.3-curl|php7.4-curl,
${shlibs:Depends}, ${misc:Depends}
Description: architecture for analyzing software, common files
Expand Down
31 changes: 12 additions & 19 deletions src/cli/fo_wrapper.php.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ $Plugins = array();
/* Set SYSCONFDIR and set global (for backward compatibility) */
/** get sysconfdir */
$sysconfdir = "";
for ($i = 1;$i < $argc;$i++)
{
for ($i = 1;$i < $argc;$i++) {
$arg = $argv[$i];
if ("-c" === $arg) {
$sysconfdir = $argv[$i + 1];
Expand All @@ -46,8 +45,7 @@ $projectGroup = $SysConf['DIRECTORIES']['PROJECTGROUP'] ?: 'fossy';
$gInfo = posix_getgrnam($projectGroup);
posix_setgid($gInfo['gid']);
$groups = `groups`;
if (!preg_match("/\s$projectGroup\s/",$groups) && (posix_getgid() != $gInfo['gid']))
{
if (!preg_match("/\s$projectGroup\s/",$groups) && (posix_getgid() != $gInfo['gid'])) {
print "FATAL: You must be in group '$projectGroup'.\n";
exit(1);
}
Expand Down Expand Up @@ -105,14 +103,13 @@ function bootstrap($sysconfdir="")
error_reporting(E_ERROR | E_WARNING | E_PARSE);

$rcfile = "fossology.rc";
if (empty($sysconfdir))
{
if (empty($sysconfdir)) {
$sysconfdir = getenv('SYSCONFDIR');
if ($sysconfdir === false)
{
if (file_exists($rcfile)) $sysconfdir = file_get_contents($rcfile);
if ($sysconfdir === false)
{
if ($sysconfdir === false) {
if (file_exists($rcfile)) {
$sysconfdir = file_get_contents($rcfile);
}
if ($sysconfdir === false) {
/** set the sysconfdir with default */
$sysconfdir = "{$SYSCONFDIR}";
}
Expand All @@ -124,15 +121,13 @@ function bootstrap($sysconfdir="")

/************* Parse fossology.conf *******************/
$ConfFile = "{$sysconfdir}/fossology.conf";
if (!file_exists($ConfFile))
{
if (!file_exists($ConfFile)) {
$text = _("FATAL! Missing configuration file: $ConfFile");
echo "$text\n";
exit(1);
}
$SysConf = parse_ini_file($ConfFile, true);
if ($SysConf === false)
{
if ($SysConf === false) {
$text = _("FATAL! Invalid configuration file: $ConfFile");
echo "$text\n";
exit(1);
Expand All @@ -142,8 +137,7 @@ function bootstrap($sysconfdir="")
* For example, if PREFIX=/usr/local and BINDIR=$PREFIX/bin, we
* want BINDIR=/usr/local/bin
*/
foreach($SysConf['DIRECTORIES'] as $var=>$assign)
{
foreach ($SysConf['DIRECTORIES'] as $var=>$assign) {
/* Evaluate the individual variables because they may be referenced
* in subsequent assignments.
*/
Expand All @@ -155,8 +149,7 @@ function bootstrap($sysconfdir="")
$GLOBALS[$var] = ${$var};
}

if (empty($MODDIR))
{
if (empty($MODDIR)) {
$text = _("FATAL! System initialization failure: MODDIR not defined in $SysConf");
echo $text. "\n";
exit(1);
Expand Down
4 changes: 2 additions & 2 deletions src/cli/tests/test_fo_copyright_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function test_get_copyright_list_all()
$this->assertEquals("B.zip/B/1b/AAL_B: copyright (c) 2002 by author", $output[22]);
}

function test_get_copryright_list_email()
function test_get_copyright_list_email()
{
$upload_id = 2;
$auth = "--user fossy --password fossy";
Expand All @@ -69,7 +69,7 @@ function test_get_copryright_list_email()
$this->assertEquals("B.zip/B/1b/3DFX_B: info@3dfx.com", $output[7]);
}

function test_get_copryright_list_withoutContainer()
function test_get_copyright_list_withoutContainer()
{
$upload_id = 2;
$auth = "--user fossy --password fossy";
Expand Down
11 changes: 4 additions & 7 deletions src/clixml/agent_tests/Functional/SchedulerTestRunnerCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class SchedulerTestRunnerCli implements SchedulerTestRunner
{
/** @var TestPgDb */
private $testDb;

public function __construct(TestPgDb $testDb)
{
$this->testDb = $testDb;
}

public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
{
$sysConf = $this->testDb->getFossSysConf();
Expand All @@ -36,15 +36,12 @@ public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")

$output = "";
$retCode = -1;
if ($success)
{
if ($success) {
while (($buffer = fgets($pipeFd, 4096)) !== false) {
$output .= $buffer;
}
$retCode = pclose($pipeFd);
}
else
{
} else {
print "failed opening pipe to $cmd";
}

Expand Down
5 changes: 2 additions & 3 deletions src/clixml/agent_tests/Functional/fo_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ INSERT INTO pfile VALUES (4, 'BE09F57E1E58119F1537439BA545835C', 'FD7D17CFA15074
INSERT INTO pfile VALUES (5, '39C379E9C7F5BB524754C4DEF5FEF135', '840B588279248271D93ACA3092AD5F4DC724BDA4', '47A4CEE30C085C497E628BAB975FD586B5BED6FB25CC2720AE17339937436158', 285, NULL);
INSERT INTO pfile VALUES (6, '2702A657B801333C3150BDC8BE642F9B', '798826BF3EB294E5D514ECFA3222CCF09BBCD985', '8DF6EB5D69FFE2BF61937D49F3EF72E98213FD09F9AD41C626E419503178BACD', 14554, NULL);


INSERT INTO users VALUES (1, 'Default User', 1, 'Default User when nobody is logged in', 'Seed', 'Pass', 0, NULL, 'y', NULL, NULL, 'simple', NULL, NULL, NULL);
INSERT INTO users VALUES (2, 'fossy', 1, 'Default Administrator', '14272952581103610285', 'cdd40d0517419e8495a6e40b14369b6a39031581', 10, 'y', 'y', NULL, NULL, 'simple', NULL, NULL, NULL);
INSERT INTO users (user_pk, user_name, root_folder_fk, user_desc, user_seed, user_pass, user_perm, user_email, user_agent_list, email_notify, ui_preference, default_folder_fk) VALUES (1, 'Default User', 1, 'Default User when nobody is logged in', 'Seed', 'Pass', 0, NULL, NULL, 'y', 'simple', 1);
INSERT INTO users (user_pk, user_name, root_folder_fk, user_desc, user_seed, user_pass, user_perm, user_email, user_agent_list, email_notify, ui_preference, default_folder_fk) VALUES (2, 'fossy', 1, 'Default Administrator', '14272952581103610285', 'cdd40d0517419e8495a6e40b14369b6a39031581', 10, NULL, NULL, 'y', 'simple', 1);


INSERT INTO clearing_decision (clearing_decision_pk, uploadtree_fk, pfile_fk, user_fk, group_fk, decision_type, scope, date_added) VALUES (2, 4, 2, 2, 2, 5, 1, '2015-05-04 11:43:18.276425+02');
Expand Down
9 changes: 4 additions & 5 deletions src/clixml/agent_tests/Functional/schedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
include_once(__DIR__.'/SchedulerTestRunnerCli.php');

class SchedulerTest extends \PHPUnit_Framework_TestCase
class SchedulerTest extends \PHPUnit\Framework\TestCase
{
/** @var int */
private $userId = 2;
Expand All @@ -30,7 +30,7 @@ class SchedulerTest extends \PHPUnit_Framework_TestCase
/** @var SchedulerTestRunnerCli */
private $runnerCli;

protected function setUp()
protected function setUp() : void
{
$this->testDb = new TestPgDb("clixmltest");
$this->dbManager = $this->testDb->getDbManager();
Expand All @@ -41,7 +41,7 @@ protected function setUp()
$this->agentDir = dirname(dirname(__DIR__));
}

protected function tearDown()
protected function tearDown() : void
{
$this->testDb->fullDestruct();
$this->testDb = null;
Expand Down Expand Up @@ -81,8 +81,7 @@ private function setUpTables()
private function getHeartCount($output)
{
$matches = array();
if (preg_match("/.*HEART: ([0-9]*).*/", $output, $matches))
{
if (preg_match("/.*HEART: ([0-9]*).*/", $output, $matches)) {
return intval($matches[1]);
}
return -1;
Expand Down
Loading

0 comments on commit 73d5604

Please sign in to comment.