Skip to content

Refactor test namespaces.#1789

Merged
aaronweeden merged 6 commits intoubccr:xdmod11.0from
aaronweeden:refactor-test-namespaces
Dec 5, 2023
Merged

Refactor test namespaces.#1789
aaronweeden merged 6 commits intoubccr:xdmod11.0from
aaronweeden:refactor-test-namespaces

Conversation

@aaronweeden
Copy link
Copy Markdown
Contributor

@aaronweeden aaronweeden commented Oct 17, 2023

Description

This PR makes the unit, component, integration, and regression tests consistently follow the PSR-4-autoloader standard whereby each namespace prefix ({Unit|Component|Integration|Regression}Tests) corresponds to a base directory (tests/{unit|component|integration|regression}/lib), and the sub-namespaces correspond to subdirectories, with namespace separators corresponding to directory separators. For example, the class in integration/lib/TestHarness/XdmodTestHelper.php should have the namespace IntegrationTests\TestHarness.

This PR also makes the tests/{unit,component,integration,regression}/bootstrap.php files:

  • Use / instead of DIRECTORY_SEPARATOR instead of inconsistently using one or the other.
  • Be consistent with each other in how they strip out the namespace prefixes from classes before loading them.
  • For unit, component, and regression: be consistent with each other in how they check the tests/integration/lib directory if a class wasn't found in their own lib directory.

This PR also removes @package and @subpackage comments, since these are used inconsistently.

This PR also adds use statements in a few cases rather than invoking classes via their fully qualified names.

There are also PRs for ubccr/xdmod-supremm#355 and ubccr/xdmod-appkernels#98.

Motivation and Context

The goal is to make the code cleaner and more consistent.

Tests performed

To make sure the namespaces are consistent with their directory paths, I ran this and confirmed it produced no output:

cd tests;
for test_type in {unit,component,integration,regression}; do \
    for file in $(find $test_type/lib -type f); do \
        prefix="$(tr '[:lower:]' '[:upper:]' <<< ${test_type:0:1})${test_type:1}Tests"; \
        expected_namespace="namespace $(dirname $file | sed "s/$test_type\/lib/$prefix/" | sed 's/\//\\/g');"; \
        actual_namespace="$(grep namespace $file)"; \
        if [[ "$expected_namespace" != "$actual_namespace" ]]; then \
            echo -e "$file"; \
            echo -e "\t$expected_namespace"; \
            echo -e "\t$actual_namespace"; \
        fi; \
    done; \
done; \
cd ..

To make sure the changes in this PR don't affect the tests that are run, I did the following in a Docker container running tools-ext-01.ccr.xdmod.org/xdmod-10.5.0-x86_64:rockylinux8.5-0.3:

  1. Run the following commands:
    export COMPOSER_ALLOW_SUPERUSER=1
    export XDMOD_REALMS='jobs,storage,cloud'
    export XDMOD_IS_CORE=yes
    export XDMOD_INSTALL_DIR=/xdmod
    export XDMOD_TEST_MODE=upgrade
    openssl genrsa -rand /proc/cpuinfo:/proc/dma:/proc/filesystems:/proc/interrupts:/proc/ioports:/proc/uptime 2048 > /etc/pki/tls/private/localhost.key
    /usr/bin/openssl req -new -key /etc/pki/tls/private/localhost.key -x509 -sha256 -days 365 -set_serial $RANDOM -extensions v3_req -out /etc/pki/tls/certs/localhost.crt -subj "/C=XX/L=Default City/O=Default Company Ltd"
    git clone {https://github.com/ubccr,}/xdmod
    cd /xdmod
    composer install
    mkdir ~/phpunit
    mkdir /tmp/screenshots
    ~/bin/buildrpm xdmod
    ./tests/ci/bootstrap.sh
    ./tests/ci/validate.sh
    composer install --no-progress
    mv ./configuration/organization.json ./configuration/organization.json.old
    mv ./configuration/portal_settings.ini ./configuration/portal_settings.ini.old
    cp /etc/xdmod/portal_settings.ini ./configuration/portal_settings.ini
    cp /etc/xdmod/organization.json ./configuration/organization.json
    composer self-update --1
    ./tests/ci/scripts/qa-test-setup.sh
    sed -i 's/\$phpunit /$phpunit --debug /' /xdmod/tests/unit/runtests.sh
    /xdmod/tests/unit/runtests.sh > /unit-before.txt
    sed -i 's/\$phpunit /$phpunit --debug /' /xdmod/tests/component/runtests.sh
    /xdmod/tests/component/runtests.sh > /component-before.txt
    sed -i 's/\$phpunit /$phpunit --debug /' /xdmod/tests/regression/runtests.sh
    /xdmod/tests/regression/runtests.sh > /regression-before.txt
    cd /xdmod/tests/integration
    ../../vendor/bin/phpunit --testsuite default --group UserAdminTest.createUsers --debug > /integration-before.txt
    ../../vendor/bin/phpunit --testsuite default --exclude-group UserAdminTest.createUsers --debug >> /integration-before.txt
    git clone https://github.com/aaronweeden/xdmod -b refactor-test-namespaces /xdmod-new
    unalias rm
    rm -r /xdmod/tests
    cp -r /xdmod{-new,}/tests
    sleep 1 # so the last modified time doesn't confuse DirectoryScannerTest::testLastModifiedFilters
    sed -i 's/\$phpunit /$phpunit --debug /' /xdmod/tests/unit/runtests.sh
    /xdmod/tests/unit/runtests.sh > /unit-after.txt
    sed -i 's/\$phpunit /$phpunit --debug /' /xdmod/tests/component/runtests.sh
    /xdmod/tests/component/runtests.sh > /component-after.txt
    sed -i 's/\$phpunit /$phpunit --debug /' /xdmod/tests/regression/runtests.sh
    /xdmod/tests/regression/runtests.sh > /regression-after.txt
    cd /xdmod/tests/integration
    ../../vendor/bin/phpunit --testsuite default --group UserAdminTest.createUsers --debug > /integration-after.txt
    ../../vendor/bin/phpunit --testsuite default --exclude-group UserAdminTest.createUsers --debug >> /integration-after.txt
    unalias mv
    for file in /regression-{before,after}.txt; do
        for test in {testChartSettings,testChartFilters,testCsvExport}; do
            for realm in {Jobs,Cloud,Storage}; do
                sed -i "s/$test with data set.*$realm.*/$test $realm/" $file;
            done;
        done;
        sort $file > $file.tmp;
        mv $file.tmp $file;
    done
    
  2. Compare /unit-{before,after}.txt and make sure the only differences are namespace names, user hashes, and amount of time the tests ran.
  3. Compare /component-{before,after}.txt and make sure the only differences are namespace names, test name hashes, and amount of time the tests ran.
  4. Compare /regression-{before,after}.txt and make sure the only differences are namespace names and amount of time the tests ran.
  5. Compare /integration-{before,after}.txt and make sure the only differences are namespace names, random values for ControllerTest::testEnumTargetAddresses, and amount of time the tests ran.

Checklist:

  • The pull request description is suitable for a Changelog entry
  • The milestone is set correctly on the pull request
  • The appropriate labels have been added to the pull request

@aaronweeden aaronweeden force-pushed the refactor-test-namespaces branch 8 times, most recently from 66e7ffd to 6fd09bf Compare October 18, 2023 01:05
@aaronweeden aaronweeden mentioned this pull request Oct 18, 2023
3 tasks
@aaronweeden aaronweeden force-pushed the refactor-test-namespaces branch 2 times, most recently from 0a0a517 to 2b6420b Compare October 20, 2023 16:31
@aaronweeden aaronweeden added this to the 11.0.0 milestone Oct 20, 2023
@aaronweeden aaronweeden added qa / testing Updates/additions to tests maintenance / code quality Improvements and code cleanup. Not a new feature or enhancement to existing functionality. labels Oct 20, 2023
@aaronweeden aaronweeden marked this pull request as ready for review October 20, 2023 17:35
eiffel777
eiffel777 previously approved these changes Nov 28, 2023
eiffel777
eiffel777 previously approved these changes Dec 5, 2023
@aaronweeden aaronweeden force-pushed the refactor-test-namespaces branch from 50046e7 to e4e3ea3 Compare December 5, 2023 16:01
@aaronweeden aaronweeden force-pushed the refactor-test-namespaces branch from e4e3ea3 to 9638748 Compare December 5, 2023 17:20
@aaronweeden aaronweeden force-pushed the refactor-test-namespaces branch from 9638748 to 2ccff49 Compare December 5, 2023 17:28
@aaronweeden aaronweeden merged commit 1f432c1 into ubccr:xdmod11.0 Dec 5, 2023
@aaronweeden aaronweeden deleted the refactor-test-namespaces branch December 5, 2023 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance / code quality Improvements and code cleanup. Not a new feature or enhancement to existing functionality. qa / testing Updates/additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants