-
Notifications
You must be signed in to change notification settings - Fork 5
[Dont Merge Yet] Fix PHP unit errors with wp-env phpunit container removal #182
Conversation
@@ -54,11 +72,23 @@ public function test_register_pattern_post_type_meta_types() { | |||
public function test_register_pattern_post_type_meta_defaults() { | |||
register_pattern_post_type(); | |||
|
|||
foreach ( array_diff( get_pattern_defaults(), [ 'title' => null ] ) as $meta_key => $default_value ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I had to change this was because it was failing with the error Fatal error: Array to string conversion
. This is apparently the error message if you use array_diff
with a multi-dimentional array. See:
https://stackoverflow.com/questions/19830585/array-to-string-conversion-error-when-calling-array-diff-assoc-with-a-multid
I broke it out to be a bit easier for me to understand as well. I had a hard time fully understanding what was happening without breaking it out a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience with this.
My obsession with terse code gave you some nasty debugging.
Before merging, remove the branch in package.json referring to this PR in wpps-scripts: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @johnstonphilip,
Thanks a lot for figuring this out!
Tasks
Summary of changes
In the wp-env project (inside Gutenberg repo), the PHPUnit and Composer packages were removed.
This resulted in PHPunit tests failing to run using wpp-scripts with the message:
The 'phpunit' container has been removed. Please use 'wp-env run tests-cli --env-cwd=wp-content/path/to/plugin phpunit' instead.
In fixing it, I was getting this error:
PHP Fatal error: Declaration of PatternManager\PatternDataHandlers\PatternDataHandlersTest::setUp() must be compatible with Yoast\PHPUnitPolyfills\TestCases\TestCase::setUp(): void in /var/www/html/wp-content/plugins/pattern-manager/wp-modules/pattern-data-handlers/tests/PatternDataHandlersTest.php on line 23
The fix is to make sure that setUp and tearDown declarations have a void declared for their return type.
I was also seeing errors for
Array to string conversion
ontest_register_pattern_post_type_meta_types
. This is apparently the error message you get if you usearray_diff
but one of them is multi-dimentional.How to test
npm run test:phpunit