31 public static function onEvent( $event ) {
32 $IP = dirname( dirname( __DIR__ ) );
34 $args = $event->getArguments();
35 if ( count(
$args ) !== 1 ) {
36 throw new InvalidArgumentException(
'Pass extensions/$extensionName as an argument, ' .
37 'e.g. "composer phpunit:coverage-edit -- extensions/BoilerPlate"' );
39 $project = current(
$args );
40 $phpunitXml = \PHPUnit\Util\Xml::loadFile(
$IP .
'/phpunit.xml.dist' );
41 $whitelist = iterator_to_array( $phpunitXml->getElementsByTagName(
'whitelist' ) );
43 foreach ( $whitelist as $childNode ) {
44 $childNode->parentNode->removeChild( $childNode );
46 $whitelistElement = $phpunitXml->createElement(
'whitelist' );
47 $whitelistElement->setAttribute(
'addUncoveredFilesFromWhitelist',
'false' );
49 foreach ( [
'includes',
'src',
'maintenance' ] as $dir ) {
50 $dirElement = $phpunitXml->createElement(
'directory', $project .
'/' . $dir );
51 $dirElement->setAttribute(
'suffix',
'.php' );
52 $whitelistElement->appendChild( $dirElement );
55 $phpunitXml->getElementsByTagName(
'filter' )->item( 0 )
56 ->appendChild( $whitelistElement );
57 $phpunitXml->formatOutput =
true;
58 $phpunitXml->save(
$IP .
'/phpunit.xml' );