Last modified: 2012-03-08 19:06:18 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T17966, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 15966 - Provide a way to invoke the Parser from within a PHPUnit test
Provide a way to invoke the Parser from within a PHPUnit test
Status: RESOLVED WORKSFORME
Product: MediaWiki
Classification: Unclassified
Unit tests (Other open bugs)
unspecified
All All
: Low enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-10-13 15:52 UTC by sharon.dagan
Modified: 2012-03-08 19:06 UTC (History)
4 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description sharon.dagan 2008-10-13 15:52:02 UTC
For the sake of unit testing of extensions code, please provide an *easy* way to invoke the Parser from within a PHPUnit test. 

For example:

/*
 *  returns a ready-to-use Parser
 */
class ParserMock {
  var $parser;
 
  function __constructor() {
     $conf   = new Array( ... );
     $parser = new Parser( $conf );
     ...
  }
 
  function setHook( ... ) {
    ...
    $parser->setHook( ... );
  }  

  function parse( $text ) {
     $title = new Title( 'test' );
     $opt = new ParserOptions( ... );
     returns $parser->parse( $text, $title, $opt );
  } 
}

class MyFooTagTest extends PHPUnit_Framework_TestCase {
  var $parserMock;
  
  function setUp() {
    $parserMock = new ParserMock;
    $myFooTag   = new MyFooTag
    $parserMock->setHook( 'foo', array( & $myFooTag, 'foo' ) );
  }

  function testFoo() {
    $out = $parserMock->parse( '<foo f="F">Bar</foo>' );
    ...
  }
}
Comment 1 Tim Starling 2008-10-16 04:24:24 UTC
That's basically how it is already, except you can use the actual Parser class instead of "ParserMock". Have you encountered some problem with this approach?
Comment 2 Antoine "hashar" Musso (WMF) 2012-01-30 17:43:14 UTC
resetting to wikibugs-l@lists.wikimedia.org assignee.
Comment 3 Max Semenik 2012-03-08 19:06:18 UTC
It works this way already. Unless there was something specific requested here, it's WORKSFORME.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links