Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Strips out unnecessary testsuites data from PHPUnit test results
*
* Run with `wp eval-file cleanup-results-key.php`
*/
global $wpdb;
$post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type='result'" );
foreach( $post_ids as $h => $post_id ) {
if ( $h && $h % 100 === 0 ) {
sleep(1);
}
WP_CLI::log( "Processing {$post_id}" );
$results = get_post_meta( $post_id, 'results', true );
// If 'testsuites' is already empty, we don't need to process'
if ( empty( $results['testsuites'] ) ) {
continue;
}
foreach( $results['testsuites'] as $i => $testsuite ) {
// If 'failures' and 'errors' are both empty for the testsuite,
// then we should drop this data from the array
if ( empty( $testsuite['failures'] ) && empty( $testsuite['errors'] ) ) {
unset( $results['testsuites'][ $i ] );
}
}
// Normalize array keys
$results['testsuites'] = array_values( $results['testsuites'] );
WP_CLI::log( 'Found ' . count( $results['testsuites'] ) . ' failures/errors remaining.' );
// Hopefully this is a lot less data than what we started with
update_post_meta( $post_id, 'results', $results );
}
WP_CLI::success( "All done!" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.