Thiemo Mättig (WMDE) has uploaded a new change for review.

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

Change subject: Streamline and simplify tests recursively scanning directories
......................................................................

Streamline and simplify tests recursively scanning directories

Main changes:
* Do not use case-insensitive search.
* Move code out of loops if possible.
* Drop unused features.

Change-Id: I75afc7ffa79194c4fe8d8aa36b80fb5dbf14b76d
---
M lib/tests/phpunit/NoBadDependencyUsageTest.php
M lib/tests/phpunit/PHPUnitTestsHaveGroupWikibaseTest.php
2 files changed, 25 insertions(+), 20 deletions(-)


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

diff --git a/lib/tests/phpunit/NoBadDependencyUsageTest.php 
b/lib/tests/phpunit/NoBadDependencyUsageTest.php
index 6d48a7b..e2a5be7 100644
--- a/lib/tests/phpunit/NoBadDependencyUsageTest.php
+++ b/lib/tests/phpunit/NoBadDependencyUsageTest.php
@@ -28,26 +28,24 @@
                $this->assertStringNotInLib( 'Wikibase\\Client\\', 2 );
        }
 
+       /**
+        * @param string $string
+        * @param int $maxAllowance
+        */
        private function assertStringNotInLib( $string, $maxAllowance ) {
-               $this->assertStringNotInDir(
-                       $string,
-                       __DIR__ . '/../../',
-                       $maxAllowance
+               $this->assertLessThanOrEqual(
+                       $maxAllowance,
+                       $this->countStringInDir( $string, __DIR__ . '/../../' ),
+                       'You are not allowed to use ' . $string . ' in this 
component'
                );
        }
 
-       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'
-                       );
-               }
-       }
-
+       /**
+        * @param string $string
+        * @param string $dir
+        *
+        * @return int
+        */
        private function countStringInDir( $string, $dir ) {
                $count = 0;
                $directoryIterator = new RecursiveDirectoryIterator( $dir );
@@ -60,7 +58,7 @@
                                $text = file_get_contents( 
$fileInfo->getPathname() );
                                $text = preg_replace( '@/\*.*?\*/@s', '', $text 
);
 
-                               if ( stripos( $text, $string ) !== false ) {
+                               if ( strpos( $text, $string ) !== false ) {
                                        $count++;
                                }
                        }
diff --git a/lib/tests/phpunit/PHPUnitTestsHaveGroupWikibaseTest.php 
b/lib/tests/phpunit/PHPUnitTestsHaveGroupWikibaseTest.php
index 37ffc83..d0501de 100644
--- a/lib/tests/phpunit/PHPUnitTestsHaveGroupWikibaseTest.php
+++ b/lib/tests/phpunit/PHPUnitTestsHaveGroupWikibaseTest.php
@@ -44,8 +44,14 @@
                ];
        }
 
+       /**
+        * @param string $string
+        * @param string $dir
+        *
+        * @return string[]
+        */
        private function getTestFilesWithoutGroup( $string, $dir ) {
-               $string = '@group ' . $string;
+               $pattern = '/@group ' . preg_quote( $string, '/' ) . '\b/';
                $files = [];
                $directoryIterator = new RecursiveDirectoryIterator( $dir );
 
@@ -55,12 +61,13 @@
                foreach ( new RecursiveIteratorIterator( $directoryIterator ) 
as $fileInfo ) {
                        if ( $fileInfo->isFile() && substr( 
$fileInfo->getFilename(), -8 ) === 'Test.php' ) {
                                $text = file_get_contents( 
$fileInfo->getPathname() );
-                               if ( stripos( $text, 'abstract class' ) !== 
false ) {
+
+                               if ( strpos( $text, 'abstract class' ) !== 
false ) {
                                        // Ignore abstract base classes.
                                        continue;
                                }
 
-                               if ( preg_match( '@' . preg_quote( $string, '@' 
) . '[^\w]@i', $text ) === 0 ) {
+                               if ( preg_match( $pattern, $text ) === 0 ) {
                                        $files[] = $fileInfo->getPathname();
                                }
                        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I75afc7ffa79194c4fe8d8aa36b80fb5dbf14b76d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

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

Reply via email to