Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/88130
Change subject: Add NoClientOrRepoUsageTest ...................................................................... Add NoClientOrRepoUsageTest Change-Id: Ia875be04ac551ce7e947188c5f3e34e663a7b060 --- A lib/tests/phpunit/NoClientOrRepoUsageTest.php 1 file changed, 58 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/30/88130/1 diff --git a/lib/tests/phpunit/NoClientOrRepoUsageTest.php b/lib/tests/phpunit/NoClientOrRepoUsageTest.php new file mode 100644 index 0000000..d5ecf2c --- /dev/null +++ b/lib/tests/phpunit/NoClientOrRepoUsageTest.php @@ -0,0 +1,58 @@ +<?php + +namespace Wikibase\Lib\Test; + +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use SplFileInfo; + +/** + * @group WikibaseLib + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + */ +class NoClientOrRepoUsageTest extends \PHPUnit_Framework_TestCase { + + public function testNoRepoUsage() { + // Increasing of this allowance is forbidden + $this->assertStringNotInLib( 'WikibaseRepo' . '::', 4 ); + } + + public function testNoClientUsage() { + // Increasing of this allowance is forbidden + $this->assertStringNotInLib( 'WikibaseClient' . '::', 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/88130 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia875be04ac551ce7e947188c5f3e34e663a7b060 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits