-
Notifications
You must be signed in to change notification settings - Fork 24
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
Behat code coverage support #234
Merged
Merged
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2ee6018
Begin adding code coverage support
swissspidy 43f58f0
Lint fixes
swissspidy 5708fb7
Don't use levels for dirname
swissspidy 98a69af
Rename env var
swissspidy ecbf4ff
Add db type as suffix
swissspidy 766ef2c
Change destination for coverage files
swissspidy 50f20e6
Create directory if missing
swissspidy 6dd119b
Merge branch 'main' into code-coverage
swissspidy a952f85
Use `SRC_DIR` variable instead
swissspidy bfaccf4
Rename file
swissspidy da6c27d
Update phpcs config
swissspidy 74745d4
Apply suggestions from code review
swissspidy 7756a91
Fix HTTP mocking test
swissspidy 0ebd313
Support Requests v1 for request mocking
swissspidy ff03cf0
Swap around
swissspidy 2b71a7d
Full namespace
swissspidy 973fcd7
Remove non-existent constant
swissspidy aa2ce7e
Manually add defaults
swissspidy ab81bed
Add to `when_i_run_from_a_subfolder`
swissspidy 6458187
Merge branch 'main' into code-coverage
swissspidy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
use SebastianBergmann\CodeCoverage\CodeCoverage; | ||
swissspidy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use SebastianBergmann\CodeCoverage\Driver\Selector; | ||
use SebastianBergmann\CodeCoverage\Filter; | ||
use SebastianBergmann\CodeCoverage\Report\Clover; | ||
|
||
$root_folder = realpath( dirname( __DIR__ ) ); | ||
|
||
if ( ! class_exists( 'SebastianBergmann\CodeCoverage\Filter' ) ) { | ||
require "{$root_folder}/vendor/autoload.php"; | ||
} | ||
|
||
$filter = new Filter(); | ||
$filter->includeDirectory( "{$root_folder}/includes" ); | ||
$filter->includeFiles( array( "{$root_folder}/plugin.php" ) ); | ||
|
||
$coverage = new CodeCoverage( | ||
( new Selector() )->forLineCoverage( $filter ), | ||
$filter | ||
); | ||
|
||
$feature = getenv( 'BEHAT_FEATURE_TITLE' ); | ||
swissspidy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$scenario = getenv( 'BEHAT_SCENARIO_TITLE' ); | ||
$name = "{$feature} - {$scenario}"; | ||
|
||
$coverage->start( $name ); | ||
|
||
register_shutdown_function( | ||
static function () use ( $coverage, $feature, $scenario, $name ) { | ||
$coverage->stop(); | ||
|
||
$project_dir = (string) getenv( 'BEHAT_PROJECT_DIR' ); | ||
|
||
$feature_suffix = preg_replace( '/[^a-z0-9]+/', '-', strtolower( $feature ) ); | ||
$scenario_suffix = preg_replace( '/[^a-z0-9]+/', '-', strtolower( $scenario ) ); | ||
$db_type = strtolower( getenv( 'WP_CLI_TEST_DBTYPE' ) ); | ||
$destination = "$project_dir/build/logs/$feature_suffix-$scenario_suffix-$db_type.xml"; | ||
|
||
$dir = dirname( $destination ); | ||
if ( ! file_exists( $dir ) ) { | ||
mkdir( $dir, 0777, true /*recursive*/ ); | ||
} | ||
|
||
( new Clover() )->process( $coverage, $destination, $name ); | ||
} | ||
); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the only step that triggers a WP-CLI command. For proper coverage, we'll need to cover all instances that trigger WP-CLI commands, like (for example) the below
when_i_run_from_a_subfolder()
andwhen_i_run_the_previous_command_again()
. There might be others as well...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's only
when_i_run_from_a_subfolder
AFAICT, becausewhen_i_run_the_previous_command_again
just re-runs the previous command without any substitutions.I don't think there are any others.
when_i_launch_in_the_background
is used for launchingwp server
in the background, but it doesn't make sense to invoke coverage collection there. That means no code coverage for server-command but I think we can live with that .