Automattic / babble

Multilingual WordPress done right.
https://wordpress.org/plugins/babble/
246 stars 50 forks source link

Babble's PHPUnit testcase is triggering a fatal error #332

Closed simonwheatley closed 9 years ago

simonwheatley commented 9 years ago

Running the PHPUnit tests currently results in a fatal error, due to is_post_type_viewable() being called at a point when it is not defined.

Below is the output when I run PHPUnit.

$ ./vendor/bin/phpunit 
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 4.8.6 by Sebastian Bergmann and contributors.

Fatal error: Call to undefined function is_post_type_viewable() in /srv/www/wordpress-develop/tests/phpunit/includes/utils.php on line 365

Call Stack:
    0.0025     228016   1. {main}() /srv/www/babble/htdocs/wp-content/plugins/babble/vendor/phpunit/phpunit/phpunit:0
    0.1145    1382280   2. PHPUnit_TextUI_Command::main(???) /srv/www/babble/htdocs/wp-content/plugins/babble/vendor/phpunit/phpunit/phpunit:47
    0.1145    1382904   3. PHPUnit_TextUI_Command->run(array(1), bool) /srv/www/babble/htdocs/wp-content/plugins/babble/vendor/phpunit/phpunit/src/TextUI/Command.php:100
   10.0610   31814408   4. PHPUnit_TextUI_TestRunner->doRun(class PHPUnit_Framework_TestSuite, array(5)) /srv/www/babble/htdocs/wp-content/plugins/babble/vendor/phpunit/phpunit/src/TextUI/Command.php:148
   10.0856   32007936   5. PHPUnit_Framework_TestSuite->run(class PHPUnit_Framework_TestResult) /srv/www/babble/htdocs/wp-content/plugins/babble/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:432
   10.0903   32023928   6. PHPUnit_Framework_TestSuite->run(class PHPUnit_Framework_TestResult) /srv/www/babble/htdocs/wp-content/plugins/babble/vendor/phpunit/phpunit/src/Framework/TestSuite.php:735
   10.0937   32028240   7. PHPUnit_Framework_TestCase->run(class PHPUnit_Framework_TestResult) /srv/www/babble/htdocs/wp-content/plugins/babble/vendor/phpunit/phpunit/src/Framework/TestSuite.php:735
   10.0938   32029880   8. PHPUnit_Framework_TestResult->run(class Test_Cookies) /srv/www/babble/htdocs/wp-content/plugins/babble/vendor/phpunit/phpunit/src/Framework/TestCase.php:702
   10.1216   32081832   9. PHPUnit_Framework_TestCase->runBare() /srv/www/babble/htdocs/wp-content/plugins/babble/vendor/phpunit/phpunit/src/Framework/TestResult.php:601
   10.1872   32612792  10. Babble_UnitTestCase->tearDown() /srv/www/babble/htdocs/wp-content/plugins/babble/vendor/phpunit/phpunit/src/Framework/TestCase.php:783
   10.1897   32560704  11. Babble_UnitTestCase->go_to(string(22)) /srv/www/babble/htdocs/wp-content/plugins/babble/tests/babble-testcase.php:30
   10.1897   32560840  12. WP_UnitTestCase->go_to(string(22)) /srv/www/babble/htdocs/wp-content/plugins/babble/tests/babble-testcase.php:44
   10.1898   32520536  13. _cleanup_query_vars() /srv/www/wordpress-develop/tests/phpunit/includes/testcase.php:359
simonwheatley commented 9 years ago

Hmmm, the function being called is in trunk and intended to be in 4.4.0… but we're running these tests on other WordPress versions, hence the breakage.

/**
 * Determines whether a post type is considered "viewable".
 *
 * For built-in post types such as posts and pages, the 'public' value will be evaluated.
 * For all others, the 'publicly_queryable' value will be used.
 *
 * @since 4.4.0
 *
 * @param object $post_type_object Post type object.
 * @return bool Whether the post type should be considered viewable.
 */
function is_post_type_viewable( $post_type_object ) {
    return $post_type_object->publicly_queryable || ( $post_type_object->_builtin && $post_type_object->public );
}
simonwheatley commented 9 years ago

Core ticket: https://core.trac.wordpress.org/ticket/33888

jarednova commented 9 years ago

@simonwheatley I'm getting the same thing on a diff't project. For me it seems to be triggered by WP_UnitTestCase::go_to('/')

DevinWalker commented 9 years ago

Hey guys, see here for the solution: https://wordpress.slack.com/archives/core/p1442426444002024

Basically, adding a shim like so will resolve the issue: https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/master/tests/helpers/shims.php

simonwheatley commented 9 years ago

@devinwalker Hah! Snap: https://github.com/Automattic/babble/blob/fix/330-richaber-adds-tests/tests/babble-compat.php

Thanks! :smiley:

DevinWalker commented 9 years ago

Well looky there!

simonwheatley commented 9 years ago

Fixed by #333