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

Cleanup, add PHP file support #270

Merged
merged 21 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions .github/workflows/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,38 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
php: [ '7.4' ]
wordpress: [ 'latest', 'nightly' ]
glotpress: [ 'develop' ]
php: [ '8.1' ]
wordpress: [ 'latest' ]
glotpress: [ 'latest' ]
experimental: [ false ]
include:
# - php: '8.0'
# os: ubuntu-latest
# experimental: true
- os: ubuntu-latest
php: '7.2'
php: '8.2'
wordpress: 'latest'
glotpress: 'latest'
experimental: false
coverage: true
- os: ubuntu-latest
php: '7.3'
wordpress: 'latest'
glotpress: 'latest'
experimental: false
php: '8.2'
wordpress: 'nightly'
glotpress: 'develop'
experimental: true
- os: ubuntu-latest
php: '7.4'
wordpress: 'latest'
php: '8.3'
wordpress: 'nightly'
glotpress: 'develop'
experimental: false
coverage: true
experimental: true

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: ${{ matrix.coverage && 'pcov' || 'none' }}
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
tools: composer
ini-values: pcov.directory=.,pcov.exclude=~(vendor|tests)~

- name: Shutdown default MySQL service
run: sudo service mysql stop
Expand All @@ -79,7 +75,7 @@ jobs:
done

- name: Install PHP dependencies
uses: ramsey/composer-install@v2
uses: ramsey/composer-install@v3

- name: Make Composer packages available globally
run: |
Expand Down Expand Up @@ -130,12 +126,13 @@ jobs:
FILES=$(ls -d -1 "$GITHUB_WORKSPACE/build/logs/clover-behat/"*.* | paste --serial --delimiters=",")
test -n "$FILES"
echo "Coverage files: $FILES"
echo "::set-output name=COVERAGE_FILES::$FILES"
echo "COVERAGE_FILES=$FILES" >> $GITHUB_OUTPUT

- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ${{ steps.coverage_files.outputs.COVERAGE_FILES }}
flags: feature
fail_ci_if_error: true
21 changes: 4 additions & 17 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,20 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
php-version: latest
coverage: none
tools: composer, cs2pr

- name: Get Composer home directory
id: composer-home
run: |
echo "::set-output name=dir::$(composer config home)"

- name: Install PHP dependencies
uses: ramsey/composer-install@v2

- name: Install composer-normalize
run: composer global require ergebnis/composer-normalize

- name: Make Composer packages available globally
run: |
echo "${PWD}/vendor/bin" >> $GITHUB_PATH
echo "${{ steps.composer-home.outputs.dir }}/vendor/bin" >> $GITHUB_PATH
uses: ramsey/composer-install@v3

- name: Lint PHP files
run: phpcs -q --report=checkstyle | cs2pr
run: vendor/bin/phpcs -q --report=checkstyle --severity=1 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 | cs2pr --graceful-warnings

- name: Analyze PHP files
run: composer run-script analyze
Expand Down
34 changes: 16 additions & 18 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,31 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
php: [ '7.4' ]
wordpress: [ 'latest', 'nightly' ]
glotpress: [ 'develop' ]
php: [ '8.1' ]
wordpress: [ 'latest' ]
glotpress: [ 'latest' ]
experimental: [ false ]
include:
# - php: '8.0'
# os: ubuntu-latest
# experimental: true
- os: ubuntu-latest
php: '7.2'
php: '8.2'
wordpress: 'latest'
glotpress: 'latest'
experimental: false
coverage: true
- os: ubuntu-latest
php: '7.3'
wordpress: 'latest'
glotpress: 'latest'
experimental: false
php: '8.2'
wordpress: 'nightly'
glotpress: 'develop'
experimental: true
- os: ubuntu-latest
php: '7.4'
wordpress: 'latest'
php: '8.3'
wordpress: 'nightly'
glotpress: 'develop'
experimental: false
coverage: true
experimental: true

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -65,7 +62,7 @@ jobs:
tools: composer

- name: Install PHP dependencies
uses: ramsey/composer-install@v2
uses: ramsey/composer-install@v3

- name: Make Composer packages available globally
run: |
Expand Down Expand Up @@ -99,7 +96,8 @@ jobs:

- name: Upload coverage to Codecov
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage-clover-${{ github.sha }}.xml
flags: php
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# PHPUnit
/coverage*.xml
.phpunit.result.cache

# Behat
*.log
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Changed
* Require at least PHP 7.2. [#236]
* Require GlotPress 4.0. [#270]
* Require at least PHP 8.1. [#270]
* Added PHP translation file support. [#270]

### Fixed
* Pass correct parameter for translation set in `traduttore.generate_zip_delay` filter. [#236]
Expand Down
10 changes: 7 additions & 3 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ SKIP_DB_CREATE=${7-false}
TMPDIR=${TMPDIR-/tmp}
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_TESTS_FILE="$WP_TESTS_DIR"/includes/functions.php
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}
WP_CORE_FILE="$WP_CORE_DIR"/wp-includs.php
GP_TESTS_DIR="$WP_CORE_DIR/build/wp-content/plugins/glotpress/tests/phpunit"

download() {
Expand Down Expand Up @@ -56,10 +58,11 @@ set -ex

install_wp() {

if [ -d $WP_CORE_DIR ]; then
if [ -f $WP_CORE_FILE ]; then
return;
fi

rm -rf $WP_CORE_DIR
mkdir -p $WP_CORE_DIR

if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
Expand Down Expand Up @@ -104,9 +107,10 @@ install_test_suite() {
local ioption='-i'
fi

# set up testing suite if it doesn't yet exist
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite if it doesn't yet exist or only partially exists
if [ ! -f $WP_TESTS_FILE ]; then
# set up testing suite
rm -rf $WP_TESTS_DIR
mkdir -p $WP_TESTS_DIR
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
Expand Down
27 changes: 17 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,27 @@
"issues": "https://github.com/wearerequired/traduttore/issues"
},
"require": {
"php": ">=7.2",
"php": ">=8.1",
"ext-json": "*",
"ext-zip": "*",
"wearerequired/traduttore-registry": "^2.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"php-stubs/wp-cli-stubs": "^2.4",
"phpunit/phpunit": "^7.5.20",
"szepeviktor/phpstan-wordpress": "^1.1",
"wearerequired/coding-standards": "^3.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"ergebnis/composer-normalize": "^2.42",
"php-stubs/wordpress-tests-stubs": "^6.5",
"php-stubs/wp-cli-stubs": "^2.10",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.2",
"phpstan/phpstan-phpunit": "^1.4",
"swissspidy/phpstan-no-private": "^0.2.0",
"szepeviktor/phpstan-wordpress": "^1.3",
"wearerequired/coding-standards": "^6.0",
"wp-cli/extension-command": "^2.0",
"wp-cli/rewrite-command": "^2.0",
"wp-cli/wp-cli-tests": "^3.0.11",
"wpackagist-plugin/glotpress": "^3.0.0",
"yoast/phpunit-polyfills": "^1.0"
"wp-cli/wp-cli-tests": "^4.2.9",
"wpackagist-plugin/glotpress": "^4.0.0",
"yoast/phpunit-polyfills": "^1.1"
},
"suggest": {
"wpackagist-plugin/slack": "Send Slack notifications for various events"
Expand All @@ -73,8 +78,10 @@
},
"config": {
"allow-plugins": {
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"composer/installers": true
"ergebnis/composer-normalize": true,
"phpstan/extension-installer": true
},
"process-timeout": 7200,
"sort-packages": true
Expand Down
4 changes: 2 additions & 2 deletions inc/CLI/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __invoke( array $args, array $assoc_args ): void {
'cache_dir' => $cache_dir,
];

WP_CLI::line( json_encode( $info ) );
WP_CLI::line( (string) json_encode( $info ) );
} else {
WP_CLI::line( "Traduttore version:\t" . $plugin_version );
WP_CLI::line( "WordPress version:\t" . $wp_version );
Expand Down Expand Up @@ -149,7 +149,7 @@ protected function get_svn_binary_path(): ?string {
* @return null|string Binary path on success, null otherwise.
*/
protected function get_wp_binary_path(): ?string {
if ( \defined( 'TRADUTTORE_WP_BIN' ) && TRADUTTORE_WP_BIN ) {
if ( \defined( 'TRADUTTORE_WP_BIN' ) && \is_string( TRADUTTORE_WP_BIN ) ) {
return TRADUTTORE_WP_BIN;
}

Expand Down
8 changes: 5 additions & 3 deletions inc/CLI/LanguagePackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@

$zip_provider = new ZipProvider( $set );

$last_updated = $zip_provider->get_last_build_time();

Check warning on line 99 in inc/CLI/LanguagePackCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/LanguagePackCommand.php#L99

Added line #L99 was not covered by tests

$language_packs[] = [
'Locale' => $locale->wp_locale,
'English Name' => $locale->english_name,
'Native Name' => $locale->native_name,
'Completed' => sprintf( '%s%%', $set->percent_translated() ),
'Updated' => $zip_provider->get_last_build_time()->format( DATE_ATOM ),
'Updated' => $last_updated ? $last_updated->format( DATE_ATOM ) : 'n/a',

Check warning on line 106 in inc/CLI/LanguagePackCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/LanguagePackCommand.php#L106

Added line #L106 was not covered by tests
'Package' => file_exists( $zip_provider->get_zip_path() ) ? $zip_provider->get_zip_url() : 'n/a',
];
}
Expand Down Expand Up @@ -160,8 +162,8 @@
* @param string[] $assoc_args Associative args.
*/
public function build( array $args, array $assoc_args ): void {
$all = get_flag_value( $assoc_args, 'all', false );
$force = get_flag_value( $assoc_args, 'force', false );
$all = (bool) get_flag_value( $assoc_args, 'all', false );
$force = (bool) get_flag_value( $assoc_args, 'force', false );

Check warning on line 166 in inc/CLI/LanguagePackCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/LanguagePackCommand.php#L165-L166

Added lines #L165 - L166 were not covered by tests
$projects = $this->check_optional_args_and_all( $args, $all );

if ( ! $projects ) {
Expand Down
11 changes: 5 additions & 6 deletions inc/CLI/ProjectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
$repository_visibility = $project->get_repository_visibility() ?? '(unknown)';
$repository_ssh_url = $repository ? $repository->get_ssh_url() : '(unknown)';
$repository_https_url = $repository ? $repository->get_https_url() : '(unknown)';
$repository_instance = $repository ? \get_class( $repository ) : '(unknown)';
$loader_instance = $loader ? \get_class( $loader ) : '(unknown)';
$repository_instance = $repository ? $repository::class : '(unknown)';
$loader_instance = $loader ? $loader::class : '(unknown)';

Check warning on line 92 in inc/CLI/ProjectCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/ProjectCommand.php#L91-L92

Added lines #L91 - L92 were not covered by tests

if ( get_flag_value( $assoc_args, 'format' ) === 'json' ) {
$info = [
Expand All @@ -110,7 +110,7 @@
'loader_instance' => $loader_instance,
];

WP_CLI::line( json_encode( $info ) );
WP_CLI::line( (string) json_encode( $info ) );

Check warning on line 113 in inc/CLI/ProjectCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/ProjectCommand.php#L113

Added line #L113 was not covered by tests
} else {
WP_CLI::line( "Project ID:\t\t" . $project_id );
WP_CLI::line( "Project name:\t\t" . $project_name );
Expand Down Expand Up @@ -166,8 +166,8 @@
* @param string[] $assoc_args Associative args.
*/
public function update( array $args, array $assoc_args ): void {
$delete = get_flag_value( $assoc_args, 'delete', false );
$cached = get_flag_value( $assoc_args, 'cached', false );
$delete = (bool) get_flag_value( $assoc_args, 'delete', false );
$cached = (bool) get_flag_value( $assoc_args, 'cached', false );
$locator = new ProjectLocator( $args[0] );
$project = $locator->get_project();

Expand Down Expand Up @@ -205,5 +205,4 @@

WP_CLI::warning( sprintf( 'Could not update translations for project (ID: %d)!', $project->get_id() ) );
}

}
Loading