Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
7 changes: 7 additions & 0 deletions bin/run-phpstan-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# Run the code style check only if a configuration file exists.
if [ -f "phpstan.dist.neon" ] || [ -f "phpstan.neon.dist" ] || [ -f "phpstan.neon" ]
then
vendor/bin/phpstan --memory-limit=2048M analyse "$@"
fi
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"php-parallel-lint/php-console-highlighter": "^1.0",
"php-parallel-lint/php-parallel-lint": "^1.3.1",
"phpcompatibility/php-compatibility": "dev-develop",
"phpstan/extension-installer": "^1.4.3",
"phpstan/phpstan": "^1.12.26",
"szepeviktor/phpstan-wordpress": "^v1.3.5",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is a new addition, it'd be better to start with 2.0?!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't, because we currently require PHP 7.2+, but v2 requires PHP 7.4+

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, ok. Makes sense.

"wp-cli/config-command": "^1 || ^2",
"wp-cli/core-command": "^1 || ^2",
"wp-cli/eval-command": "^1 || ^2",
Expand All @@ -28,7 +31,8 @@
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"johnpbloch/wordpress-core-installer": true
"johnpbloch/wordpress-core-installer": true,
"phpstan/extension-installer": true
},
"sort-packages": true,
"lock": false
Expand Down Expand Up @@ -63,19 +67,22 @@
"bin/run-linter-tests",
"bin/run-php-unit-tests",
"bin/run-phpcs-tests",
"bin/run-phpcbf-cleanup"
"bin/run-phpcbf-cleanup",
"bin/run-phpstan-tests"
],
"scripts": {
"behat": "run-behat-tests",
"behat-rerun": "rerun-behat-tests",
"lint": "run-linter-tests",
"phpcs": "run-phpcs-tests",
"phpcbf": "run-phpcbf-cleanup",
"phpstan": "run-phpstan-tests",
"phpunit": "run-php-unit-tests",
"prepare-tests": "install-package-tests",
"test": [
"@lint",
"@phpcs",
"@phpstan",
"@phpunit",
"@behat"
]
Expand Down
2 changes: 2 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
#############################################################################
-->

<exclude-pattern>tests/phpstan/scan-files.php</exclude-pattern>

<!-- This is a procedural stand-alone file that is never loaded in a WordPress context,
so this file does not have to comply with WP naming conventions. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
Expand Down
19 changes: 19 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
parameters:
level: 5
paths:
- src
- tests
scanDirectories:
- vendor/wp-cli/wp-cli
- vendor/phpunit/php-code-coverage
- vendor/behat/behat
scanFiles:
- tests/phpstan/scan-files.php
treatPhpDocTypesAsCertain: false
dynamicConstantNames:
- WP_DEBUG
- WP_DEBUG_LOG
- WP_DEBUG_DISPLAY
ignoreErrors:
# Needs fixing in WP-CLI.
- message: '#Parameter \#1 \$cmd of function WP_CLI\\Utils\\esc_cmd expects array<string>#'
44 changes: 17 additions & 27 deletions src/Context/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1179,14 +1179,11 @@
'skip-email' => true,
];

$run_dir = '' !== $subdir ? ( $this->variables['RUN_DIR'] . "/$subdir" ) : $this->variables['RUN_DIR'];
$install_cache_path = '';
$run_dir = '' !== $subdir ? ( $this->variables['RUN_DIR'] . "/$subdir" ) : $this->variables['RUN_DIR'];

Check warning on line 1182 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L1182

Added line #L1182 was not covered by tests

if ( self::$install_cache_dir ) {
$install_cache_path = self::$install_cache_dir . '/install_' . md5( implode( ':', $install_args ) . ':subdir=' . $subdir );
}
$install_cache_path = self::$install_cache_dir . '/install_' . md5( implode( ':', $install_args ) . ':subdir=' . $subdir );

Check warning on line 1184 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L1184

Added line #L1184 was not covered by tests

if ( $install_cache_path && file_exists( $install_cache_path ) ) {
if ( file_exists( $install_cache_path ) ) {

Check warning on line 1186 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L1186

Added line #L1186 was not covered by tests
self::copy_dir( $install_cache_path, $run_dir );

// This is the sqlite equivalent of restoring a database dump in MySQL
Expand All @@ -1198,26 +1195,24 @@
} else {
$this->proc( 'wp core install', $install_args, $subdir )->run_check();

if ( $install_cache_path ) {
mkdir( $install_cache_path );
mkdir( $install_cache_path );

Check warning on line 1198 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L1198

Added line #L1198 was not covered by tests

self::dir_diff_copy( $run_dir, self::$cache_dir, $install_cache_path );
self::dir_diff_copy( $run_dir, self::$cache_dir, $install_cache_path );

Check warning on line 1200 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L1200

Added line #L1200 was not covered by tests

if ( 'sqlite' !== self::$db_type ) {
$mysqldump_binary = Utils\get_sql_dump_command();
$mysqldump_binary = Utils\force_env_on_nix_systems( $mysqldump_binary );
$support_column_statistics = exec( "{$mysqldump_binary} --help | grep 'column-statistics'" );
$command = "{$mysqldump_binary} --no-defaults --no-tablespaces";
if ( $support_column_statistics ) {
$command .= ' --skip-column-statistics';
}
self::run_sql( $command, [ 'result-file' => "{$install_cache_path}.sql" ], true /*add_database*/ );
if ( 'sqlite' !== self::$db_type ) {
$mysqldump_binary = Utils\get_sql_dump_command();
$mysqldump_binary = Utils\force_env_on_nix_systems( $mysqldump_binary );
$support_column_statistics = exec( "{$mysqldump_binary} --help | grep 'column-statistics'" );
$command = "{$mysqldump_binary} --no-defaults --no-tablespaces";
if ( $support_column_statistics ) {
$command .= ' --skip-column-statistics';

Check warning on line 1208 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L1202-L1208

Added lines #L1202 - L1208 were not covered by tests
}
self::run_sql( $command, [ 'result-file' => "{$install_cache_path}.sql" ], true /*add_database*/ );

Check warning on line 1210 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L1210

Added line #L1210 was not covered by tests
}

if ( 'sqlite' === self::$db_type ) {
// This is the sqlite equivalent of creating a database dump in MySQL
copy( "$run_dir/wp-content/database/.ht.sqlite", "{$install_cache_path}.sqlite" );
}
if ( 'sqlite' === self::$db_type ) {

Check warning on line 1213 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L1213

Added line #L1213 was not covered by tests
// This is the sqlite equivalent of creating a database dump in MySQL
copy( "$run_dir/wp-content/database/.ht.sqlite", "{$install_cache_path}.sqlite" );

Check warning on line 1215 in src/Context/FeatureContext.php

View check run for this annotation

Codecov / codecov/patch

src/Context/FeatureContext.php#L1215

Added line #L1215 was not covered by tests
}
}
}
Expand Down Expand Up @@ -1557,11 +1552,6 @@
$framework_folder = FeatureContext::get_framework_dir();
wp_cli_behat_env_debug( "Framework folder location: {$framework_folder}" );

// Didn't manage to detect a valid framework folder.
if ( empty( $vendor_folder ) ) {
return;
}

// Load helper functionality that is needed for the tests.
require_once "{$framework_folder}/php/utils.php";
require_once "{$framework_folder}/php/WP_CLI/Process.php";
Expand Down
2 changes: 1 addition & 1 deletion src/Context/Support.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
break;

default:
throw new PendingException();
throw new \Behat\Behat\Tester\Exception\PendingException();

Check warning on line 73 in src/Context/Support.php

View check run for this annotation

Codecov / codecov/patch

src/Context/Support.php#L73

Added line #L73 was not covered by tests
}

if ( ! $r ) {
Expand Down
1 change: 1 addition & 0 deletions src/Context/ThenStepDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@
}
$action = substr( $action, 0, -1 );
$expected = $this->replace_variables( (string) $expected );
$contents = '';

Check warning on line 426 in src/Context/ThenStepDefinitions.php

View check run for this annotation

Codecov / codecov/patch

src/Context/ThenStepDefinitions.php#L426

Added line #L426 was not covered by tests
if ( 'file' === $type ) {
$contents = file_get_contents( $path );
} elseif ( 'directory' === $type ) {
Expand Down
6 changes: 6 additions & 0 deletions tests/phpstan/scan-files.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

namespace SebastianBergmann\CodeCoverage\Driver {
class Xdebug {
}
}