It is not entirely meaningless. It might be an indicator that the number of calls to a method is intentionally unlimited. This is similar to e.g. an @inheritDoc PHPDoc comment that marks a method as being "intentionally undocumented". However, what's the meaning of being "intentionally unconstrained"? Let's just not have any constraint then. I feel all these ->expects( $this->any() ) bloat the test code so much that it's never worth it. Change-Id: I9925e7706bd03e1666f6eb0b284cb42b0dd3be23
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @covers ApiOpenSearch
|
|
*/
|
|
class ApiOpenSearchTest extends MediaWikiIntegrationTestCase {
|
|
public function testGetAllowedParams() {
|
|
$config = $this->replaceSearchEngineConfig();
|
|
$config->method( 'getSearchTypes' )
|
|
->willReturn( [ 'the one ring' ] );
|
|
|
|
$api = $this->createApi();
|
|
$engine = $this->replaceSearchEngine();
|
|
$engine->method( 'getProfiles' )
|
|
->will( $this->returnValueMap( [
|
|
[ SearchEngine::COMPLETION_PROFILE_TYPE, $api->getUser(), [
|
|
[
|
|
'name' => 'normal',
|
|
'desc-message' => 'normal-message',
|
|
'default' => true,
|
|
],
|
|
[
|
|
'name' => 'strict',
|
|
'desc-message' => 'strict-message',
|
|
],
|
|
] ],
|
|
] ) );
|
|
|
|
$params = $api->getAllowedParams();
|
|
|
|
$this->assertArrayNotHasKey( 'offset', $params );
|
|
$this->assertArrayHasKey( 'profile', $params, print_r( $params, true ) );
|
|
$this->assertEquals( 'normal', $params['profile'][ApiBase::PARAM_DFLT] );
|
|
}
|
|
|
|
private function replaceSearchEngineConfig() {
|
|
$config = $this->getMockBuilder( SearchEngineConfig::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$this->setService( 'SearchEngineConfig', $config );
|
|
|
|
return $config;
|
|
}
|
|
|
|
private function replaceSearchEngine() {
|
|
$engine = $this->getMockBuilder( SearchEngine::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$engineFactory = $this->getMockBuilder( SearchEngineFactory::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$engineFactory->method( 'create' )
|
|
->willReturn( $engine );
|
|
$this->setService( 'SearchEngineFactory', $engineFactory );
|
|
|
|
return $engine;
|
|
}
|
|
|
|
private function createApi() {
|
|
$ctx = new RequestContext();
|
|
$apiMain = new ApiMain( $ctx );
|
|
return new ApiOpenSearch( $apiMain, 'opensearch', '' );
|
|
}
|
|
}
|