lastTestLogs = null; $this->originalSpi = LoggerFactory::getProvider(); $this->spi = new LogCapturingSpi( $this->originalSpi ); LoggerFactory::registerProvider( $this->spi ); } /** * A test ended. * * @param PHPUnit_Framework_Test $test * @param float $time */ public function endTest( PHPUnit_Framework_Test $test, $time ) { $this->lastTestLogs = $this->spi->getLogs(); LoggerFactory::registerProvider( $this->originalSpi ); $this->originalSpi = null; $this->spi = null; } /** * Get string formatted logs generated during the last * test to execute. * * @return string */ public function getLog() { $logs = $this->lastTestLogs; if ( !$logs ) { return ''; } $message = []; foreach ( $logs as $log ) { $message[] = sprintf( '[%s] [%s] %s %s', $log['channel'], $log['level'], $log['message'], json_encode( $log['context'] ) ); } return implode( "\n", $message ); } }