Browse Source

minor #522 Test base class (keradus)

This PR was squashed before being merged into the 1.0.x-dev branch (closes #522).

Discussion
----------

Test base class

So many code was repeated again and again.
Hate it...

Commits
-------

80eca39 Test base class
Dariusz Rumiński 10 years ago
parent
commit
481d8477ca

+ 48 - 0
Symfony/CS/Tests/Fixer/AbstractFixerTestBase.php

@@ -0,0 +1,48 @@
+<?php
+
+/*
+ * This file is part of the PHP CS utility.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Symfony\CS\Tests\Fixer;
+
+/**
+ * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
+ */
+abstract class AbstractFixerTestBase extends \PHPUnit_Framework_TestCase
+{
+    protected function getFixer()
+    {
+        $fixerName = 'Symfony\CS\Fixer'.substr(get_called_class(), strlen(__NAMESPACE__), -strlen('Test'));
+
+        return new $fixerName();
+    }
+
+    protected function getTestFile($filename = __FILE__)
+    {
+        static $files = array();
+
+        if (!isset($files[$filename])) {
+            $files[$filename] = new \SplFileInfo($filename);
+        }
+
+        return $files[$filename];
+    }
+
+    protected function makeTest($expected, $input = null, \SplFileInfo $file = null)
+    {
+        $fixer = $this->getFixer();
+        $file = $file ?: $this->getTestFile();
+
+        if (null !== $input) {
+            $this->assertSame($expected, $fixer->fix($file, $input));
+        }
+
+        $this->assertSame($expected, $fixer->fix($file, $expected));
+    }
+}

+ 4 - 21
Symfony/CS/Tests/Fixer/All/ConcatWithoutSpacesFixerTest.php

@@ -11,23 +11,19 @@
 
 namespace Symfony\CS\Tests\Fixer\All;
 
-use Symfony\CS\Fixer\All\ConcatWithoutSpacesFixer as Fixer;
+use Symfony\CS\Tests\Fixer\AbstractFixerTestBase;
 
 /**
  * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  */
-class ConcatWithoutSpacesFixerTest extends \PHPUnit_Framework_TestCase
+class ConcatWithoutSpacesFixerTest extends AbstractFixerTestBase
 {
     /**
      * @dataProvider provideCases
      */
-    public function testFix($expected, $input)
+    public function testFix($expected, $input = null)
     {
-        $fixer = new Fixer();
-        $file = $this->getTestFile();
-
-        $this->assertSame($expected, $fixer->fix($file, $input));
-        $this->assertSame($expected, $fixer->fix($file, $expected));
+        $this->makeTest($expected, $input);
     }
 
     public function provideCases()
@@ -45,21 +41,8 @@ class ConcatWithoutSpacesFixerTest extends \PHPUnit_Framework_TestCase
             ),
             array(
                 '<?php $a = "foobar"
-    ."baz";',
-                '<?php $a = "foobar"
     ."baz";',
             ),
         );
     }
-
-    private function getTestFile($filename = __FILE__)
-    {
-        static $files = array();
-
-        if (!isset($files[$filename])) {
-            $files[$filename] = new \SplFileInfo($filename);
-        }
-
-        return $files[$filename];
-    }
 }

+ 45 - 53
Symfony/CS/Tests/Fixer/All/ControlSpacesFixerTest.php

@@ -11,45 +11,28 @@
 
 namespace Symfony\CS\Tests\Fixer\All;
 
-use Symfony\CS\Fixer\All\ControlSpacesFixer as Fixer;
+use Symfony\CS\Tests\Fixer\AbstractFixerTestBase;
 
-class ControlSpacesFixerTest extends \PHPUnit_Framework_TestCase
+class ControlSpacesFixerTest extends AbstractFixerTestBase
 {
     public function testFixControlsWithSuffixBrace()
     {
-        $fixer = new Fixer();
-
         $try = 'try{';
         $tryFixed = 'try {';
-        $this->assertSame($tryFixed, $fixer->fix($this->getTestFile(), $try));
-        $this->assertSame($tryFixed, $fixer->fix($this->getTestFile(), $tryFixed));
+
+        $this->makeTest($tryFixed, $try);
     }
 
     public function testFixControlsWithPrefixBraceAndParentheses()
     {
-        $fixer = new Fixer();
-
         $while = 'do { ... }while($test);';
         $whileFixed = 'do { ... } while ($test);';
-        $this->assertSame($whileFixed, $fixer->fix($this->getTestFile(), $while));
-        $this->assertSame($whileFixed, $fixer->fix($this->getTestFile(), $whileFixed));
-    }
 
-    /**
-     * @dataProvider testFixControlsWithParenthesesAndSuffixBraceProvider
-     */
-    public function testFixControlsWithParenthesesAndSuffixBrace($if, $ifFixed)
-    {
-        $fixer = new Fixer();
-
-        $this->assertSame($ifFixed, $fixer->fix($this->getTestFile(), $if));
-        $this->assertSame($ifFixed, $fixer->fix($this->getTestFile(), $ifFixed));
+        $this->makeTest($whileFixed, $while);
     }
 
     public function testFixControlClosingParenthesesKeepsIndentation()
     {
-        $fixer = new Fixer();
-
         $if = 'if(true === true
             && true === true
         )    {';
@@ -58,61 +41,70 @@ class ControlSpacesFixerTest extends \PHPUnit_Framework_TestCase
             && true === true
         ) {';
 
-        $this->assertSame($ifFixed, $fixer->fix($this->getTestFile(), $if));
-        $this->assertSame($ifFixed, $fixer->fix($this->getTestFile(), $ifFixed));
+        $this->makeTest($ifFixed, $if);
+    }
+
+    /**
+     * @dataProvider testFixControlsWithParenthesesAndSuffixBraceProvider
+     */
+    public function testFixControlsWithParenthesesAndSuffixBrace($expected, $input = null)
+    {
+        $this->makeTest($expected, $input);
     }
 
     public function testFixControlsWithParenthesesAndSuffixBraceProvider()
     {
         return array(
-            array('if($test){', 'if ($test) {'),
-            array('if( $test ){', 'if ($test) {'),
-            array('if  (   $test ){', 'if ($test) {'),
-            array('if  (($test1 || $test2) && $test3){', 'if (($test1 || $test2) && $test3) {'),
-            array('if(($test1 || $test2) && $test3){', 'if (($test1 || $test2) && $test3) {'),
-            array('if ($this->tesT ($test)) {', 'if ($this->tesT ($test)) {'),
-            array('if ($this->testtesT ($test)) {', 'if ($this->testtesT ($test)) {'),
+            array(
+                'if ($test) {',
+                'if($test){',
+            ),
+            array(
+                'if ($test) {',
+                'if( $test ){',
+            ),
+            array(
+                'if ($test) {',
+                'if  (   $test ){',
+            ),
+            array(
+                'if (($test1 || $test2) && $test3) {',
+                'if  (($test1 || $test2) && $test3){',
+            ),
+            array(
+                'if (($test1 || $test2) && $test3) {',
+                'if(($test1 || $test2) && $test3){',
+            ),
+            array(
+                'if ($this->tesT ($test)) {',
+            ),
+            array(
+                'if ($this->testtesT ($test)) {',
+            ),
         );
     }
 
     public function testFixControlsWithPrefixBraceAndSuffixBrace()
     {
-        $fixer = new Fixer();
-
         $else = '}else{';
         $elseFixed = '} else {';
-        $this->assertSame($elseFixed, $fixer->fix($this->getTestFile(), $else));
-        $this->assertSame($elseFixed, $fixer->fix($this->getTestFile(), $elseFixed));
+
+        $this->makeTest($elseFixed, $else);
     }
 
     public function testFixControlsWithPrefixBraceAndParenthesesAndSuffixBrace()
     {
-        $fixer = new Fixer();
-
         $elseif = '}elseif($test){';
         $elseifFixed = '} elseif ($test) {';
-        $this->assertSame($elseifFixed, $fixer->fix($this->getTestFile(), $elseif));
-        $this->assertSame($elseifFixed, $fixer->fix($this->getTestFile(), $elseifFixed));
+
+        $this->makeTest($elseifFixed, $elseif);
     }
 
     public function testFixControlsWithPrefixBraceAndParenthesesAndSuffixBraceInLambdas()
     {
-        $fixer = new Fixer();
-
         $use = ')use($test){';
         $useFixed = ') use ($test) {';
-        $this->assertSame($useFixed, $fixer->fix($this->getTestFile(), $use));
-        $this->assertSame($useFixed, $fixer->fix($this->getTestFile(), $useFixed));
-    }
-
-    private function getTestFile($filename = __FILE__)
-    {
-        static $files = array();
-
-        if (!isset($files[$filename])) {
-            $files[$filename] = new \SplFileInfo($filename);
-        }
 
-        return $files[$filename];
+        $this->makeTest($useFixed, $use);
     }
 }

+ 10 - 91
Symfony/CS/Tests/Fixer/All/ExtraEmptyLinesFixerTest.php

@@ -11,15 +11,12 @@
 
 namespace Symfony\CS\Tests\Fixer\All;
 
-use Symfony\CS\Fixer\All\ExtraEmptyLinesFixer;
+use Symfony\CS\Tests\Fixer\AbstractFixerTestBase;
 
-class ExtraEmptyLinesFixerTest extends \PHPUnit_Framework_TestCase
+class ExtraEmptyLinesFixerTest extends AbstractFixerTestBase
 {
     public function testFix()
     {
-        $fixer = new ExtraEmptyLinesFixer();
-        $file = $this->getTestFile();
-
         $expected = <<<'EOF'
 <?php
 $a = new Bar();
@@ -35,14 +32,11 @@ $a = new Bar();
 $a = new FooBaz();
 EOF;
 
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected, $input);
     }
 
     public function testFixWithManyEmptyLines()
     {
-        $fixer = new ExtraEmptyLinesFixer();
-        $file = $this->getTestFile();
-
         $expected = <<<'EOF'
 <?php
 $a = new Bar();
@@ -62,14 +56,11 @@ $a = new Bar();
 $a = new FooBaz();
 EOF;
 
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected, $input);
     }
 
     public function testFixWithHeredoc()
     {
-        $fixer = new ExtraEmptyLinesFixer();
-        $file = $this->getTestFile();
-
         $expected = '
 <?php
 $b = <<<TEXT
@@ -81,25 +72,11 @@ FooFoo
 TEXT;
 ';
 
-        $input = '
-<?php
-$b = <<<TEXT
-Foo TEXT
-Bar
-
-
-FooFoo
-TEXT;
-';
-
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected);
     }
 
     public function testFixWithNowdoc()
     {
-        $fixer = new ExtraEmptyLinesFixer();
-        $file = $this->getTestFile();
-
         $expected = '
 <?php
 $b = <<<\'TEXT\'
@@ -111,24 +88,11 @@ FooFoo
 TEXT;
 ';
 
-        $input = '
-<?php
-$b = <<<\'TEXT\'
-Foo TEXT;
-Bar1}
-
-
-FooFoo
-TEXT;
-';
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected);
     }
 
     public function testFixWithEncapsulatedNowdoc()
     {
-        $fixer = new ExtraEmptyLinesFixer();
-        $file = $this->getTestFile();
-
         $expected = '
 <?php
 $b = <<<\'TEXT\'
@@ -146,31 +110,11 @@ FooFoo
 TEXT;
 ';
 
-        $input = '
-<?php
-$b = <<<\'TEXT\'
-Foo TEXT
-Bar
-
-<<<\'TEMPLATE\'
-BarFooBar TEMPLATE
-
-
-TEMPLATE;
-
-
-FooFoo
-TEXT;
-';
-
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected);
     }
 
     public function testFixWithMultilineString()
     {
-        $fixer = new ExtraEmptyLinesFixer();
-        $file = $this->getTestFile();
-
         $expected = <<<'EOF'
 <?php
 $a = 'Foo
@@ -179,22 +123,11 @@ $a = 'Foo
 Bar';
 EOF;
 
-        $input = <<<'EOF'
-<?php
-$a = 'Foo
-
-
-Bar';
-EOF;
-
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected);
     }
 
     public function testFixWithTrickyMultilineStrings()
     {
-        $fixer = new ExtraEmptyLinesFixer();
-        $file = $this->getTestFile();
-
         $expected = <<<'EOF'
 <?php
 $a = 'Foo';
@@ -232,14 +165,11 @@ Here\'s an escaped quote '
 FooFoo';
 EOF;
 
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected, $input);
     }
 
     public function testFixWithCommentWithAQuote()
     {
-        $fixer = new ExtraEmptyLinesFixer();
-        $file = new \SplFileInfo(__FILE__);
-
         $expected = <<<'EOF'
 <?php
 $a = 'foo';
@@ -262,17 +192,6 @@ $b = 'foobar';
 $c = 'bar';
 EOF;
 
-        $this->assertSame($expected, $fixer->fix($file, $input));
-    }
-
-    private function getTestFile($filename = __FILE__)
-    {
-        static $files = array();
-
-        if (!isset($files[$filename])) {
-            $files[$filename] = new \SplFileInfo($filename);
-        }
-
-        return $files[$filename];
+        $this->makeTest($expected, $input);
     }
 }

+ 109 - 46
Symfony/CS/Tests/Fixer/All/IncludeFixerTest.php

@@ -11,66 +11,129 @@
 
 namespace Symfony\CS\Tests\Fixer\All;
 
-use Symfony\CS\Fixer\All\IncludeFixer as Fixer;
+use Symfony\CS\Tests\Fixer\AbstractFixerTestBase;
 
 /**
  * @author Саша Стаменковић <umpirsky@gmail.com>
  */
-class IncludeFixerTest extends \PHPUnit_Framework_TestCase
+class IncludeFixerTest extends AbstractFixerTestBase
 {
     /**
      * @dataProvider testFixProvider
      */
-    public function testFix($include, $includeFixed)
+    public function testFix($expected, $input = null)
     {
-        $fixer = new Fixer();
-
-        $this->assertSame($includeFixed, $fixer->fix($this->getTestFile(), $include));
-        $this->assertSame($includeFixed, $fixer->fix($this->getTestFile(), $includeFixed));
+        $this->makeTest($expected, $input);
     }
 
     public function testFixProvider()
     {
         return array(
-            array("<?php include   'foo.php';", "<?php include 'foo.php';"),
-            array("<?php include   'foo.php'  ;", "<?php include 'foo.php';"),
-            array("<?php include   ('foo.php')  ;", "<?php include 'foo.php';"),
-            array('<?php include (  "Buzz/foo-Bar.php" );', '<?php include "Buzz/foo-Bar.php";'),
-            array('<?php include (  "$buzz/foo-Bar.php" );', '<?php include "$buzz/foo-Bar.php";'),
-            array('<?php include (  "{$buzz}/foo-Bar.php" );', '<?php include "{$buzz}/foo-Bar.php";'),
-            array("<?php include('foo.php');", "<?php include 'foo.php';"),
-            array("<?php include_once( 'foo.php' );", "<?php include_once 'foo.php';"),
-            array('<?php require($foo ? "foo.php" : "bar.php");', '<?php require $foo ? "foo.php" : "bar.php";'),
-            array('<?php require($foo  ?  "foo.php"  :  "bar.php");', '<?php require $foo  ?  "foo.php"  :  "bar.php";'),
-            array("<?php return require_once  __DIR__.'foo.php';", "<?php return require_once __DIR__.'foo.php';"),
-            array("<?php \$foo = require_once  __DIR__.('foo.php');", "<?php \$foo = require_once __DIR__.('foo.php');"),
-            array("<?php     require_once  (__DIR__.('foo.php'));", "<?php     require_once __DIR__.('foo.php');"),
-            array("<?php     require_once  (__DIR__ . ('foo.php'));", "<?php     require_once __DIR__ . ('foo.php');"),
-            array("<?php require_once (dirname(__FILE__).'foo.php');", "<?php require_once dirname(__FILE__).'foo.php';"),
-            array('<?php ClassCollectionLoader::load(include($this->getCacheDir().\'classes.map\'), $this->getCacheDir(), $name, $this->debug, false, $extension);', '<?php ClassCollectionLoader::load(include($this->getCacheDir().\'classes.map\'), $this->getCacheDir(), $name, $this->debug, false, $extension);'),
-            array("<?php require_once '\".__DIR__.\"/../bootstrap.php';", "<?php require_once '\".__DIR__.\"/../bootstrap.php';"),
-            array("// require foo", "// require foo"),
-            array("<?php // require foo", "<?php // require foo"),
-            array("* require foo", "* require foo"),
-            array("<?php /* require foo */", "<?php /* require foo */"),
-            array('exit(\'POST must include "file"\');', 'exit(\'POST must include "file"\');'),
-            array('<?php include_once("foo/".CONSTANT."/bar.php");', '<?php include_once "foo/".CONSTANT."/bar.php";'),
-            array('<?php include_once("foo/".CONSTANT."/bar.php"); include_once("foo/".CONSTANT."/bar.php");', '<?php include_once "foo/".CONSTANT."/bar.php"; include_once "foo/".CONSTANT."/bar.php";'),
-            array('<?php include_once("foo/".CONSTANT."/bar.php"); $foo = "bar";', '<?php include_once "foo/".CONSTANT."/bar.php"; $foo = "bar";'),
-            array('<?php include_once("foo/".CONSTANT."/bar.php"); foo();', '<?php include_once "foo/".CONSTANT."/bar.php"; foo();'),
-            array('<?php include_once("foo/" . CONSTANT . "/bar.php");', '<?php include_once "foo/" . CONSTANT . "/bar.php";'),
-            array('<?php require($a ? $b : $c) . $d;', '<?php require ($a ? $b : $c) . $d;'),
+            array(
+                "<?php include 'foo.php';",
+                "<?php include   'foo.php';",
+            ),
+            array(
+                "<?php include 'foo.php';",
+                "<?php include   'foo.php'  ;",
+            ),
+            array(
+                "<?php include 'foo.php';",
+                "<?php include   ('foo.php')  ;",
+            ),
+            array(
+                '<?php include "Buzz/foo-Bar.php";',
+                '<?php include (  "Buzz/foo-Bar.php" );',
+            ),
+            array(
+                '<?php include "$buzz/foo-Bar.php";',
+                '<?php include (  "$buzz/foo-Bar.php" );',
+            ),
+            array(
+                '<?php include "{$buzz}/foo-Bar.php";',
+                '<?php include (  "{$buzz}/foo-Bar.php" );',
+            ),
+            array(
+                "<?php include 'foo.php';",
+                "<?php include('foo.php');",
+            ),
+            array(
+                "<?php include_once 'foo.php';",
+                "<?php include_once( 'foo.php' );",
+            ),
+            array(
+                '<?php require $foo ? "foo.php" : "bar.php";',
+                '<?php require($foo ? "foo.php" : "bar.php");',
+            ),
+            array(
+                '<?php require $foo  ?  "foo.php"  :  "bar.php";',
+                '<?php require($foo  ?  "foo.php"  :  "bar.php");',
+            ),
+            array(
+                "<?php return require_once __DIR__.'foo.php';",
+                "<?php return require_once  __DIR__.'foo.php';",
+            ),
+            array(
+                "<?php \$foo = require_once __DIR__.('foo.php');",
+                "<?php \$foo = require_once  __DIR__.('foo.php');",
+            ),
+            array(
+                "<?php     require_once __DIR__.('foo.php');",
+                "<?php     require_once  (__DIR__.('foo.php'));",
+            ),
+            array(
+                "<?php     require_once __DIR__ . ('foo.php');",
+                "<?php     require_once  (__DIR__ . ('foo.php'));",
+            ),
+            array(
+                "<?php require_once dirname(__FILE__).'foo.php';",
+                "<?php require_once (dirname(__FILE__).'foo.php');",
+            ),
+            array(
+                '<?php ClassCollectionLoader::load(include($this->getCacheDir().\'classes.map\'), $this->getCacheDir(), $name, $this->debug, false, $extension);',
+            ),
+            array(
+                "<?php require_once '\".__DIR__.\"/../bootstrap.php';",
+            ),
+            array(
+                "// require foo",
+            ),
+            array(
+                "<?php // require foo",
+            ),
+            array(
+                "* require foo",
+            ),
+            array(
+                "<?php /* require foo */",
+            ),
+            array(
+                'exit(\'POST must include "file"\');',
+            ),
+            array(
+                '<?php include_once "foo/".CONSTANT."/bar.php";',
+                '<?php include_once("foo/".CONSTANT."/bar.php");',
+            ),
+            array(
+                '<?php include_once "foo/".CONSTANT."/bar.php"; include_once "foo/".CONSTANT."/bar.php";',
+                '<?php include_once("foo/".CONSTANT."/bar.php"); include_once("foo/".CONSTANT."/bar.php");',
+            ),
+            array(
+                '<?php include_once "foo/".CONSTANT."/bar.php"; $foo = "bar";',
+                '<?php include_once("foo/".CONSTANT."/bar.php"); $foo = "bar";',
+            ),
+            array(
+                '<?php include_once "foo/".CONSTANT."/bar.php"; foo();',
+                '<?php include_once("foo/".CONSTANT."/bar.php"); foo();',
+            ),
+            array(
+                '<?php include_once "foo/" . CONSTANT . "/bar.php";',
+                '<?php include_once("foo/" . CONSTANT . "/bar.php");',
+            ),
+            array(
+                '<?php require ($a ? $b : $c) . $d;',
+                '<?php require($a ? $b : $c) . $d;',
+            ),
         );
     }
-
-    private function getTestFile($filename = __FILE__)
-    {
-        static $files = array();
-
-        if (!isset($files[$filename])) {
-            $files[$filename] = new \SplFileInfo($filename);
-        }
-
-        return $files[$filename];
-    }
 }

+ 4 - 24
Symfony/CS/Tests/Fixer/All/NewWithBracesFixerTest.php

@@ -11,26 +11,17 @@
 
 namespace Symfony\CS\Tests\Fixer\All;
 
-use Symfony\CS\Fixer\All\NewWithBracesFixer as Fixer;
+use Symfony\CS\Tests\Fixer\AbstractFixerTestBase;
 
 /**
  * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  */
-class NewWithBracesFixerTest extends \PHPUnit_Framework_TestCase
+class NewWithBracesFixerTest extends AbstractFixerTestBase
 {
-    public function makeTest($expected, $input)
-    {
-        $fixer = new Fixer();
-        $file = $this->getTestFile();
-
-        $this->assertSame($expected, $fixer->fix($file, $input));
-        $this->assertSame($expected, $fixer->fix($file, $expected));
-    }
-
     /**
      * @dataProvider provideStandardCases
      */
-    public function testStandard($expected, $input)
+    public function testStandard($expected, $input = null)
     {
         $this->makeTest($expected, $input);
     }
@@ -39,7 +30,7 @@ class NewWithBracesFixerTest extends \PHPUnit_Framework_TestCase
      * @dataProvider provide54Cases
      * @requires PHP 5.4
      */
-    public function test54($expected, $input)
+    public function test54($expected, $input = null)
     {
         $this->makeTest($expected, $input);
     }
@@ -88,15 +79,4 @@ class NewWithBracesFixerTest extends \PHPUnit_Framework_TestCase
             ),
         );
     }
-
-    private function getTestFile($filename = __FILE__)
-    {
-        static $files = array();
-
-        if (!isset($files[$filename])) {
-            $files[$filename] = new \SplFileInfo($filename);
-        }
-
-        return $files[$filename];
-    }
 }

+ 14 - 28
Symfony/CS/Tests/Fixer/All/NoTrailingCommaInSingLineArrayFixerTest.php

@@ -11,57 +11,43 @@
 
 namespace Symfony\CS\Tests\Fixer\All;
 
-use Symfony\CS\Fixer\All\NoTrailingCommaInSingLineArrayFixer as Fixer;
+use Symfony\CS\Tests\Fixer\AbstractFixerTestBase;
 
 /**
  * @author Sebastiaan Stok <s.stok@rollerscapes.net>
  */
-class NoTrailingCommaInSingLineArrayFixerTest extends \PHPUnit_Framework_TestCase
+class NoTrailingCommaInSingLineArrayFixerTest extends AbstractFixerTestBase
 {
     /**
      * @dataProvider provideExamples
      */
-    public function testFix($expected, $input)
+    public function testFix($expected, $input = null)
     {
-        $fixer = new Fixer();
-        $file = $this->getTestFile();
-
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected, $input);
     }
 
     public function provideExamples()
     {
         return array(
-            array('<?php $x = array();', '<?php $x = array();'),
-            array('<?php $x = array(());', '<?php $x = array(());'),
-            array('<?php $x = array("foo");', '<?php $x = array("foo");'),
+            array('<?php $x = array();'),
+            array('<?php $x = array(());'),
+            array('<?php $x = array("foo");'),
             array('<?php $x = array("foo");', '<?php $x = array("foo", );'),
-            array("<?php \$x = array(\n'foo', \n);", "<?php \$x = array(\n'foo', \n);"),
-            array("<?php \$x = array('foo', \n);", "<?php \$x = array('foo', \n);"),
+            array("<?php \$x = array(\n'foo', \n);"),
+            array("<?php \$x = array('foo', \n);"),
             array("<?php \$x = array(array('foo'), \n);", "<?php \$x = array(array('foo',), \n);"),
-            array("<?php \$x = array(array('foo',\n), \n);", "<?php \$x = array(array('foo',\n), \n);"),
+            array("<?php \$x = array(array('foo',\n), \n);"),
 
             // Short syntax
-            array('<?php $x = array([]);', '<?php $x = array([]);'),
-            array('<?php $x = [[]];', '<?php $x = [[]];'),
+            array('<?php $x = array([]);'),
+            array('<?php $x = [[]];'),
             array('<?php $x = ["foo"];', '<?php $x = ["foo",];'),
             array('<?php $x = bar(["foo"]);', '<?php $x = bar(["foo",]);'),
-            array("<?php \$x = bar(['foo'],\n]);", "<?php \$x = bar(['foo'],\n]);"),
-            array("<?php \$x = ['foo', \n];", "<?php \$x = ['foo', \n];"),
+            array("<?php \$x = bar(['foo'],\n]);"),
+            array("<?php \$x = ['foo', \n];"),
             array('<?php $x = array([]);', '<?php $x = array([],);'),
             array('<?php $x = [[]];', '<?php $x = [[],];'),
             array('<?php $x = [$y[]];', '<?php $x = [$y[],];'),
         );
     }
-
-    private function getTestFile($filename = __FILE__)
-    {
-        static $files = array();
-
-        if (!isset($files[$filename])) {
-            $files[$filename] = new \SplFileInfo($filename);
-        }
-
-        return $files[$filename];
-    }
 }

+ 38 - 35
Symfony/CS/Tests/Fixer/All/ObjectOperatorFixerTest.php

@@ -11,39 +11,57 @@
 
 namespace Symfony\CS\Tests\Fixer\All;
 
-use Symfony\CS\Fixer\All\ObjectOperatorFixer as Fixer;
+use Symfony\CS\Tests\Fixer\AbstractFixerTestBase;
 
 /**
  * @author Farhad Safarov <farhad.safarov@gmail.com>
  */
-class ObjectOperatorFixerTest extends \PHPUnit_Framework_TestCase
+class ObjectOperatorFixerTest extends AbstractFixerTestBase
 {
     /**
-     * @dataProvider testFixObjectOperatorSpaces
+     * @dataProvider provideCases
      */
-    public function testFixControlsWithParenthesesAndSuffixBrace($toBeFixed, $expected)
+    public function testFix($expected, $input = null)
     {
-        $fixer = new Fixer();
-
-        $this->assertSame($expected, $fixer->fix($this->getTestFile(), $toBeFixed));
+        $this->makeTest($expected, $input);
     }
 
-    public function testFixObjectOperatorSpaces()
+    public function provideCases()
     {
         return array(
-            array('<?php $object   ->method();', '<?php $object->method();'),
-            array('<?php $object   ->   method();', '<?php $object->method();'),
-            array('<?php $object->   method();', '<?php $object->method();'),
-            array('<?php $object	->method();', '<?php $object->method();'),
-            array('<?php $object->	method();', '<?php $object->method();'),
-            array('<?php $object	->	method();', '<?php $object->method();'),
-            array('<?php $object->method();', '<?php $object->method();'),
-            array('<?php echo "use it as you want";', '<?php echo "use it as you want";'),
+            array(
+                '<?php $object->method();',
+                '<?php $object   ->method();',
+            ),
+            array(
+                '<?php $object->method();',
+                '<?php $object   ->   method();',
+            ),
+            array(
+                '<?php $object->method();',
+                '<?php $object->   method();',
+            ),
+            array(
+                '<?php $object->method();',
+                '<?php $object	->method();',
+            ),
+            array(
+                '<?php $object->method();',
+                '<?php $object->	method();',
+            ),
+            array(
+                '<?php $object->method();',
+                '<?php $object	->	method();',
+            ),
+            array(
+                '<?php $object->method();',
+            ),
+            array(
+                '<?php echo "use it as -> you want";',
+            ),
             // Ensure that doesn't break chained multi-line statements
-            array('<?php $object->method()
-                        ->method2()
-                        ->method3();',
-                    '<?php $object->method()
+            array(
+                '<?php $object->method()
                         ->method2()
                         ->method3();',
             ),
@@ -51,23 +69,8 @@ class ObjectOperatorFixerTest extends \PHPUnit_Framework_TestCase
                 '<?php $this
              ->add()
              // Some comment
-             ->delete();',
-                 '<?php $this
-             ->add()
-             // Some comment
              ->delete();',
             ),
         );
     }
-
-    private function getTestFile($filename = __FILE__)
-    {
-        static $files = array();
-
-        if (!isset($files[$filename])) {
-            $files[$filename] = new \SplFileInfo($filename);
-        }
-
-        return $files[$filename];
-    }
 }

+ 10 - 45
Symfony/CS/Tests/Fixer/All/PhpdocParamsAlignmentFixerTest.php

@@ -11,15 +11,12 @@
 
 namespace Symfony\CS\Tests\Fixer\All;
 
-use Symfony\CS\Fixer\All\PhpdocParamsAlignmentFixer;
+use Symfony\CS\Tests\Fixer\AbstractFixerTestBase;
 
-class PhpdocParamsAlignmentFixerTest extends \PHPUnit_Framework_TestCase
+class PhpdocParamsAlignmentFixerTest extends AbstractFixerTestBase
 {
     public function testFix()
     {
-        $fixer = new PhpdocParamsAlignmentFixer();
-        $file = $this->getTestFile();
-
         $expected = <<<'EOF'
 <?php
     /**
@@ -44,14 +41,11 @@ EOF;
 
 EOF;
 
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected, $input);
     }
 
     public function testFixMultiLineDesc()
     {
-        $fixer = new PhpdocParamsAlignmentFixer();
-        $file = $this->getTestFile();
-
         $expected = <<<'EOF'
 <?php
     /**
@@ -82,14 +76,11 @@ EOF;
 
 EOF;
 
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected, $input);
     }
 
     public function testFixMultiLineDescWithThrows()
     {
-        $fixer = new PhpdocParamsAlignmentFixer();
-        $file = $this->getTestFile();
-
         $expected = <<<'EOF'
 <?php
     /**
@@ -130,14 +121,11 @@ EOF;
 
 EOF;
 
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected, $input);
     }
 
     public function testFixWithReturnAndThrows()
     {
-        $fixer = new PhpdocParamsAlignmentFixer();
-        $file = $this->getTestFile();
-
         $expected = <<<'EOF'
 <?php
     /**
@@ -160,7 +148,7 @@ EOF;
 
 EOF;
 
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected, $input);
     }
 
     /**
@@ -169,9 +157,6 @@ EOF;
      */
     public function testFixThreeParamsWithReturn()
     {
-        $fixer = new PhpdocParamsAlignmentFixer();
-        $file = $this->getTestFile();
-
         $expected = <<<'EOF'
 <?php
     /**
@@ -194,14 +179,11 @@ EOF;
 
 EOF;
 
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected, $input);
     }
 
     public function testFixOnlyReturn()
     {
-        $fixer = new PhpdocParamsAlignmentFixer();
-        $file = $this->getTestFile();
-
         $expected = <<<'EOF'
 <?php
     /**
@@ -218,14 +200,11 @@ EOF;
 
 EOF;
 
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected, $input);
     }
 
     public function testReturnWithDollarThis()
     {
-        $fixer = new PhpdocParamsAlignmentFixer();
-        $file = $this->getTestFile();
-
         $expected = <<<'EOF'
 <?php
     /**
@@ -244,14 +223,11 @@ EOF;
 
 EOF;
 
-        $this->assertSame($expected, $fixer->fix($file, $input));
+        $this->makeTest($expected, $input);
     }
 
     public function testCustomAnnotationsStayUntouched()
     {
-        $fixer = new PhpdocParamsAlignmentFixer();
-        $file = $this->getTestFile();
-
         $expected = <<<'EOF'
 <?php
     /**
@@ -270,17 +246,6 @@ EOF;
 
 EOF;
 
-        $this->assertSame($expected, $fixer->fix($file, $input));
-    }
-
-    private function getTestFile($filename = __FILE__)
-    {
-        static $files = array();
-
-        if (!isset($files[$filename])) {
-            $files[$filename] = new \SplFileInfo($filename);
-        }
-
-        return $files[$filename];
+        $this->makeTest($expected, $input);
     }
 }

+ 4 - 68
Symfony/CS/Tests/Fixer/All/ReturnStatementsFixerTest.php

@@ -11,22 +11,19 @@
 
 namespace Symfony\CS\Tests\Fixer\All;
 
-use Symfony\CS\Fixer\All\ReturnStatementsFixer as Fixer;
+use Symfony\CS\Tests\Fixer\AbstractFixerTestBase;
 
 /**
  * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  */
-class ReturnStatementsFixerTest extends \PHPUnit_Framework_TestCase
+class ReturnStatementsFixerTest extends AbstractFixerTestBase
 {
     /**
      * @dataProvider provideCases
      */
-    public function testFix($expected, $input)
+    public function testFix($expected, $input = null)
     {
-        $fixer = new Fixer();
-
-        $this->assertSame($expected, $fixer->fix($this->getTestFile(), $input));
-        $this->assertSame($expected, $fixer->fix($this->getTestFile(), $expected));
+        $this->makeTest($expected, $input);
     }
 
     public function provideCases()
@@ -35,9 +32,6 @@ class ReturnStatementsFixerTest extends \PHPUnit_Framework_TestCase
             array(
                 '
 $a = $a;
-return $a;',
-                '
-$a = $a;
 return $a;',
             ),
             array(
@@ -78,20 +72,12 @@ return $c;',
                 '<?php
     if (true) {
         return 1;
-    }',
-                '<?php
-    if (true) {
-        return 1;
     }',
             ),
             array(
                 '<?php
     if (true)
         return 1;
-    ',
-                '<?php
-    if (true)
-        return 1;
     ',
             ),
             array(
@@ -100,12 +86,6 @@ return $c;',
         return 1;
     } else {
         return 2;
-    }',
-                '<?php
-    if (true) {
-        return 1;
-    } else {
-        return 2;
     }',
             ),
             array(
@@ -114,12 +94,6 @@ return $c;',
         return 1;
     else
         return 2;
-    ',
-                '<?php
-    if (true)
-        return 1;
-    else
-        return 2;
     ',
             ),
             array(
@@ -128,12 +102,6 @@ return $c;',
         return 1;
     } elseif (false) {
         return 2;
-    }',
-                '<?php
-    if (true) {
-        return 1;
-    } elseif (false) {
-        return 2;
     }',
             ),
             array(
@@ -142,29 +110,15 @@ return $c;',
         return 1;
     elseif (false)
         return 2;
-    ',
-                '<?php
-    if (true)
-        return 1;
-    elseif (false)
-        return 2;
     ',
             ),
             array(
                 '<?php
-    throw new Exception("return true;");',
-                '<?php
     throw new Exception("return true;");',
             ),
             array(
                 '<?php
     function foo()
-    {
-        // comment
-        return "foo";
-    }',
-                '<?php
-    function foo()
     {
         // comment
         return "foo";
@@ -176,27 +130,9 @@ return $c;',
     {
         // comment
 
-        return "bar";
-    }',
-                '<?php
-    function foo()
-    {
-        // comment
-
         return "bar";
     }',
             ),
         );
     }
-
-    private function getTestFile($filename = __FILE__)
-    {
-        static $files = array();
-
-        if (!isset($files[$filename])) {
-            $files[$filename] = new \SplFileInfo($filename);
-        }
-
-        return $files[$filename];
-    }
 }

Some files were not shown because too many files changed in this diff