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 0000000..e45aadb
--- /dev/null
+++ b/MediaWiki/Tests/MediaWikiTest.php
@@ -0,0 +1,92 @@
+<?php
+/**
+ * This file was copied from CakePhps codesniffer tests before being modified
+ * 
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 0000000..f6488a9
--- /dev/null
+++ b/MediaWiki/Tests/files/NamingConventions/case_global_name_fail.php
@@ -0,0 +1,6 @@
+<?php
+
+function fooFoo () {
+       // The below should have capital after wg
+       global $wgsomething;
+}
\ No newline at end of file
diff --git a/MediaWiki/Tests/files/NamingConventions/wg_global_name_fail.php 
b/MediaWiki/Tests/files/NamingConventions/wg_global_name_fail.php
new file mode 100644
index 0000000..ba12d41
--- /dev/null
+++ b/MediaWiki/Tests/files/NamingConventions/wg_global_name_fail.php
@@ -0,0 +1,6 @@
+<?php
+
+function fooFoo () {
+       // The below should start with wg...
+       global $someotherglobal;
+}
\ No newline at end of file
diff --git a/MediaWiki/Tests/files/generic_pass.php 
b/MediaWiki/Tests/files/generic_pass.php
new file mode 100644
index 0000000..89696cf
--- /dev/null
+++ b/MediaWiki/Tests/files/generic_pass.php
@@ -0,0 +1,23 @@
+<?php
+
+class FooBar extends BarBaz implements SomethingSomewhere {
+
+       private $foo = 'halalalalalaa';
+
+       public $var;
+
+       public function fooBarBaz( $par ) {
+               global $wgBarBarBar;
+               $foo = $par;
+               return $foo + $wgBarBarBar + $this->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.php
index a67a812..94fd33a 100644
--- a/MediaWikiBreaks/Tests/MediaWikiBreaksTest.php
+++ b/MediaWikiBreaks/Tests/MediaWikiBreaksTest.php
@@ -22,7 +22,7 @@
  *  - Rename appropriatly
  *  - Adapt $this->helper->runPhpCs call to pass second parameter $standard
  */
-class MediawikiStandardTest extends PHPUnit_Framework_TestCase {
+class MediaWikiBreaksStandardTest extends PHPUnit_Framework_TestCase {
 
        /**
         * @var TestHelper
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 54b962f..fe48dbe 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -9,6 +9,9 @@
                 verbose="false"
                 bootstrap="./phpunit.bootstrap.php">
        <testsuites>
+               <testsuite name="phpcs/MediaWiki">
+                       <file>./MediaWiki/Tests/MediaWikiTest.php</file>
+               </testsuite>
                <testsuite name="phpcs/MediaWikiBreaks">
                        
<file>./MediaWikiBreaks/Tests/MediaWikiBreaksTest.php</file>
                </testsuite>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I875b366b5bb273323a5faedcd65f1c2978a33d70
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/tools/codesniffer
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>

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

Reply via email to