#64963 closed defect (bug) (fixed)
Unit tests make unconditional HTTP request for GP_Locales class PHP file
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.1 | Priority: | normal |
| Severity: | normal | Version: | 4.9 |
| Component: | Build/Test Tools | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
I noticed that running PHPUnit can be quite slow on a poor connection, even though I'm not doing any external-http tests. I threw in a debug_print_backtrace() to WP_Http::request() and I found that after these lines are printed:
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.
An HTTP request is made from the PluralFormsTest::data_locales() data provider:
#0 /var/www/src/wp-includes/class-wp-http.php(659): WP_Http->request()
#1 /var/www/src/wp-includes/http.php(84): WP_Http->get()
#2 /var/www/src/wp-admin/includes/file.php(1166): wp_safe_remote_get()
#3 /var/www/tests/phpunit/tests/pomo/pluralForms.php(75): download_url()
#4 [internal function]: PluralFormsTest::data_locales()
#5 /var/www/vendor/phpunit/phpunit/src/Util/Annotation/DocBlock.php(421): ReflectionMethod->invoke()
#6 /var/www/vendor/phpunit/phpunit/src/Util/Annotation/DocBlock.php(278): PHPUnit\Util\Annotation\DocBlock->getDataFromDataProviderAnnotation()
#7 /var/www/vendor/phpunit/phpunit/src/Util/Test.php(329): PHPUnit\Util\Annotation\DocBlock->getProvidedData()
#8 /var/www/vendor/phpunit/phpunit/src/Framework/TestBuilder.php(72): PHPUnit\Util\Test::getProvidedData()
#9 /var/www/vendor/phpunit/phpunit/src/Framework/TestSuite.php(891): PHPUnit\Framework\TestBuilder->build()
#10 /var/www/vendor/phpunit/phpunit/src/Framework/TestSuite.php(232): PHPUnit\Framework\TestSuite->addTestMethod()
#11 /var/www/vendor/phpunit/phpunit/src/Framework/TestSuite.php(362): PHPUnit\Framework\TestSuite->__construct()
#12 /var/www/vendor/phpunit/phpunit/src/Framework/TestSuite.php(512): PHPUnit\Framework\TestSuite->addTestSuite()
#13 /var/www/vendor/phpunit/phpunit/src/Framework/TestSuite.php(537): PHPUnit\Framework\TestSuite->addTestFile()
#14 /var/www/vendor/phpunit/phpunit/src/TextUI/TestSuiteMapper.php(67): PHPUnit\Framework\TestSuite->addTestFiles()
#15 /var/www/vendor/phpunit/phpunit/src/TextUI/Command.php(391): PHPUnit\TextUI\TestSuiteMapper->map()
#16 /var/www/vendor/phpunit/phpunit/src/TextUI/Command.php(114): PHPUnit\TextUI\Command->handleArguments()
#17 /var/www/vendor/phpunit/phpunit/src/TextUI/Command.php(99): PHPUnit\TextUI\Command->run()
#18 /var/www/vendor/phpunit/phpunit/phpunit(107): PHPUnit\TextUI\Command::main()
#19 /var/www/vendor/bin/phpunit(122): include('/var/www/vendor...')
This is in spite of me running npm run test:php -- --group=64890 to limit execution to a specific group without any external-http requests. It seems the PluralFormsTest::test_regression() test needs to be refactored to not use PluralFormsTest::data_locales() as a data provider, since apparently PHPUnit has a test collector which runs all data providers unconditionally when initializing.
Attachments (1)
Change History (8)
This ticket was mentioned in PR #11382 on WordPress/wordpress-develop by @westonruter.
3 months ago
#2
- Keywords has-unit-tests added
This ticket was mentioned in Slack in #core by westonruter. View the logs.
3 months ago
@westonruter commented on PR #11382:
3 months ago
#5
Fixed in r62174 (9cee59516df60b1b51ff163763082a0464617995)
Trac ticket: https://core.trac.wordpress.org/ticket/64963
## Use of AI Tools
None