use Wikimedia\Rdbms\DBQueryError;
use Wikimedia\TestingAccessWrapper;
+use Wikimedia\Timestamp\ConvertibleTimestamp;
/**
* @group API
}
public function testAddRequestedFieldsCurTimestamp() {
+ // Fake timestamp for better testability, CI can sometimes take
+ // unreasonably long to run the simple test request here.
+ $reset = ConvertibleTimestamp::setFakeTime( '20190102030405' );
+
$req = new FauxRequest( [
'action' => 'query',
'meta' => 'siteinfo',
$api = new ApiMain( $req );
$api->execute();
$timestamp = $api->getResult()->getResultData()['curtimestamp'];
- $this->assertLessThanOrEqual( 1, abs( strtotime( $timestamp ) - time() ) );
+ $this->assertSame( '2019-01-02T03:04:05Z', $timestamp );
}
public function testAddRequestedFieldsResponseLangInfo() {
$mock->method( 'needsToken' )->willReturn( true );
$api = new ApiMain( new FauxRequest( [ 'action' => 'testmodule' ] ) );
- $api->getModuleManager()->addModule( 'testmodule', 'action', get_class( $mock ),
- function () use ( $mock ) {
+ $api->getModuleManager()->addModule( 'testmodule', 'action', [
+ 'class' => get_class( $mock ),
+ 'factory' => function () use ( $mock ) {
return $mock;
}
- );
+ ] );
$api->execute();
}
$mock->method( 'mustBePosted' )->willReturn( false );
$api = new ApiMain( new FauxRequest( [ 'action' => 'testmodule' ] ) );
- $api->getModuleManager()->addModule( 'testmodule', 'action', get_class( $mock ),
- function () use ( $mock ) {
+ $api->getModuleManager()->addModule( 'testmodule', 'action', [
+ 'class' => get_class( $mock ),
+ 'factory' => function () use ( $mock ) {
return $mock;
}
- );
+ ] );
$api->execute();
}
$req->setRequestURL( "http://localhost" );
$api = new ApiMain( $req );
- $api->getModuleManager()->addModule( 'testmodule', 'action', get_class( $mock ),
- function () use ( $mock ) {
+ $api->getModuleManager()->addModule( 'testmodule', 'action', [
+ 'class' => get_class( $mock ),
+ 'factory' => function () use ( $mock ) {
return $mock;
}
- );
+ ] );
$wrapper = TestingAccessWrapper::newFromObject( $api );
$wrapper->mInternalMode = false;