26 public static function onEvent( $event ) {
27 $IP = dirname( dirname( __DIR__ ) );
29 $args = $event->getArguments();
30 if ( count( $args ) !== 1 ) {
31 throw new InvalidArgumentException(
'Pass extensions/$extensionName as an argument, ' .
32 'e.g. "composer phpunit:coverage-edit -- extensions/BoilerPlate"' );
34 $project = current( $args );
35 $phpunitXml =
new DomDocument();
36 $phpunitXml->load(
$IP .
'/phpunit.xml.dist' );
37 $include = iterator_to_array( $phpunitXml->getElementsByTagName(
'include' ) );
39 foreach ( $include as $childNode ) {
40 $childNode->parentNode->removeChild( $childNode );
42 $includeElement = $phpunitXml->createElement(
'include' );
44 foreach ( [
'includes',
'src',
'maintenance' ] as $dir ) {
45 $dirElement = $phpunitXml->createElement(
'directory', $project .
'/' . $dir );
46 $dirElement->setAttribute(
'suffix',
'.php' );
47 $includeElement->appendChild( $dirElement );
50 $phpunitXml->getElementsByTagName(
'coverage' )->item( 0 )
51 ->appendChild( $includeElement );
52 $phpunitXml->formatOutput =
true;
53 $phpunitXml->save(
$IP .
'/phpunit.xml' );