[MediaWiki-commits] [Gerrit] Add tests for existing custom sniffs - change (mediawiki...codesniffer)
jenkins-bot has submitted this change and it was merged. Change subject: Add tests for existing custom sniffs .. Add tests for existing custom sniffs Change-Id: I875b366b5bb273323a5faedcd65f1c2978a33d70 --- A MediaWiki/Tests/MediaWikiStandardTest.php A MediaWiki/Tests/files/NamingConventions/case_global_name_fail.php A MediaWiki/Tests/files/NamingConventions/wg_global_name_fail.php A MediaWiki/Tests/files/generic_pass.php M README.md A TestHelper.php A phpunit.bootstrap.php A phpunit.xml.dist 8 files changed, 322 insertions(+), 1 deletion(-) Approvals: Hashar: Looks good to me, approved jenkins-bot: Verified diff --git a/MediaWiki/Tests/MediaWikiStandardTest.php b/MediaWiki/Tests/MediaWikiStandardTest.php new file mode 100644 index 000..e45aadb --- /dev/null +++ b/MediaWiki/Tests/MediaWikiStandardTest.php @@ -0,0 +1,92 @@ +https://github.com/cakephp/cakephp-codesniffer/blob/015919e55049e696eef9e518026e2d9abcdba722/CakePHP/tests/CakePHPStandardTest.php + * + * @license MIT + * CakePHP(tm) : The Rapid Development PHP Framework (http://cakephp.org) + * Copyright (c) 2005-2013, Cake Software Foundation, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * @author Adam Shorland + * Modifications + * - Rename appropriatly + * - Adapt $this->helper->runPhpCs call to pass second parameter $standard + */ +class MediaWikiStandardTest extends PHPUnit_Framework_TestCase { + + /** +* @var TestHelper +*/ + private $helper; + + public function setUp() { + parent::setUp(); + if (empty($this->helper)) { + $this->helper = new TestHelper(); + } + } + + /** +* testFiles +* +* Run simple syntax checks, if the filename ends with pass.php - expect it to pass +*/ + public static function testProvider() { + $tests = array(); + + $standard = dirname(dirname(__FILE__)); + + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/files')); + foreach ($iterator as $dir) { + if ($dir->isDir()) { + continue; + } + + $file = $dir->getPathname(); + $expectPass = (substr($file, -8) === 'pass.php'); + $tests[] = array( + $file, + $standard, + $expectPass + ); + } + return $tests; + } + + /** +* _testFile +* +* @dataProvider testProvider +* +* @param string $file +* @param string $standard +* @param boolean $expectPass +*/ + public function testFile($file, $standard, $expectPass) { + $outputStr = $this->helper->runPhpCs($file, $standard); + if ($expectPass) { + $this->assertNotRegExp( + "/FOUND \d+ ERROR/", + $outputStr, + basename($file) . ' - expected to pass with no errors, some were reported. ' + ); + } else { + $this->assertRegExp( + "/FOUND \d+ ERROR/", + $outputStr, + basename($file) . ' - expected failures, none reported. ' + ); + } + } + +} \ No newline at end of file diff --git a/MediaWiki/Tests/files/NamingConventions/case_global_name_fail.php b/MediaWiki/Tests/files/NamingConventions/case_global_name_fail.php new file mode 100644 index 000..f6488a9 --- /dev/null +++ b/MediaWiki/Tests/files/NamingConventions/case_global_name_fail.php @@ -0,0 +1,6 @@ +https://www.mediawiki.org/wiki/Manual:Coding_conventions + +/** + * @param $outputtype + * @param null $ts + * @return null + */ +function wfTimestampOrNull( $outputtype = TS_UNIX, $ts = null ) { + if ( is_null( $ts ) ) { + return null; + } else { + return wfTimestamp( $outputtype, $ts ); + } +} + +$wgAutopromote = array( + 'autoconfirmed' => array( '&', + arr
[MediaWiki-commits] [Gerrit] Add tests for existing custom sniffs - change (mediawiki...codesniffer)
Addshore has uploaded a new change for review. https://gerrit.wikimedia.org/r/154276 Change subject: Add tests for existing custom sniffs .. Add tests for existing custom sniffs Change-Id: I875b366b5bb273323a5faedcd65f1c2978a33d70 --- A MediaWiki/Tests/MediaWikiTest.php A MediaWiki/Tests/files/NamingConventions/case_global_name_fail.php A MediaWiki/Tests/files/NamingConventions/wg_global_name_fail.php A MediaWiki/Tests/files/generic_pass.php M MediaWikiBreaks/Tests/MediaWikiBreaksTest.php M phpunit.xml.dist 6 files changed, 131 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/codesniffer refs/changes/76/154276/1 diff --git a/MediaWiki/Tests/MediaWikiTest.php b/MediaWiki/Tests/MediaWikiTest.php new file mode 100644 index 000..e45aadb --- /dev/null +++ b/MediaWiki/Tests/MediaWikiTest.php @@ -0,0 +1,92 @@ +https://github.com/cakephp/cakephp-codesniffer/blob/015919e55049e696eef9e518026e2d9abcdba722/CakePHP/tests/CakePHPStandardTest.php + * + * @license MIT + * CakePHP(tm) : The Rapid Development PHP Framework (http://cakephp.org) + * Copyright (c) 2005-2013, Cake Software Foundation, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * @author Adam Shorland + * Modifications + * - Rename appropriatly + * - Adapt $this->helper->runPhpCs call to pass second parameter $standard + */ +class MediaWikiStandardTest extends PHPUnit_Framework_TestCase { + + /** +* @var TestHelper +*/ + private $helper; + + public function setUp() { + parent::setUp(); + if (empty($this->helper)) { + $this->helper = new TestHelper(); + } + } + + /** +* testFiles +* +* Run simple syntax checks, if the filename ends with pass.php - expect it to pass +*/ + public static function testProvider() { + $tests = array(); + + $standard = dirname(dirname(__FILE__)); + + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/files')); + foreach ($iterator as $dir) { + if ($dir->isDir()) { + continue; + } + + $file = $dir->getPathname(); + $expectPass = (substr($file, -8) === 'pass.php'); + $tests[] = array( + $file, + $standard, + $expectPass + ); + } + return $tests; + } + + /** +* _testFile +* +* @dataProvider testProvider +* +* @param string $file +* @param string $standard +* @param boolean $expectPass +*/ + public function testFile($file, $standard, $expectPass) { + $outputStr = $this->helper->runPhpCs($file, $standard); + if ($expectPass) { + $this->assertNotRegExp( + "/FOUND \d+ ERROR/", + $outputStr, + basename($file) . ' - expected to pass with no errors, some were reported. ' + ); + } else { + $this->assertRegExp( + "/FOUND \d+ ERROR/", + $outputStr, + basename($file) . ' - expected failures, none reported. ' + ); + } + } + +} \ No newline at end of file diff --git a/MediaWiki/Tests/files/NamingConventions/case_global_name_fail.php b/MediaWiki/Tests/files/NamingConventions/case_global_name_fail.php new file mode 100644 index 000..f6488a9 --- /dev/null +++ b/MediaWiki/Tests/files/NamingConventions/case_global_name_fail.php @@ -0,0 +1,6 @@ +foo; + } + + private function someFunction( FooBar $baz ) { + $foo = array( + $baz, + 'memememememememee', + ); + $cat = array_merge( $foo, array( 'barn', 'door' ) ); + return $cat; + } +} diff --git a/MediaWikiBreaks/Tests/MediaWikiBreaksTest.php b/MediaWikiBreaks/Tests/MediaWikiBreaksTest