Jeroen De Dauw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/110893

Change subject: Prevent new usage of deprecated Settings class
......................................................................

Prevent new usage of deprecated Settings class

Change-Id: I43a7f34ed1bd5be99becaad8338a3ba59f500284
---
A lib/tests/phpunit/NoBadDependencyUsageTest.php
D lib/tests/phpunit/NoClientOrRepoUsageTest.php
2 files changed, 88 insertions(+), 61 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/93/110893/1

diff --git a/lib/tests/phpunit/NoBadDependencyUsageTest.php 
b/lib/tests/phpunit/NoBadDependencyUsageTest.php
new file mode 100644
index 0000000..873631a
--- /dev/null
+++ b/lib/tests/phpunit/NoBadDependencyUsageTest.php
@@ -0,0 +1,88 @@
+<?php
+
+namespace Wikibase\Lib\Test;
+
+use RecursiveDirectoryIterator;
+use RecursiveIteratorIterator;
+use SplFileInfo;
+
+/**
+ * @group WikibaseLib
+ * @group Wikibase
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class NoBadDependencyUsageTest extends \PHPUnit_Framework_TestCase {
+
+       public function testNoRepoUsageInLib() {
+               // Increasing this allowance is forbidden
+               $this->assertStringNotInLib( 'WikibaseRepo' . '::', 4 );
+               $this->assertStringNotInLib( 'Wikibase\\Repo\\', 4 );
+       }
+
+       public function testNoClientUsageInLib() {
+               // Increasing this allowance is forbidden
+               $this->assertStringNotInLib( 'WikibaseClient' . '::', 3 );
+               $this->assertStringNotInLib( 'Wikibase\\Client\\', 3 );
+       }
+
+       public function testNoSettingsUsageOutsideLib() {
+               // Increasing this allowance is forbidden
+               $this->assertStringNotInRepo( 'Settings::', 21 );
+               $this->assertStringNotInClient( 'Settings::', 16 );
+       }
+
+       private function assertStringNotInLib( $string, $maxAllowance ) {
+               $this->assertStringNotInDir(
+                       $string,
+                       __DIR__ . '/../../',
+                       $maxAllowance
+               );
+       }
+       private function assertStringNotInClient( $string, $maxAllowance ) {
+               $this->assertStringNotInDir(
+                       $string,
+                       __DIR__ . '/../../../client/',
+                       $maxAllowance
+               );
+       }
+
+       private function assertStringNotInRepo( $string, $maxAllowance ) {
+               $this->assertStringNotInDir(
+                       $string,
+                       __DIR__ . '/../../../repo/',
+                       $maxAllowance
+               );
+       }
+
+       private function assertStringNotInDir( $string, $dirs, $maxAllowance ) {
+               $dirs = (array)$dirs;
+
+               foreach ( $dirs as $dir ) {
+                       $this->assertLessThanOrEqual(
+                               $maxAllowance,
+                               $this->countStringInDir( $string, $dir ),
+                               'You are not allowed to use ' . $string . ' in 
this component'
+                       );
+               }
+       }
+
+       private function countStringInDir( $string, $dir ) {
+               $count = 0;
+               $directoryIterator = new RecursiveDirectoryIterator( $dir );
+
+               /**
+                * @var SplFileInfo $fileInfo
+                */
+               foreach ( new RecursiveIteratorIterator( $directoryIterator ) 
as $fileInfo ) {
+                       if ( $fileInfo->isFile() && substr( 
$fileInfo->getFilename(), -4 ) === '.php' ) {
+                               if ( stripos( file_get_contents( 
$fileInfo->getPathname() ), $string ) !== false ) {
+                                       $count++;
+                               }
+                       }
+               }
+
+               return $count;
+       }
+
+}
diff --git a/lib/tests/phpunit/NoClientOrRepoUsageTest.php 
b/lib/tests/phpunit/NoClientOrRepoUsageTest.php
deleted file mode 100644
index 7d17230..0000000
--- a/lib/tests/phpunit/NoClientOrRepoUsageTest.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-
-namespace Wikibase\Lib\Test;
-
-use RecursiveDirectoryIterator;
-use RecursiveIteratorIterator;
-use SplFileInfo;
-
-/**
- * @group WikibaseLib
- * @group Wikibase
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-class NoClientOrRepoUsageTest extends \PHPUnit_Framework_TestCase {
-
-       public function testNoRepoUsage() {
-               // Increasing this allowance is forbidden
-               $this->assertStringNotInLib( 'WikibaseRepo' . '::', 4 );
-               $this->assertStringNotInLib( 'Wikibase\\Repo\\', 4 );
-       }
-
-       public function testNoClientUsage() {
-               // Increasing this allowance is forbidden
-               $this->assertStringNotInLib( 'WikibaseClient' . '::', 3 );
-               $this->assertStringNotInLib( 'Wikibase\\Client\\', 3 );
-       }
-
-       public function assertStringNotInLib( $string, $maxAllowance = 0 ) {
-               $dirs = array(
-                       __DIR__ . '/../../'
-               );
-
-               foreach ( $dirs as $dir ) {
-                       $this->assertLessThanOrEqual(
-                               $maxAllowance,
-                               $this->countStringInDir( $string, $dir ),
-                               'You are not allowed to use Repo or Client code 
in Lib!'
-                       );
-               }
-       }
-
-       public function countStringInDir( $string, $dir ) {
-               $count = 0;
-               $directoryIterator = new RecursiveDirectoryIterator( $dir );
-
-               /**
-                * @var SplFileInfo $fileInfo
-                */
-               foreach ( new RecursiveIteratorIterator( $directoryIterator ) 
as $fileInfo ) {
-                       if ( $fileInfo->isFile() && substr( 
$fileInfo->getFilename(), -4 ) === '.php' ) {
-                               if ( stripos( file_get_contents( 
$fileInfo->getPathname() ), $string ) !== false ) {
-                                       $count++;
-                               }
-                       }
-               }
-
-               return $count;
-       }
-
-}

-- 
To view, visit https://gerrit.wikimedia.org/r/110893
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I43a7f34ed1bd5be99becaad8338a3ba59f500284
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to