Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also run unit tests on PHP 8.0 and 8.1 #119

Merged
merged 54 commits into from
May 6, 2022
Merged

Also run unit tests on PHP 8.0 and 8.1 #119

merged 54 commits into from
May 6, 2022

Conversation

kienstra
Copy link
Contributor

@kienstra kienstra commented Apr 30, 2022

Changes

  • Also run unit tests on PHP 8.0 and 8.1.
  • Correct PHP 8 issues.

Testing instructions

Not needed, just a sanity check would be great.

npm run lint:pkg-json
if [ -n "$( git diff --diff-filter=d --staged --name-only | grep -E 'package.json' )" ]
then
npm run lint:pkg-json
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no change to package.json, no need to lint it in the pre-commit hook

@@ -51,7 +51,7 @@ public function add_submenu_page() {
* Add submenu pages to the Genesis Custom Blocks menu.
*/
public function maybe_redirect() {
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
$page = filter_input( INPUT_GET, 'page' );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FILTER_SANITIZE_STRING is deprecated in PHP 8.1.

By removing it here, it will use the default filter of FILTER_UNSAFE_RAW.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the deprecation notice:

Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /var/www/html/wp-content/plugins/project/php/Blocks/Loader.php on line 545

@@ -27,8 +27,8 @@ class TestTemplateOutput extends AbstractAttribute {
*
* @inheritdoc
*/
public function setUp() {
parent::setUp();
public function set_up() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing setUp() to set_up(), like in Core, allows this to not have a :void return declaration, without causing a PHP error.

Copy link
Contributor Author

@kienstra kienstra May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also prevents having an ugly phpcs:ignore on this line.

@@ -148,14 +148,14 @@ public function test_block_template() {
$actual_template = str_replace( [ "\t", "\n" ], '', $rendered_template );

// The 'className' should be present.
$this->assertContains(
$this->assertStringContainsString(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertContains() causes a PHPUnit error in PHP 8.1, as a string is not iterable

@@ -11,27 +11,25 @@ references:
executors:
php:
docker:
- image: cimg/php:7.4.5-node
- image: cimg/php:7.4-node
Copy link
Contributor Author

@kienstra kienstra Apr 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 5 isn't needed, any 7.4.* version should be fine

description: "Ensure nodegit runs without error"
steps:
- run: sudo apt-get update && sudo apt-get install libkrb5-dev
- run: composer update
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This'll ensure that the Composer packages are compatible with the PHP version, whether it be 5.6 or 8.1


e2e-tests:
machine:
image: ubuntu-1604:202004-01
image: ubuntu-2004:202111-02
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1604 is deprecated

"squizlabs/php_codesniffer": "3.5.3",
"wp-coding-standards/wpcs": "2.2.0",
"phpunit/phpunit": "7.5.2"
"brain/monkey": "^2",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uses a version of ^2 instead of 2.4.0, as it's fine for composer to get the latest 2.*

@@ -132,7 +132,7 @@ abstract public function register_settings();
/**
* Gets a JSON-serialized version of this object.
*
* @return array|mixed The JSON-serialized object.
* @return mixed The JSON-serialized object.
Copy link
Contributor Author

@kienstra kienstra Apr 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a PHP 8 notice:

Deprecated: Return type of Genesis\CustomBlocks\Blocks\Controls\ControlAbstract::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/wp-content/plugins/project/php/Blocks/Controls/ControlAbstract.php on line 137

$abspath = ABSPATH;

// Workaround for weird hosting situations.
if ( trailingslashit( ABSPATH ) . 'wp-content' !== WP_CONTENT_DIR && isset( $_SERVER['DOCUMENT_ROOT'] ) ) {
$abspath = sanitize_text_field( wp_unslash( $_SERVER['DOCUMENT_ROOT'] ) );
}

$stylesheet_url = str_replace( untrailingslashit( $abspath ), '', $path );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a PHP 8 error in PHPUnit tests.

If $path is null, str_replace() can't accept null as the 3rd argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So on line 212, this exits if $path is empty.

@kienstra kienstra marked this pull request as ready for review April 30, 2022 21:30
<directory suffix=".php">./tests/php/Integration/Helpers/</directory>
<directory prefix="Test" suffix=".php">./tests/php/Integration/</directory>
</testsuite>
</testsuites>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just changed the configuration to the new XML configuration, via:

composer test -- --migrate-configuration 

@kienstra
Copy link
Contributor Author

kienstra commented May 6, 2022

@dreamwhisper, thanks so much!

@kienstra kienstra merged commit 7a1035b into develop May 6, 2022
@kienstra kienstra deleted the add/phpunit-8.1 branch May 6, 2022 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants