Legoktm has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/401409 )
Change subject: Make it easier to use ApiFormatTestBase with custom formatters ...................................................................... Make it easier to use ApiFormatTestBase with custom formatters Custom formatters are not registered with the module manager, and need to set the class that should be insantiated. It's currently not possible to pass $class to encodeData() if using then normal data provider, so remove it in favor of a $printerClass property that subclasses can set. On top of that, allow setting a factory function via the $printerFactory property (can be set to a closure in setUp) since classes like ApiFormatRaw have different construction parameters than what is normally expected. Finally, allow passing expected exceptions in the data provider. Change-Id: I48d43e1b4c32c0cf8c78b5cc042abf3f1ca5eec1 --- M tests/phpunit/includes/api/format/ApiFormatTestBase.php 1 file changed, 24 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/09/401409/1 diff --git a/tests/phpunit/includes/api/format/ApiFormatTestBase.php b/tests/phpunit/includes/api/format/ApiFormatTestBase.php index fb086e9..a10ee1a 100644 --- a/tests/phpunit/includes/api/format/ApiFormatTestBase.php +++ b/tests/phpunit/includes/api/format/ApiFormatTestBase.php @@ -9,6 +9,22 @@ protected $printerName; /** + * Class being tested, if it's not already registered with + * the module manager + * + * @var string|null + */ + protected $printerClass; + + /** + * Factory to register with the module manager to + * create the class + * + * @var callable|null + */ + protected $printerFactory; + + /** * Return general data to be encoded for testing * @return array See self::testGeneralEncoding * @throws Exception @@ -21,16 +37,17 @@ * Get the formatter output for the given input data * @param array $params Query parameters * @param array $data Data to encode - * @param string $class Printer class to use instead of the normal one * @return string * @throws Exception */ - protected function encodeData( array $params, array $data, $class = null ) { + protected function encodeData( array $params, array $data ) { $context = new RequestContext; $context->setRequest( new FauxRequest( $params, true ) ); $main = new ApiMain( $context ); - if ( $class !== null ) { - $main->getModuleManager()->addModule( $this->printerName, 'format', $class ); + if ( $this->printerClass !== null ) { + $main->getModuleManager()->addModule( + $this->printerName, 'format', $this->printerClass, $this->printerFactory + ); } $result = $main->getResult(); $result->addArrayType( null, 'default' ); @@ -58,6 +75,9 @@ if ( isset( $params['SKIP'] ) ) { $this->markTestSkipped( $expect ); } + if ( isset( $params['exception'] ) ) { + $this->setExpectedException( $params['exception'][0], $params['exception'][1] ); + } $this->assertSame( $expect, $this->encodeData( $params, $data ) ); } -- To view, visit https://gerrit.wikimedia.org/r/401409 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I48d43e1b4c32c0cf8c78b5cc042abf3f1ca5eec1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Legoktm <lego...@member.fsf.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits