Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: phpunit migrate configuration #6053

Merged
merged 2 commits into from
Apr 10, 2023

Conversation

vishwarajanand
Copy link
Contributor

@vishwarajanand vishwarajanand commented Apr 10, 2023

PhpUnit throws the following error / suggestion, hence upgrading all it's configs by using --migrate-configuration:

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

Here's the script to do this migration:

Bash script to migrate PhpUnit configs
#!/bin/bash
# Copyright 2023 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# first argument can be a directory
DIRS=$(find * -maxdepth 1 -type d -name '[A-Z]*' -not -path '*/vendor/*')
if [ "$#" -eq 1 ]; then
    DIRS=$1
elif [ "$#" -ne 1 ]; then
    echo "Running for all Product directories"
fi

FAILED_FILE=$(mktemp -d)/failed
for DIR in ${DIRS}; do {
    echo "Running $DIR composer update"
    # Update composer to use local packages
    for i in bigquery,BigQuery core,Core logging,Logging, pubsub,PubSub storage,Storage; do
        IFS=","; set -- $i;
        if grep -q "\"google/cloud-$1\":" ${DIR}/composer.json; then
            composer config repositories.$1 "{\"type\": \"path\", \"url\": \"../$2\", \"options\":{\"versions\":{\"google/cloud-$1\":\"1.100\"}}}" -d ${DIR}
        fi
    done
    composer -q --no-interaction --no-ansi --no-progress update -d ${DIR};
    if [ $? != 0 ]; then
        echo "$DIR: composer install failed" >> "${FAILED_FILE}"
        continue
    fi

    PHPUNIT_CONFIG_FILES=$(find "$DIR" -maxdepth 1 -type f -name 'phpunit*xml.dist' -not -path '*/vendor/*')
    IFS=$'\n'
    for PHPUNIT_CONFIG_FILE in ${PHPUNIT_CONFIG_FILES}; do {
        echo "Running $PHPUNIT_CONFIG_FILE migration"
        ${DIR}/vendor/bin/phpunit -c ${PHPUNIT_CONFIG_FILE} --migrate-configuration;
        if [ $? != 0 ]; then
            echo "$PHPUNIT_CONFIG_FILE: migration failed" >> "${FAILED_FILE}"
        fi
    }; done
}; done
echo "Migration complete"
echo "Deleting backup files"
PHPUNIT_CONFIG_BACKUP_FILES=$(find . -maxdepth 4 -type f -name 'phpunit*xml.dist.bak' -not -path '*/vendor/*')
for PHPUNIT_CONFIG_BACKUP_FILE in ${PHPUNIT_CONFIG_BACKUP_FILES}; do {
        echo "Deleting $PHPUNIT_CONFIG_BACKUP_FILE after migration"
        rm $PHPUNIT_CONFIG_BACKUP_FILE;
        if [ $? != 0 ]; then
            echo "$PHPUNIT_CONFIG_BACKUP_FILE: deletion failed" >> "${FAILED_FILE}"
        fi
    }; done
echo "Deletion completed"

if [ -f "${FAILED_FILE}" ]; then
    echo "--------- Failed tests --------------"
    cat "${FAILED_FILE}"
    echo "-------------------------------------"
fi
# add all changed phpunit configs to staged
git add .
# removes composer.json
find . -maxdepth 4 -type f -name "composer.json" -not -path '*/vendor/*' | xargs git reset

Note:

  1. This PR covers all types of phpunit configs:
  • phpunit-conformance.xml.dist
  • phpunit-docfx.xml.dist
  • phpunit-perf.xml.dist
  • phpunit-snippets.xml.dist
  • phpunit-system.xml.dist
  • phpunit.xml.dist
  1. Certain phpunit configs (ex: root /phpunit.dist.xml or /dev/phpunit.dist.xml) didn't need any upgrade, so those are not changed.

@vishwarajanand vishwarajanand added testing type: cleanup An internal cleanup or hygiene concern. labels Apr 10, 2023
@vishwarajanand vishwarajanand marked this pull request as ready for review April 10, 2023 22:08
@vishwarajanand vishwarajanand requested review from a team as code owners April 10, 2023 22:08
@bshaffer bshaffer merged commit 04acdb4 into googleapis:main Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing type: cleanup An internal cleanup or hygiene concern.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants