bobbingwide / oik-batch

Batch interface to WordPress
https://www.oik-plugins.com/oik-plugins/oik-batch
GNU General Public License v2.0
0 stars 0 forks source link

Investigate notices produced when Gutenberg 8.3.0 is activated #41

Open bobbingwide opened 4 years ago

bobbingwide commented 4 years ago

For some time now I've been ignoring a load of notices issued while running oik-batch. Now they've prevented my PhpUnit tests for oik from running.

Raising here since I've got to pick somewhere. Extract from output from PhpUnit for oik,

C:\apache\htdocs\wordpress\wp-content\plugins\oik>pu
c:\apache\htdocs\phpLibraries\phpunit\phpunit-8.4.1.phar
#!/usr/bin/env php
Searching for wp-config.php in directories leading to: C:\apache\htdocs\wordpress\wp-content\plugins\oik
Found wp-config.php in: C:\apache\htdocs\wordpress/
oik-wp running WordPress 5.4.1
C:\apache\htdocs\wordpress\wp-content\plugins\oik
cli
Using wordpress-develop-tests plugin
PHPUnit 8.4.1 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.3.8
Configuration: C:\apache\htdocs\wordpress\wp-content\plugins\oik\phpunit.xml.dist

...........................................................R
Notice: Trying to get property 'ID' of non-object in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat.php on line 262

Notice: Trying to get property 'post_type' of non-object in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat.php on line 270
...  63 / 454 ( 13%)
...........................................................R
Notice: Trying to get property 'ID' of non-object in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat.php on line 262

Notice: Trying to get property 'post_type' of non-object in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat.php on line 270
R
Notice: Trying to get property 'ID' of non-object in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat.php on line 262

Notice: Trying to get property 'post_type' of non-object in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat.php on line 270
.. 126 / 454 ( 27%)
........................F

Time: 7.56 seconds, Memory: 72.00 MB

There was 1 failure:
bobbingwide commented 4 years ago

Investigation

Gutenberg assumes that global $post is set. When run in PhpUnit tests and other batch routines this is not necessarily the case.

Backtrace from PhpUnit for oik

C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\includes\bwtrace-actions.php(279:2) bw_trace_error_handler(1) 784 8 2020-06-23T09:42:44+00:00 2.346656 0.000754 cf=the_content,pre_render_block 35690 326 0 73400320/73400320 256M F=1423 err Array ( [0] => 8 [1] => Notice: Trying to get property 'ID' of non-object [2] => C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat.php [3] => 262 )

  1. bw_lazy_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\libs\bwtrace.php:108 0
  2. bw_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\includes\bwtrace-actions.php:286 0
  3. bw_trace_error_handler(8,Trying to get property 'ID' of non-object,C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat.php,262,array) C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat.php:262 5
  4. gutenberg_render_block_with_assigned_block_context(unsupported,array) C:\apache\htdocs\wordpress\wp-includes\class-wp-hook.php:287 2
  5. apply_filters(unsupported,array) C:\apache\htdocs\wordpress\wp-includes\plugin.php:206 2
  6. apply_filters(pre_render_block,unsupported,array) C:\apache\htdocs\wordpress\wp-includes\blocks.php:455 3
  7. render_block(array) C:\apache\htdocs\wordpress\wp-includes\blocks.php:537 1
  8. do_blocks([bw_twitter theme=gener alt=0]) C:\apache\htdocs\wordpress\wp-includes\class-wp-hook.php:287 1
  9. apply_filters([bw_twitter theme=gener alt=0],array) C:\apache\htdocs\wordpress\wp-includes\plugin.php:206 2
  10. apply_filters(the_content,[bw_twitter theme=gener alt=0]) C:\apache\htdocs\wordpress\wp-content\plugins\oik\libs\oik-sc-help.php:631 2
  11. bw_expand_shortcode([bw_twitter theme=gener alt=0]) C:\apache\htdocs\wordpress\wp-content\plugins\oik\libs\oik-sc-help.php:238 1
  12. _sc__snippet(bw_twitter,theme=gener alt=0) C:\apache\htdocs\wordpress\wp-content\plugins\oik\tests\test-oik-sc-help.php:77 2
  13. test_sc__snippet phar://C:/apache/htdocs/phpLibraries/phpunit/phpunit-8.4.1.phar/phpunit/Framework/TestCase.php:1144 0
  14. runTest phar://C:/apache/htdocs/phpLibraries/phpunit/phpunit-8.4.1.phar/phpunit/Framework/TestCase.php:820 0
  15. runBare phar://C:/apache/htdocs/phpLibraries/phpunit/phpunit-8.4.1.phar/phpunit/Framework/TestResult.php:565 0
  16. run(object) phar://C:/apache/htdocs/phpLibraries/phpunit/phpunit-8.4.1.phar/phpunit/Framework/TestCase.php:597 1
  17. run(object) phar://C:/apache/htdocs/phpLibraries/phpunit/phpunit-8.4.1.phar/phpunit/Framework/TestSuite.php:432 1
  18. run(object) phar://C:/apache/htdocs/phpLibraries/phpunit/phpunit-8.4.1.phar/phpunit/Framework/TestSuite.php:432 1
  19. run(object) phar://C:/apache/htdocs/phpLibraries/phpunit/phpunit-8.4.1.phar/phpunit/Framework/TestSuite.php:432 1
  20. run(object) phar://C:/apache/htdocs/phpLibraries/phpunit/phpunit-8.4.1.phar/phpunit/TextUI/TestRunner.php:425 1
  21. doRun(object,array,1) phar://C:/apache/htdocs/phpLibraries/phpunit/phpunit-8.4.1.phar/phpunit/TextUI/Command.php:94 3
  22. run(array,1) phar://C:/apache/htdocs/phpLibraries/phpunit/phpunit-8.4.1.phar/phpunit/TextUI/Command.php:66 2
  23. main C:\apache\htdocs\wordpress\wp-content\plugins\oik-batch\oik-phpunit.php:75 0
  24. oik_phpunit_run_phpunit C:\apache\htdocs\wordpress\wp-content\plugins\oik-batch\oik-phpunit.php:30 0
  25. oik_phpunit_loaded C:\apache\htdocs\wordpress\wp-content\plugins\oik-batch\oik-phpunit.php:81 0

Workaround

Change gutenberg_render_block_with_assigned_block_context() to set only set values of $context which are available.

$context = [];
if ( $post ) {
        $context['postId'] = $post->ID;
        /*
         * The `postType` context is largely unnecessary server-side, since the
         * ID is usually sufficient on its own. That being said, since a block's
         * manifest is expected to be shared between the server and the client,
         * it should be included to consistently fulfill the expectation.
         */
        $context['postType'] = $post->post_type;
}
$context['query'] = array('categoryIds' => array());