Skip to content

Fixing namespacing issue causing some tests to be skipped#3037

Closed
sol-loup wants to merge 2 commits intomainfrom
fix-abstractunit-tests
Closed

Fixing namespacing issue causing some tests to be skipped#3037
sol-loup wants to merge 2 commits intomainfrom
fix-abstractunit-tests

Conversation

@sol-loup
Copy link
Copy Markdown
Contributor

@sol-loup sol-loup commented Apr 10, 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/.
      "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.

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.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@sol-loup has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@sol-loup sol-loup force-pushed the fix-abstractunit-tests branch from 9363dc2 to 91d2478 Compare April 10, 2025 16:15
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@sol-loup has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@sol-loup merged this pull request in 30b28f4.

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
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
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
@tzahgr tzahgr mentioned this pull request May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants