Fixing namespacing issue causing some tests to be skipped#3037
Closed
Fixing namespacing issue causing some tests to be skipped#3037
Conversation
Contributor
|
@sol-loup has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
9363dc2 to
91d2478
Compare
Contributor
|
@sol-loup has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Contributor
Closed
6 tasks
vinkmeta
pushed a commit
that referenced
this pull request
Apr 13, 2025
Summary:
This PR addresses a PSR-4 autoloading compliance issue that prevented several PHPUnit tests from being discovered and executed. When running PHPUnit, errors like `Class ... located in ... does not comply with psr-4 autoloading standard. Skipping.` were reported for multiple test files.
**Root Cause:**
The issue stemmed from a mismatch between the namespace declarations within the test files and the PSR-4 autoloading configuration defined in `composer.json`. Specifically:
1. The `composer.json` file maps the base namespace `WooCommerce\Facebook\Tests\` to the directory `tests/Unit/`.
```json
"autoload-dev": {
"psr-4": {
"WooCommerce\\Facebook\\Tests\\": "tests/Unit"
}
}
```
2. According to PSR-4, any subsequent parts of a namespace must correspond directly to the subdirectory structure *under* the base path (`tests/Unit/`).
3. Several test files incorrectly included `Unit` as part of their namespace (e.g., `namespace WooCommerce\Facebook\Tests\Unit\Admin\Settings;`) while residing in paths like `tests/Unit/Admin/Settings/`.
4. This caused the autoloader to look for the class file in an incorrect, nested path (e.g., `tests/Unit/Unit/Admin/Settings/ConnectionTest.php`) instead of the actual location (`tests/Unit/Admin/Settings/ConnectionTest.php`), leading to the "does not comply" error.
5. In some cases, minor discrepancies in directory names (e.g., `API\Plugin` in the namespace vs. `Api\REST` in the path) also contributed to the problem.
## How changes were detected and fixed
Thankfully, running `composer dump-autoload -o` was sufficient to uncover all the PSR skipped tests:
Class WooCommerce\Facebook\Tests\Unit\Framework\Utilities\AsyncRequestTest located in ./tests/Unit/Framework/Utilities/AsyncRequestTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\ConnectionTest located in ./tests/Unit/Admin/Settings/ConnectionTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings\ShopsTest located in ./tests/Unit/Admin/Settings/ShopsTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings_Screens\ConnectionTest located in ./tests/Unit/Admin/Settings_Screens/ConnectionTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings_Screens\ShopsTest located in ./tests/Unit/Admin/Settings_Screens/ShopsTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\API\Plugin\RestAPITest located in ./tests/Unit/Api/REST/RestAPITest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Handlers\MetaExtensionTest located in ./tests/Unit/Handlers/MetaExtensionTest.php does not comply with psr-4 autoloading standard. Skipping.
**Changes:**
The `namespace` declarations in the affected test files have been modified to accurately reflect their directory structure relative to the `tests/Unit/` base path defined in `composer.json`. This typically involved removing the redundant `Unit` segment from the namespace or correcting other segments to match the actual folder names (e.g., changing `API\Plugin` to `Api\REST`).
These changes ensure that the class namespaces correctly map to their file locations according to the PSR-4 standard, allowing Composer's autoloader and PHPUnit to find and execute the tests properly.
Pull Request resolved: #3037
Test Plan:
1. Checked out the branch containing these changes.
2. Ran `composer dump-autoload` to ensure the autoloader cache was updated.
3. Executed the PHPUnit test suite using the standard command (`vendor/bin/phpunit` or `composer test-unit`).
4. **Result:** PHPUnit completed its run successfully, executing 286 tests without the previous PSR-4 autoloading errors.
**!---- (auto-generated) DO NOT EDIT OR PUT ANYTHING AFTER THIS LINE ----!**
MFTRunTestsScript Run / Test Suite: sa_checkout / Test Collection: www / Diff Version V3
https://internalfb.com/intern/testinfra/testrun/13229323982953381
MFTRunTestsScript Run / Test Suite: sa_checkout / Test Collection: bloks / Diff Version V3
https://internalfb.com/intern/testinfra/testrun/12103424076120115
Reviewed By: ajello-meta, nealweiMeta
Differential Revision: D72797935
Pulled By: sol-loup
fbshipit-source-id: 9726b427374c91dea93e093382583ff642c7b8f7
This was referenced Apr 14, 2025
Closed
mradmeta
pushed a commit
that referenced
this pull request
Apr 14, 2025
Summary:
This PR addresses a PSR-4 autoloading compliance issue that prevented several PHPUnit tests from being discovered and executed. When running PHPUnit, errors like `Class ... located in ... does not comply with psr-4 autoloading standard. Skipping.` were reported for multiple test files.
**Root Cause:**
The issue stemmed from a mismatch between the namespace declarations within the test files and the PSR-4 autoloading configuration defined in `composer.json`. Specifically:
1. The `composer.json` file maps the base namespace `WooCommerce\Facebook\Tests\` to the directory `tests/Unit/`.
```json
"autoload-dev": {
"psr-4": {
"WooCommerce\\Facebook\\Tests\\": "tests/Unit"
}
}
```
2. According to PSR-4, any subsequent parts of a namespace must correspond directly to the subdirectory structure *under* the base path (`tests/Unit/`).
3. Several test files incorrectly included `Unit` as part of their namespace (e.g., `namespace WooCommerce\Facebook\Tests\Unit\Admin\Settings;`) while residing in paths like `tests/Unit/Admin/Settings/`.
4. This caused the autoloader to look for the class file in an incorrect, nested path (e.g., `tests/Unit/Unit/Admin/Settings/ConnectionTest.php`) instead of the actual location (`tests/Unit/Admin/Settings/ConnectionTest.php`), leading to the "does not comply" error.
5. In some cases, minor discrepancies in directory names (e.g., `API\Plugin` in the namespace vs. `Api\REST` in the path) also contributed to the problem.
## How changes were detected and fixed
Thankfully, running `composer dump-autoload -o` was sufficient to uncover all the PSR skipped tests:
Class WooCommerce\Facebook\Tests\Unit\Framework\Utilities\AsyncRequestTest located in ./tests/Unit/Framework/Utilities/AsyncRequestTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\ConnectionTest located in ./tests/Unit/Admin/Settings/ConnectionTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings\ShopsTest located in ./tests/Unit/Admin/Settings/ShopsTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings_Screens\ConnectionTest located in ./tests/Unit/Admin/Settings_Screens/ConnectionTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings_Screens\ShopsTest located in ./tests/Unit/Admin/Settings_Screens/ShopsTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\API\Plugin\RestAPITest located in ./tests/Unit/Api/REST/RestAPITest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Handlers\MetaExtensionTest located in ./tests/Unit/Handlers/MetaExtensionTest.php does not comply with psr-4 autoloading standard. Skipping.
**Changes:**
The `namespace` declarations in the affected test files have been modified to accurately reflect their directory structure relative to the `tests/Unit/` base path defined in `composer.json`. This typically involved removing the redundant `Unit` segment from the namespace or correcting other segments to match the actual folder names (e.g., changing `API\Plugin` to `Api\REST`).
These changes ensure that the class namespaces correctly map to their file locations according to the PSR-4 standard, allowing Composer's autoloader and PHPUnit to find and execute the tests properly.
Pull Request resolved: #3037
Test Plan:
1. Checked out the branch containing these changes.
2. Ran `composer dump-autoload` to ensure the autoloader cache was updated.
3. Executed the PHPUnit test suite using the standard command (`vendor/bin/phpunit` or `composer test-unit`).
4. **Result:** PHPUnit completed its run successfully, executing 286 tests without the previous PSR-4 autoloading errors.
**!---- (auto-generated) DO NOT EDIT OR PUT ANYTHING AFTER THIS LINE ----!**
MFTRunTestsScript Run / Test Suite: sa_checkout / Test Collection: www / Diff Version V3
https://internalfb.com/intern/testinfra/testrun/13229323982953381
MFTRunTestsScript Run / Test Suite: sa_checkout / Test Collection: bloks / Diff Version V3
https://internalfb.com/intern/testinfra/testrun/12103424076120115
Reviewed By: ajello-meta, nealweiMeta
Differential Revision: D72797935
Pulled By: sol-loup
fbshipit-source-id: 9726b427374c91dea93e093382583ff642c7b8f7
rubycalling
pushed a commit
that referenced
this pull request
Apr 16, 2025
Summary:
This PR addresses a PSR-4 autoloading compliance issue that prevented several PHPUnit tests from being discovered and executed. When running PHPUnit, errors like `Class ... located in ... does not comply with psr-4 autoloading standard. Skipping.` were reported for multiple test files.
**Root Cause:**
The issue stemmed from a mismatch between the namespace declarations within the test files and the PSR-4 autoloading configuration defined in `composer.json`. Specifically:
1. The `composer.json` file maps the base namespace `WooCommerce\Facebook\Tests\` to the directory `tests/Unit/`.
```json
"autoload-dev": {
"psr-4": {
"WooCommerce\\Facebook\\Tests\\": "tests/Unit"
}
}
```
2. According to PSR-4, any subsequent parts of a namespace must correspond directly to the subdirectory structure *under* the base path (`tests/Unit/`).
3. Several test files incorrectly included `Unit` as part of their namespace (e.g., `namespace WooCommerce\Facebook\Tests\Unit\Admin\Settings;`) while residing in paths like `tests/Unit/Admin/Settings/`.
4. This caused the autoloader to look for the class file in an incorrect, nested path (e.g., `tests/Unit/Unit/Admin/Settings/ConnectionTest.php`) instead of the actual location (`tests/Unit/Admin/Settings/ConnectionTest.php`), leading to the "does not comply" error.
5. In some cases, minor discrepancies in directory names (e.g., `API\Plugin` in the namespace vs. `Api\REST` in the path) also contributed to the problem.
## How changes were detected and fixed
Thankfully, running `composer dump-autoload -o` was sufficient to uncover all the PSR skipped tests:
Class WooCommerce\Facebook\Tests\Unit\Framework\Utilities\AsyncRequestTest located in ./tests/Unit/Framework/Utilities/AsyncRequestTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\ConnectionTest located in ./tests/Unit/Admin/Settings/ConnectionTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings\ShopsTest located in ./tests/Unit/Admin/Settings/ShopsTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings_Screens\ConnectionTest located in ./tests/Unit/Admin/Settings_Screens/ConnectionTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings_Screens\ShopsTest located in ./tests/Unit/Admin/Settings_Screens/ShopsTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\API\Plugin\RestAPITest located in ./tests/Unit/Api/REST/RestAPITest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Handlers\MetaExtensionTest located in ./tests/Unit/Handlers/MetaExtensionTest.php does not comply with psr-4 autoloading standard. Skipping.
**Changes:**
The `namespace` declarations in the affected test files have been modified to accurately reflect their directory structure relative to the `tests/Unit/` base path defined in `composer.json`. This typically involved removing the redundant `Unit` segment from the namespace or correcting other segments to match the actual folder names (e.g., changing `API\Plugin` to `Api\REST`).
These changes ensure that the class namespaces correctly map to their file locations according to the PSR-4 standard, allowing Composer's autoloader and PHPUnit to find and execute the tests properly.
Pull Request resolved: #3037
Test Plan:
1. Checked out the branch containing these changes.
2. Ran `composer dump-autoload` to ensure the autoloader cache was updated.
3. Executed the PHPUnit test suite using the standard command (`vendor/bin/phpunit` or `composer test-unit`).
4. **Result:** PHPUnit completed its run successfully, executing 286 tests without the previous PSR-4 autoloading errors.
**!---- (auto-generated) DO NOT EDIT OR PUT ANYTHING AFTER THIS LINE ----!**
MFTRunTestsScript Run / Test Suite: sa_checkout / Test Collection: www / Diff Version V3
https://internalfb.com/intern/testinfra/testrun/13229323982953381
MFTRunTestsScript Run / Test Suite: sa_checkout / Test Collection: bloks / Diff Version V3
https://internalfb.com/intern/testinfra/testrun/12103424076120115
Reviewed By: ajello-meta, nealweiMeta
Differential Revision: D72797935
Pulled By: sol-loup
fbshipit-source-id: 9726b427374c91dea93e093382583ff642c7b8f7
This was referenced Apr 18, 2025
This was referenced May 2, 2025
sharunaanandraj
pushed a commit
that referenced
this pull request
May 14, 2025
Summary:
This PR addresses a PSR-4 autoloading compliance issue that prevented several PHPUnit tests from being discovered and executed. When running PHPUnit, errors like `Class ... located in ... does not comply with psr-4 autoloading standard. Skipping.` were reported for multiple test files.
**Root Cause:**
The issue stemmed from a mismatch between the namespace declarations within the test files and the PSR-4 autoloading configuration defined in `composer.json`. Specifically:
1. The `composer.json` file maps the base namespace `WooCommerce\Facebook\Tests\` to the directory `tests/Unit/`.
```json
"autoload-dev": {
"psr-4": {
"WooCommerce\\Facebook\\Tests\\": "tests/Unit"
}
}
```
2. According to PSR-4, any subsequent parts of a namespace must correspond directly to the subdirectory structure *under* the base path (`tests/Unit/`).
3. Several test files incorrectly included `Unit` as part of their namespace (e.g., `namespace WooCommerce\Facebook\Tests\Unit\Admin\Settings;`) while residing in paths like `tests/Unit/Admin/Settings/`.
4. This caused the autoloader to look for the class file in an incorrect, nested path (e.g., `tests/Unit/Unit/Admin/Settings/ConnectionTest.php`) instead of the actual location (`tests/Unit/Admin/Settings/ConnectionTest.php`), leading to the "does not comply" error.
5. In some cases, minor discrepancies in directory names (e.g., `API\Plugin` in the namespace vs. `Api\REST` in the path) also contributed to the problem.
Thankfully, running `composer dump-autoload -o` was sufficient to uncover all the PSR skipped tests:
Class WooCommerce\Facebook\Tests\Unit\Framework\Utilities\AsyncRequestTest located in ./tests/Unit/Framework/Utilities/AsyncRequestTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\ConnectionTest located in ./tests/Unit/Admin/Settings/ConnectionTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings\ShopsTest located in ./tests/Unit/Admin/Settings/ShopsTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings_Screens\ConnectionTest located in ./tests/Unit/Admin/Settings_Screens/ConnectionTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings_Screens\ShopsTest located in ./tests/Unit/Admin/Settings_Screens/ShopsTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\API\Plugin\RestAPITest located in ./tests/Unit/Api/REST/RestAPITest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Handlers\MetaExtensionTest located in ./tests/Unit/Handlers/MetaExtensionTest.php does not comply with psr-4 autoloading standard. Skipping.
**Changes:**
The `namespace` declarations in the affected test files have been modified to accurately reflect their directory structure relative to the `tests/Unit/` base path defined in `composer.json`. This typically involved removing the redundant `Unit` segment from the namespace or correcting other segments to match the actual folder names (e.g., changing `API\Plugin` to `Api\REST`).
These changes ensure that the class namespaces correctly map to their file locations according to the PSR-4 standard, allowing Composer's autoloader and PHPUnit to find and execute the tests properly.
Pull Request resolved: #3037
Test Plan:
1. Checked out the branch containing these changes.
2. Ran `composer dump-autoload` to ensure the autoloader cache was updated.
3. Executed the PHPUnit test suite using the standard command (`vendor/bin/phpunit` or `composer test-unit`).
4. **Result:** PHPUnit completed its run successfully, executing 286 tests without the previous PSR-4 autoloading errors.
**!---- (auto-generated) DO NOT EDIT OR PUT ANYTHING AFTER THIS LINE ----!**
MFTRunTestsScript Run / Test Suite: sa_checkout / Test Collection: www / Diff Version V3
https://internalfb.com/intern/testinfra/testrun/13229323982953381
MFTRunTestsScript Run / Test Suite: sa_checkout / Test Collection: bloks / Diff Version V3
https://internalfb.com/intern/testinfra/testrun/12103424076120115
Reviewed By: ajello-meta, nealweiMeta
Differential Revision: D72797935
Pulled By: sol-loup
fbshipit-source-id: 9726b427374c91dea93e093382583ff642c7b8f7
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses a PSR-4 autoloading compliance issue that prevented several PHPUnit tests from being discovered and executed. When running PHPUnit, errors like
Class ... located in ... does not comply with psr-4 autoloading standard. Skipping.were reported for multiple test files.Root Cause:
The issue stemmed from a mismatch between the namespace declarations within the test files and the PSR-4 autoloading configuration defined in
composer.json. Specifically:composer.jsonfile maps the base namespaceWooCommerce\Facebook\Tests\to the directorytests/Unit/.tests/Unit/).Unitas part of their namespace (e.g.,namespace WooCommerce\Facebook\Tests\Unit\Admin\Settings;) while residing in paths liketests/Unit/Admin/Settings/.tests/Unit/Unit/Admin/Settings/ConnectionTest.php) instead of the actual location (tests/Unit/Admin/Settings/ConnectionTest.php), leading to the "does not comply" error.API\Pluginin the namespace vs.Api\RESTin the path) also contributed to the problem.How changes were detected and fixed
Thankfully, running
composer dump-autoload -owas sufficient to uncover all the PSR skipped tests:Class WooCommerce\Facebook\Tests\Unit\Framework\Utilities\AsyncRequestTest located in ./tests/Unit/Framework/Utilities/AsyncRequestTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\ConnectionTest located in ./tests/Unit/Admin/Settings/ConnectionTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings\ShopsTest located in ./tests/Unit/Admin/Settings/ShopsTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings_Screens\ConnectionTest located in ./tests/Unit/Admin/Settings_Screens/ConnectionTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Admin\Settings_Screens\ShopsTest located in ./tests/Unit/Admin/Settings_Screens/ShopsTest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\API\Plugin\RestAPITest located in ./tests/Unit/Api/REST/RestAPITest.php does not comply with psr-4 autoloading standard. Skipping.
Class WooCommerce\Facebook\Tests\Unit\Handlers\MetaExtensionTest located in ./tests/Unit/Handlers/MetaExtensionTest.php does not comply with psr-4 autoloading standard. Skipping.
Changes:
The
namespacedeclarations in the affected test files have been modified to accurately reflect their directory structure relative to thetests/Unit/base path defined incomposer.json. This typically involved removing the redundantUnitsegment from the namespace or correcting other segments to match the actual folder names (e.g., changingAPI\PlugintoApi\REST).These changes ensure that the class namespaces correctly map to their file locations according to the PSR-4 standard, allowing Composer's autoloader and PHPUnit to find and execute the tests properly.
Test Plan
composer dump-autoloadto ensure the autoloader cache was updated.vendor/bin/phpunitorcomposer test-unit).