wiki.techinc.nl/tests/parser/DelayedParserTest.php
Tim Starling a387fee397 Split up testHelpers.inc, break off fuzz testing
* Split up testHelpers.inc into one class per file, with the file named
  after the class per the usual convention. Put them in tests/parser
  since they are all parser-related, even though a couple are reused by
  other unit tests.
* Also rename parserTest.inc and parserTestsParserHook.php to follow the
  usual convention, and split off ParserTestResultNormalizer
* Move fuzz testing out to its own maintenance script. It's really not
  helpful to have fuzz testing, which is designed to run forever,
  exposed as a PHPUnit test.
* Increased fuzz test memory limit, and increased the memory headroom for
  getMemoryBreakdown(), since HHVM's ReflectionClass has an internal
  cache which uses quite a lot of memory.
* Temporarily switched a couple of ParserTest methods from private to
  public to support fuzz testing from a separate class -- I plan on
  replacing this interface in a subsequent commit.

Change-Id: Ib1a07e109ec1005bff2751b78eb4de35f2dfc472
2016-09-08 09:06:45 +10:00

116 lines
3.1 KiB
PHP

<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup Testing
*/
/**
* A class to delay execution of a parser test hooks.
*/
class DelayedParserTest {
/** Initialized on construction */
private $hooks;
private $fnHooks;
private $transparentHooks;
public function __construct() {
$this->reset();
}
/**
* Init/reset or forgot about the current delayed test.
* Call to this will erase any hooks function that were pending.
*/
public function reset() {
$this->hooks = [];
$this->fnHooks = [];
$this->transparentHooks = [];
}
/**
* Called whenever we actually want to run the hook.
* Should be the case if we found the parserTest is not disabled
* @param ParserTest|NewParserTest $parserTest
* @return bool
* @throws MWException
*/
public function unleash( &$parserTest ) {
if ( !( $parserTest instanceof ParserTest || $parserTest instanceof NewParserTest ) ) {
throw new MWException( __METHOD__ . " must be passed an instance of ParserTest or "
. "NewParserTest classes\n" );
}
# Trigger delayed hooks. Any failure will make us abort
foreach ( $this->hooks as $hook ) {
$ret = $parserTest->requireHook( $hook );
if ( !$ret ) {
return false;
}
}
# Trigger delayed function hooks. Any failure will make us abort
foreach ( $this->fnHooks as $fnHook ) {
$ret = $parserTest->requireFunctionHook( $fnHook );
if ( !$ret ) {
return false;
}
}
# Trigger delayed transparent hooks. Any failure will make us abort
foreach ( $this->transparentHooks as $hook ) {
$ret = $parserTest->requireTransparentHook( $hook );
if ( !$ret ) {
return false;
}
}
# Delayed execution was successful.
return true;
}
/**
* Similar to ParserTest object but does not run anything
* Use unleash() to really execute the hook
* @param string $hook
*/
public function requireHook( $hook ) {
$this->hooks[] = $hook;
}
/**
* Similar to ParserTest object but does not run anything
* Use unleash() to really execute the hook function
* @param string $fnHook
*/
public function requireFunctionHook( $fnHook ) {
$this->fnHooks[] = $fnHook;
}
/**
* Similar to ParserTest object but does not run anything
* Use unleash() to really execute the hook function
* @param string $hook
*/
public function requireTransparentHook( $hook ) {
$this->transparentHooks[] = $hook;
}
}