Merge ".pipeline/config.yaml: rename dev stage to publish"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiMainTest.php
index 1e2135b..1606275 100644 (file)
@@ -2,6 +2,7 @@
 
 use Wikimedia\Rdbms\DBQueryError;
 use Wikimedia\TestingAccessWrapper;
+use Wikimedia\Timestamp\ConvertibleTimestamp;
 
 /**
  * @group API
@@ -169,6 +170,10 @@ class ApiMainTest extends ApiTestCase {
        }
 
        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',
@@ -177,7 +182,7 @@ class ApiMainTest extends ApiTestCase {
                $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() {
@@ -242,11 +247,12 @@ class ApiMainTest extends ApiTestCase {
                $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();
        }
 
@@ -260,11 +266,12 @@ class ApiMainTest extends ApiTestCase {
                $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();
        }
 
@@ -309,11 +316,12 @@ class ApiMainTest extends ApiTestCase {
                $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;