wp-browser: [BUG] Running tests in a separate process and with preservedGlobalState fails
Environment OS: MacOS PHP version: 7.3 Installed Codeception version: 4.1.5 Installed wp-browser version: 2.5.5 WordPress version: 5.4.1 Local development environment: VVV WordPress structure and management: default
Can you perform the test manually?
Testing REST response through Insomnia works.
Codeception configuration file
Paste, in a fenced YAML block, the content of your Codeception configuration file; remove any sensitive data!
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
commands:
- Codeception\Command\GenerateWPUnit
- Codeception\Command\GenerateWPRestApi
- Codeception\Command\GenerateWPRestController
- Codeception\Command\GenerateWPRestPostTypeController
- Codeception\Command\GenerateWPAjax
- Codeception\Command\GenerateWPCanonical
- Codeception\Command\GenerateWPXMLRPC
params:
- .env.testing
coverage:
enabled: true
include:
- src/*
exclude:
- src/Core/CompiledContainer.php
low_limit: 30
high_limit: 75
settings:
colors: true
memory_limit: 1024M
Suite configuration file Paste, in a fenced YAML block, the content of the suite configuration file; remove any sensitive data!
# Codeception Test Suite Configuration
#
# Suite for unit or integration tests that require WordPress functions and classes.
actor: IntegrationTester
modules:
enabled:
- WPLoader
- \Helper\Integration
config:
WPLoader:
wpRootFolder: "%WP_ROOT_FOLDER%"
dbName: "%TEST_DB_NAME%"
dbHost: "%TEST_DB_HOST%"
dbUser: "%TEST_DB_USER%"
dbPassword: "%TEST_DB_PASSWORD%"
tablePrefix: "%TEST_TABLE_PREFIX%"
domain: "%TEST_SITE_WP_DOMAIN%"
adminEmail: "%TEST_SITE_ADMIN_EMAIL%"
title: "Test"
plugins: ['advanced-custom-fields-pro/acf.php', 'classic-editor/classic-editor.php', 'members/members.php', 'my-plugin/my-plugin.php']
activatePlugins: ['advanced-custom-fields-pro/acf.php', 'classic-editor/classic-editor.php', 'members/members.php', 'my-plugin/my-plugin.php']
Describe the bug When running a test that has a
/**
* Test successful login request
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
I get this error:
1) LoginEndpointTest: Request was successful
Test tests/Integration/Endpoints/LoginEndpointTest.php:testRequestWasSuccessful
[PHPUnit\Framework\Exception] PHP Fatal error: Uncaught Error: Class 'Codeception\TestCase\WPTestCase' not found in /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/tests/Integration/Endpoints/LoginEndpointTest.php:16
Stack trace:
#0 Standard input code(31): require_once()
#1 Standard input code(111): __phpunit_run_isolated_test()
#2 {main}
thrown in /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/tests/Integration/Endpoints/LoginEndpointTest.php on line 16
Fatal error: Uncaught Error: Class 'Codeception\TestCase\WPTestCase' not found in /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/tests/Integration/Endpoints/LoginEndpointTest.php:16
Stack trace:
#0 Standard input code(31): require_once()
#1 Standard input code(111): __phpunit_run_isolated_test()
#2 {main}
thrown in /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/tests/Integration/Endpoints/LoginEndpointTest.php on line 16
To Reproduce
Add the docblocks with annotations before running tests.
Expected behavior
The test should be able to run in a separate process.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 21 (11 by maintainers)
That is great to know!
I will write some more documentation and merge the PR.
Thanks again for your testing and collaboration.
Getting there, I’ve made one more push to the branch.
Thanks again for your feedback and collaboration.
It seems the plugins are not being loaded correctly, then.
I will look into this and push an update.
Thanks for getting back to me and confirming this.
In my opinion too, while I really love using Docker for my own setup, it’s a bit overkill.
I’ve poked at the issue a bit and will come back, in the next days, with some test code; would you be willing to test it out in a branch?
None that I could immediately think of. I guess you’re trying to run integration-level tests and WordPress love for side-effects (globals, constants, and such) is getting in the way. I will have to play with this a bit and will come back with a response. I will probably not be able to “beat the system” (Codeception idea of isolation is to use containers), but I will learn something I will share.