Skip to content

Commit

Permalink
[CMS-459] Add php 8.1 support (#2284)
Browse files Browse the repository at this point in the history
* Add "schedule" event and "long" functional test suit CI workflow

* Add php 8.1 to CI functional testing matrix

* Add "--stop-on-failure" option to "test:short" composer script

* Fix php 8.1 deprecation "Calling a static element on a trait is deprecated"

* Fix php 8.1 deprecation "Deprecated: Return type of XXX should either be compatible with YYY..."

* Fix php 8.1 deprecation "Passing null to non-nullable parameters of built-in functions is deprecated"

* Fix use of CommandExecutorTrait in LocalMachineHelper

* Add php 8.1 support

* Add "workflow_dispatch" event to CI workflow (trigger all functional tests manually)

* Update comment on error_reporting() set
  • Loading branch information
Sergei Churilo authored Dec 17, 2021
1 parent ca22176 commit 6584f0a
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 34 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/3x.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
name: Terminus 3.x
on: push
on:
push:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
inputs:
functional_tests_all:
description: Run all functional tests
required: true
default: '1'
jobs:
# Checkout in separate job because docker image is alpine based and checkout action doesn't work.
checkout_build:
Expand Down Expand Up @@ -37,7 +46,7 @@ jobs:
strategy:
matrix:
operating-system: [ 'macos-latest' ]
php-versions: [ '8.0' ]
php-versions: [ '8.0', '8.1' ]
max-parallel: 1
env:
TERMINUS_TOKEN: ${{ secrets.TERMINUS_TOKEN }}
Expand Down Expand Up @@ -66,7 +75,11 @@ jobs:
- name: Install Composer Dependencies
run: composer install --no-interaction --prefer-dist
- name: Functional Tests (short)
if: ${{ github.event_name == 'push' }}
run: composer test:short
- name: Functional Tests (long)
if: ${{ github.event_name == 'schedule' || github.event.inputs.functional_tests_all == '1' }}
run: composer test:long
- name: Coverage Report
run: composer coverage
- name: Save coverage as artifact
Expand Down
11 changes: 2 additions & 9 deletions bin/terminus
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,8 @@ if (version_compare(PHP_VERSION, '7.4.0', '<') === true) {
echo 'Upgrade to PHP 7.4 or newer to use Terminus 3. For PHP versions prior to 7.4, downgrade to Terminus 2.x.'; echo "\n\n";
exit(1);
} elseif (version_compare(PHP_VERSION, '8.1.0', '>=') === true) {
echo "\n";
echo 'PHP 8.1+ is not supported by this version of Terminus.' . "\n";
echo 'Check for new versions at https://github.com/pantheon-systems/terminus/releases' . "\n";
echo "\n";
if (!getenv('TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP')) {
echo 'Set environment variable TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP to try continuing anyway.' . "\n";
echo "Stopping.\n\n";
exit(1);
}
// Prevent outputting PHP deprecation messages produced by vendors.
error_reporting(error_reporting() & ~E_DEPRECATED);
}

// This variable is automatically managed via updateDependenciesversion() in /RoboFile.php,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"SHELL_INTERACTIVE=true TERMINUS_TEST_MODE=1 behat --colors --config tests/config/behat.yml --stop-on-failure --suite=default"
],
"test:short": [
"XDEBUG_MODE=coverage vendor/bin/phpunit --colors=always -c ./phpunit.xml --debug --group=short --do-not-cache-result --verbose"
"XDEBUG_MODE=coverage vendor/bin/phpunit --colors=always -c ./phpunit.xml --debug --group=short --do-not-cache-result --verbose --stop-on-failure"
],
"test:long": [
"XDEBUG_MODE=coverage vendor/bin/phpunit --colors=always -c ./phpunit.xml --debug --group=long --do-not-cache-result --verbose"
Expand Down
2 changes: 1 addition & 1 deletion src/Collections/OrganizationOwnedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public function __construct($options = [])
public function getUrl()
{
// Replace the {organization_id} token with the actual organization id.
return str_replace('{organization_id}', $this->getOrganization()->id, parent::getUrl());
return str_replace('{organization_id}', $this->getOrganization()->id ?? '', parent::getUrl());
}
}
2 changes: 1 addition & 1 deletion src/Collections/SiteOwnedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public function __construct($options = [])
*/
public function getUrl()
{
return str_replace('{site_id}', $this->getSite()->id, parent::getUrl());
return str_replace('{site_id}', $this->getSite()->id ?? '', parent::getUrl());
}
}
2 changes: 1 addition & 1 deletion src/Collections/UserOwnedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public function __construct($options = [])
public function getUrl()
{
// Replace the {user_id} token with the actual user id.
return str_replace('{user_id}', $this->getUser()->id, parent::getUrl());
return str_replace('{user_id}', $this->getUser()->id ?? '', parent::getUrl());
}
}
2 changes: 1 addition & 1 deletion src/Friends/SiteTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getSite()
*/
public function getUrl()
{
return str_replace('{site_id}', $this->getSite()->id, parent::getUrl());
return str_replace('{site_id}', $this->getSite()->id ?? '', parent::getUrl());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/LocalMachineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LocalMachineHelper implements ConfigAwareInterface, ContainerAwareInterfac
use ContainerAwareTrait;
use IO;
use CommandExecutorTrait {
execute as executeUnbuffered;
CommandExecutorTrait::execute as executeUnbuffered;
}

/**
Expand Down Expand Up @@ -165,7 +165,7 @@ public function writeFile($filename, $content)
protected function fixFilename($filename)
{
$config = $this->getConfig();
return $config->fixDirectorySeparators(str_replace('~', $config->get('user_home'), $filename));
return $config->fixDirectorySeparators(str_replace('~', $config->get('user_home') ?? '', $filename));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Models/TerminusModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function getReferences()
*/
public function getUrl()
{
return str_replace('{id}', $this->id, $this->url);
return str_replace('{id}', $this->id ?? '', $this->url);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Plugins/PluginInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function getLatestVersion()
{
$command = str_replace(
'{package}',
$this->getName(),
$this->getName() ?? '',
self::GET_LATEST_AVAILABLE_VERSION
);
$results = $this->runCommand($command);
Expand Down Expand Up @@ -223,7 +223,7 @@ public static function checkWhetherPackagistProject($project_name, LocalMachineH
// Search for the Packagist project.
$command = str_replace(
'{project}',
$project_name,
$project_name ?? '',
self::VALIDATION_COMMAND
);
$results = $local_machine_helper->exec($command);
Expand Down
19 changes: 8 additions & 11 deletions src/Request/RequestOperationResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,36 +65,33 @@ public function setStatusCodeReason(string $status_code_reason): void
}

/**
* @param mixed $offset
* @return bool
* @inheritdoc
*/
public function offsetExists($offset)
public function offsetExists(mixed $offset): bool
{
return isset($this->{$offset});
}

/**
* @param mixed $offset
* @return mixed|null
* @inheritdoc
*/
public function offsetGet($offset)
public function offsetGet(mixed $offset): mixed
{
return $this->{$offset} ?? null;
}

/**
* @param mixed $offset
* @param mixed $value
* @inheritdoc
*/
public function offsetSet($offset, $value)
public function offsetSet(mixed $offset, mixed $value): void
{
$this->{$offset} = $value;
}

/**
* @param mixed $offset
* @inheritdoc
*/
public function offsetUnset($offset)
public function offsetUnset(mixed $offset): void
{
unset($this->{$offset});
}
Expand Down
11 changes: 9 additions & 2 deletions tests/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@

if (!getenv('TERMINUS_TESTING_RUNTIME_ENV')) {
// Create a testing runtime multidev environment.
$sitename = TerminusTestTrait::getSiteName();
$sitename = (new class {
use TerminusTestTrait;

})::getSiteName();

$multidev = sprintf('test-%s', substr(uniqid(), -6, 6));
$createMdCommand = sprintf('multidev:create %s.dev %s', $sitename, $multidev);
exec(
Expand All @@ -76,7 +80,10 @@
throw new Exception(sprintf('Command "%s" exited with non-zero code (%d)', $createMdCommand, $code));
}

TerminusTestTrait::setMdEnv($multidev);
(new class {
use TerminusTestTrait;

})::setMdEnv($multidev);

register_shutdown_function(function () use ($sitename, $multidev) {
// Delete a testing runtime multidev environment.
Expand Down

0 comments on commit 6584f0a

Please sign in to comment.