resourceloader: Document which FileModule methods use a DB
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 19 Jun 2019 22:44:39 +0000 (23:44 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Wed, 19 Jun 2019 22:44:39 +0000 (23:44 +0100)
Also, for the unit test, disable the two methods we use there
that can get called. The unintended side-effects of these two
methods was the only reason it used `@group Database`.
Removing that makes the test a bit faster as well.

Enforce this via MediaWikiServices for this suite to avoid an
untracked dependency slipping back in in the future.

Bug: T225730
Change-Id: I6c54466e9517d9899bc39f8f9bb946369c0a526d

includes/resourceloader/ResourceLoaderFileModule.php
tests/phpunit/ResourceLoaderTestCase.php
tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php

index 47c8987..7093ab1 100644 (file)
 
 /**
  * ResourceLoader module based on local JavaScript/CSS files.
+ *
+ * The following public methods can query the database:
+ *
+ * - getDefinitionSummary / … / ResourceLoaderModule::getFileDependencies.
+ * - getVersionHash / getDefinitionSummary / … / ResourceLoaderModule::getFileDependencies.
+ * - getStyles / ResourceLoaderModule::saveFileDependencies.
  */
 class ResourceLoaderFileModule extends ResourceLoaderModule {
 
index e5c0cbc..64693b0 100644 (file)
@@ -157,6 +157,12 @@ class ResourceLoaderTestModule extends ResourceLoaderModule {
        }
 }
 
+/**
+ * A more constrained and testable variant of ResourceLoaderFileModule.
+ *
+ * - Implements getLessVars() support.
+ * - Disables database persistance of discovered file dependencies.
+ */
 class ResourceLoaderFileTestModule extends ResourceLoaderFileModule {
        protected $lessVars = [];
 
@@ -172,6 +178,16 @@ class ResourceLoaderFileTestModule extends ResourceLoaderFileModule {
        public function getLessVars( ResourceLoaderContext $context ) {
                return $this->lessVars;
        }
+
+       /** @return array */
+       protected function getFileDependencies( ResourceLoaderContext $context ) {
+               // No-op
+               return [];
+       }
+
+       protected function saveFileDependencies( ResourceLoaderContext $context, $refs ) {
+               // No-op
+       }
 }
 
 class ResourceLoaderFileModuleTestingSubclass extends ResourceLoaderFileModule {
index 1585cbc..5be0f9b 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 
 /**
- * @group Database
  * @group ResourceLoader
  */
 class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
@@ -19,11 +18,14 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
                        }
                );
                $this->setService( 'SkinFactory', $skinFactory );
+
+               // This test is not expected to query any database
+               MediaWiki\MediaWikiServices::disableStorageBackend();
        }
 
        private static function getModules() {
                $base = [
-                       'localBasePath' => realpath( __DIR__ ),
+                       'localBasePath' => __DIR__,
                ];
 
                return [
@@ -229,12 +231,12 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
         */
        public function testMixedCssAnnotations() {
                $basePath = __DIR__ . '/../../data/css';
-               $testModule = new ResourceLoaderFileModule( [
+               $testModule = new ResourceLoaderFileTestModule( [
                        'localBasePath' => $basePath,
                        'styles' => [ 'test.css' ],
                ] );
                $testModule->setName( 'testing' );
-               $expectedModule = new ResourceLoaderFileModule( [
+               $expectedModule = new ResourceLoaderFileTestModule( [
                        'localBasePath' => $basePath,
                        'styles' => [ 'expected.css' ],
                ] );
@@ -319,7 +321,7 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
         */
        public function testBomConcatenation() {
                $basePath = __DIR__ . '/../../data/css';
-               $testModule = new ResourceLoaderFileModule( [
+               $testModule = new ResourceLoaderFileTestModule( [
                        'localBasePath' => $basePath,
                        'styles' => [ 'bom.css' ],
                ] );