| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
namespace MediaWiki\Composer; |
| 20 |
|
| 21 |
use Composer\Script\Event; |
| 22 |
use DOMDocument; |
| 23 |
use DOMNode; |
| 24 |
use InvalidArgumentException; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class ComposerPhpunitXmlCoverageEdit { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public static function onEvent( $event ) { |
| 40 |
$IP = dirname( dirname( __DIR__ ) ); |
| 41 |
|
| 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"' ); |
| 46 |
} |
| 47 |
$project = current( $args ); |
| 48 |
$phpunitXml = new DomDocument(); |
| 49 |
$phpunitXml->load( $IP . '/phpunit.xml.dist' ); |
| 50 |
$include = iterator_to_array( $phpunitXml->getElementsByTagName( 'include' ) ); |
| 51 |
|
| 52 |
foreach ( $include as $childNode ) { |
| 53 |
$childNode->parentNode->removeChild( $childNode ); |
| 54 |
} |
| 55 |
$whitelistElement = $phpunitXml->createElement( 'include' ); |
| 56 |
|
| 57 |
foreach ( [ 'includes', 'src', 'maintenance' ] as $dir ) { |
| 58 |
$dirElement = $phpunitXml->createElement( 'directory', $project . '/' . $dir ); |
| 59 |
$dirElement->setAttribute( 'suffix', '.php' ); |
| 60 |
$whitelistElement->appendChild( $dirElement ); |
| 61 |
|
| 62 |
} |
| 63 |
$phpunitXml->getElementsByTagName( 'coverage' )->item( 0 ) |
| 64 |
->appendChild( $whitelistElement ); |
| 65 |
$phpunitXml->formatOutput = true; |
| 66 |
$phpunitXml->save( $IP . '/phpunit.xml' ); |
| 67 |
} |
| 68 |
} |