MediaWiki master
ComposerPhpunitXmlCoverageEdit.php
Go to the documentation of this file.
1<?php
20
21use Composer\Script\Event;
22use DOMDocument;
23use DOMNode;
24use InvalidArgumentException;
25
39 public static function onEvent( $event ) {
40 $IP = dirname( dirname( __DIR__ ) );
41 // TODO: Support passing arbitrary directories for core (or extensions/skins).
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' ) );
52 foreach ( $include as $childNode ) {
53 $childNode->parentNode->removeChild( $childNode );
54 }
55 $whitelistElement = $phpunitXml->createElement( 'include' );
56 // TODO: Use AutoloadClasses from extension.json to load the relevant directories
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}
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:98
Edit phpunit.xml to speed up code coverage generation.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...