39 public static function onEvent( $event ) {
40 $IP = dirname( dirname( __DIR__ ) );
42 $args = $event->getArguments();
43 if ( count( $args ) !== 1 ) {
44 throw new InvalidArgumentException(
'Pass extensions/$extensionName as an argument, ' .
45 'e.g. "composer phpunit:coverage-edit -- extensions/BoilerPlate"' );
47 $project = current( $args );
48 $phpunitXml =
new DomDocument();
49 $phpunitXml->load(
$IP .
'/phpunit.xml.dist' );
50 $include = iterator_to_array( $phpunitXml->getElementsByTagName(
'include' ) );
52 foreach ( $include as $childNode ) {
53 $childNode->parentNode->removeChild( $childNode );
55 $whitelistElement = $phpunitXml->createElement(
'include' );
57 foreach ( [
'includes',
'src',
'maintenance' ] as $dir ) {
58 $dirElement = $phpunitXml->createElement(
'directory', $project .
'/' . $dir );
59 $dirElement->setAttribute(
'suffix',
'.php' );
60 $whitelistElement->appendChild( $dirElement );
63 $phpunitXml->getElementsByTagName(
'coverage' )->item( 0 )
64 ->appendChild( $whitelistElement );
65 $phpunitXml->formatOutput =
true;
66 $phpunitXml->save(
$IP .
'/phpunit.xml' );