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