Browse Source

Unify Reporter tests

Dariusz Ruminski 7 years ago
parent
commit
96d6ecd9e6

+ 203 - 0
tests/Report/AbstractReporterTestCase.php

@@ -0,0 +1,203 @@
+<?php
+
+/*
+ * This file is part of PHP CS Fixer.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace PhpCsFixer\Tests\Report;
+
+use PhpCsFixer\Report\ReporterInterface;
+use PhpCsFixer\Report\ReportSummary;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
+ *
+ * @internal
+ */
+abstract class AbstractReporterTestCase extends TestCase
+{
+    /**
+     * @var ReporterInterface
+     */
+    protected $reporter;
+
+    protected function setUp()
+    {
+        $this->reporter = $this->createReporter();
+    }
+
+    final public function testGetFormat()
+    {
+        $this->assertSame(
+            $this->getFormat(),
+            $this->reporter->getFormat()
+        );
+    }
+
+    /**
+     * @param string        $expectedReport
+     * @param ReportSummary $reportSummary
+     *
+     * @dataProvider provideGenerateCases
+     */
+    final public function testGenerate($expectedReport, ReportSummary $reportSummary)
+    {
+        $actualReport = $this->reporter->generate($reportSummary);
+
+        $this->assertFormat($expectedReport, $actualReport);
+    }
+
+    /**
+     * @return array
+     */
+    final public function provideGenerateCases()
+    {
+        return array(
+            'no errors' => array(
+                $this->createNoErrorReport(),
+                new ReportSummary(
+                    array(),
+                    0,
+                    0,
+                    false,
+                    false,
+                    false
+                ),
+            ),
+            'simple' => array(
+                $this->createSimpleReport(),
+                new ReportSummary(
+                    array(
+                        'someFile.php' => array(
+                            'appliedFixers' => array('some_fixer_name_here'),
+                        ),
+                    ),
+                    0,
+                    0,
+                    false,
+                    false,
+                    false
+                ),
+            ),
+            'with diff' => array(
+                $this->createWithDiffReport(),
+                new ReportSummary(
+                    array(
+                        'someFile.php' => array(
+                            'appliedFixers' => array('some_fixer_name_here'),
+                            'diff' => 'this text is a diff ;)',
+                        ),
+                    ),
+                    0,
+                    0,
+                    false,
+                    false,
+                    false
+                ),
+            ),
+            'with applied fixers' => array(
+                $this->createWithAppliedFixersReport(),
+                new ReportSummary(
+                    array(
+                        'someFile.php' => array(
+                            'appliedFixers' => array('some_fixer_name_here_1', 'some_fixer_name_here_2'),
+                        ),
+                    ),
+                    0,
+                    0,
+                    true,
+                    false,
+                    false
+                ),
+            ),
+            'with time and memory' => array(
+                $this->createWithTimeAndMemoryReport(),
+                new ReportSummary(
+                    array(
+                        'someFile.php' => array(
+                            'appliedFixers' => array('some_fixer_name_here'),
+                        ),
+                    ),
+                    1234,
+                    2.5 * 1024 * 1024,
+                    false,
+                    false,
+                    false
+                ),
+            ),
+            'complex' => array(
+                $this->createComplexReport(),
+                new ReportSummary(
+                    array(
+                        'someFile.php' => array(
+                            'appliedFixers' => array('some_fixer_name_here_1', 'some_fixer_name_here_2'),
+                            'diff' => 'this text is a diff ;)',
+                        ),
+                        'anotherFile.php' => array(
+                            'appliedFixers' => array('another_fixer_name_here'),
+                            'diff' => 'another diff here ;)',
+                        ),
+                    ),
+                    1234,
+                    2.5 * 1024 * 1024,
+                    true,
+                    true,
+                    true
+                ),
+            ),
+        );
+    }
+
+    /**
+     * @return ReporterInterface
+     */
+    abstract protected function createReporter();
+
+    /**
+     * @return string
+     */
+    abstract protected function getFormat();
+
+    /**
+     * @return string
+     */
+    abstract protected function createNoErrorReport();
+
+    /**
+     * @return string
+     */
+    abstract protected function createSimpleReport();
+
+    /**
+     * @return string
+     */
+    abstract protected function createWithDiffReport();
+
+    /**
+     * @return string
+     */
+    abstract protected function createWithAppliedFixersReport();
+
+    /**
+     * @return string
+     */
+    abstract protected function createWithTimeAndMemoryReport();
+
+    /**
+     * @return string
+     */
+    abstract protected function createComplexReport();
+
+    /**
+     * @param string $expected
+     * @param string $input
+     */
+    abstract protected function assertFormat($expected, $input);
+}

+ 47 - 159
tests/Report/JsonReporterTest.php

@@ -13,8 +13,6 @@
 namespace PhpCsFixer\Tests\Report;
 
 use PhpCsFixer\Report\JsonReporter;
-use PhpCsFixer\Report\ReportSummary;
-use PHPUnit\Framework\TestCase;
 
 /**
  * @author Boris Gorbylev <ekho@ekho.name>
@@ -24,55 +22,11 @@ use PHPUnit\Framework\TestCase;
  *
  * @covers \PhpCsFixer\Report\JsonReporter
  */
-final class JsonReporterTest extends TestCase
+final class JsonReporterTest extends AbstractReporterTestCase
 {
-    /** @var JsonReporter */
-    private $reporter;
-
-    protected function setUp()
-    {
-        $this->reporter = new JsonReporter();
-    }
-
-    /**
-     * @covers \PhpCsFixer\Report\JsonReporter::getFormat
-     */
-    public function testGetFormat()
-    {
-        $this->assertSame('json', $this->reporter->getFormat());
-    }
-
-    public function testGenerateNoErrors()
-    {
-        $expectedReport = <<<'JSON'
-{
-    "files": [
-    ],
-    "time": {
-        "total": 0
-    },
-    "memory": 0
-}
-JSON;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(),
-                0,
-                0,
-                false,
-                false,
-                false
-            )
-        );
-
-        $this->assertJsonSchema($actualReport);
-        $this->assertJsonStringEqualsJsonString($expectedReport, $actualReport);
-    }
-
-    public function testGenerateSimple()
+    public function createSimpleReport()
     {
-        $expectedReport = <<<'JSON'
+        return <<<'JSON'
 {
     "files": [
         {
@@ -80,34 +34,16 @@ JSON;
         }
     ],
     "time": {
-        "total": 5
+        "total": 0
     },
-    "memory": 2
+    "memory": 0
 }
 JSON;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here'),
-                    ),
-                ),
-                5 * 1000,
-                2 * 1024 * 1024,
-                false,
-                false,
-                false
-            )
-        );
-
-        $this->assertJsonSchema($actualReport);
-        $this->assertJsonStringEqualsJsonString($expectedReport, $actualReport);
     }
 
-    public function testGenerateWithDiff()
+    public function createWithDiffReport()
     {
-        $expectedReport = <<<'JSON'
+        return <<<'JSON'
 {
     "files": [
         {
@@ -116,71 +52,34 @@ JSON;
         }
     ],
     "time": {
-        "total": 5
+        "total": 0
     },
-    "memory": 2
+    "memory": 0
 }
 JSON;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here'),
-                        'diff' => 'this text is a diff ;)',
-                    ),
-                ),
-                5 * 1000,
-                2 * 1024 * 1024,
-                false,
-                false,
-                false
-            )
-        );
-
-        $this->assertJsonSchema($actualReport);
-        $this->assertJsonStringEqualsJsonString($expectedReport, $actualReport);
     }
 
-    public function testGenerateWithAppliedFixers()
+    public function createWithAppliedFixersReport()
     {
-        $expectedReport = <<<'JSON'
+        return <<<'JSON'
 {
     "files": [
         {
             "name": "someFile.php",
-            "appliedFixers":["some_fixer_name_here"]
+            "appliedFixers":["some_fixer_name_here_1", "some_fixer_name_here_2"]
         }
     ],
     "time": {
-        "total": 5
+        "total": 0
     },
-    "memory": 2
+    "memory": 0
 }
 JSON;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here'),
-                    ),
-                ),
-                5 * 1000,
-                2 * 1024 * 1024,
-                true,
-                false,
-                false
-            )
-        );
-
-        $this->assertJsonSchema($actualReport);
-        $this->assertJsonStringEqualsJsonString($expectedReport, $actualReport);
     }
 
-    public function testGenerateWithTimeAndMemory()
+    public function createWithTimeAndMemoryReport()
     {
-        $expectedReport = <<<'JSON'
+        return <<<'JSON'
 {
     "files": [
         {
@@ -193,34 +92,16 @@ JSON;
     }
 }
 JSON;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here'),
-                    ),
-                ),
-                1234,
-                2.5 * 1024 * 1024,
-                false,
-                false,
-                false
-            )
-        );
-
-        $this->assertJsonSchema($actualReport);
-        $this->assertJsonStringEqualsJsonString($expectedReport, $actualReport);
     }
 
-    public function testGenerateComplex()
+    public function createComplexReport()
     {
-        $expectedReport = <<<'JSON'
+        return <<<'JSON'
 {
     "files": [
         {
             "name": "someFile.php",
-            "appliedFixers":["some_fixer_name_here"],
+            "appliedFixers":["some_fixer_name_here_1", "some_fixer_name_here_2"],
             "diff": "this text is a diff ;)"
         },
         {
@@ -235,29 +116,36 @@ JSON;
     }
 }
 JSON;
+    }
 
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here'),
-                        'diff' => 'this text is a diff ;)',
-                    ),
-                    'anotherFile.php' => array(
-                        'appliedFixers' => array('another_fixer_name_here'),
-                        'diff' => 'another diff here ;)',
-                    ),
-                ),
-                1234,
-                2.5 * 1024 * 1024,
-                true,
-                true,
-                true
-            )
-        );
+    protected function createReporter()
+    {
+        return new JsonReporter();
+    }
 
-        $this->assertJsonSchema($actualReport);
-        $this->assertJsonStringEqualsJsonString($expectedReport, $actualReport);
+    protected function getFormat()
+    {
+        return 'json';
+    }
+
+    protected function createNoErrorReport()
+    {
+        return <<<'JSON'
+{
+    "files": [
+    ],
+    "time": {
+        "total": 0
+    },
+    "memory": 0
+}
+JSON;
+    }
+
+    protected function assertFormat($expected, $input)
+    {
+        $this->assertJsonSchema($input);
+        $this->assertJsonStringEqualsJsonString($expected, $input);
     }
 
     /**

+ 37 - 136
tests/Report/JunitReporterTest.php

@@ -14,23 +14,19 @@ namespace PhpCsFixer\Tests\Report;
 
 use GeckoPackages\PHPUnit\Constraints\XML\XMLMatchesXSDConstraint;
 use PhpCsFixer\Report\JunitReporter;
-use PhpCsFixer\Report\ReportSummary;
 use PHPUnit\Framework\TestCase;
+use Symfony\Component\Console\Formatter\OutputFormatter;
 
 /**
  * @author Boris Gorbylev <ekho@ekho.name>
+ * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  *
  * @internal
  *
  * @covers \PhpCsFixer\Report\JunitReporter
  */
-final class JunitReporterTest extends TestCase
+final class JunitReporterTest extends AbstractReporterTestCase
 {
-    /**
-     * @var JunitReporter
-     */
-    private $reporter;
-
     /**
      * JUnit XML schema from Jenkins.
      *
@@ -38,25 +34,26 @@ final class JunitReporterTest extends TestCase
      *
      * @see https://github.com/jenkinsci/xunit-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd
      */
-    private $xsd;
+    private static $xsd;
 
-    protected function setUp()
+    public static function setUpBeforeClass()
     {
-        $this->reporter = new JunitReporter();
-        $this->xsd = file_get_contents(__DIR__.'/../../doc/junit-10.xsd');
+        self::$xsd = file_get_contents(__DIR__.'/../../doc/junit-10.xsd');
     }
 
-    /**
-     * @covers \PhpCsFixer\Report\JunitReporter::getFormat
-     */
-    public function testGetFormat()
+    public static function tearDownAfterClass()
+    {
+        self::$xsd = null;
+    }
+
+    public function getFormat()
     {
-        $this->assertSame('junit', $this->reporter->getFormat());
+        return 'junit';
     }
 
-    public function testGenerateNoErrors()
+    public function createNoErrorReport()
     {
-        $expectedReport = <<<'XML'
+        return <<<'XML'
 <?xml version="1.0" encoding="UTF-8"?>
 <testsuites>
   <testsuite name="PHP CS Fixer" tests="1" assertions="1" failures="0" errors="0">
@@ -64,25 +61,11 @@ final class JunitReporterTest extends TestCase
   </testsuite>
 </testsuites>
 XML;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(),
-                0,
-                0,
-                false,
-                false,
-                false
-            )
-        );
-
-        $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd));
-        $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport);
     }
 
-    public function testGenerateSimple()
+    public function createSimpleReport()
     {
-        $expectedReport = <<<'XML'
+        return <<<'XML'
 <?xml version="1.0" encoding="UTF-8"?>
 <testsuites>
   <testsuite name="PHP CS Fixer" tests="1" assertions="1" failures="1" errors="0">
@@ -92,29 +75,11 @@ XML;
   </testsuite>
 </testsuites>
 XML;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here'),
-                    ),
-                ),
-                0,
-                0,
-                false,
-                false,
-                false
-            )
-        );
-
-        $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd));
-        $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport);
     }
 
-    public function testGenerateWithDiff()
+    public function createWithDiffReport()
     {
-        $expectedReport = <<<'XML'
+        return <<<'XML'
 <?xml version="1.0" encoding="UTF-8"?>
 <testsuites>
   <testsuite name="PHP CS Fixer" tests="1" assertions="1" failures="1" errors="0">
@@ -129,30 +94,11 @@ this text is a diff ;)]]></failure>
   </testsuite>
 </testsuites>
 XML;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here'),
-                        'diff' => 'this text is a diff ;)',
-                    ),
-                ),
-                0,
-                0,
-                false,
-                false,
-                false
-            )
-        );
-
-        $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd));
-        $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport);
     }
 
-    public function testGenerateWithAppliedFixers()
+    public function createWithAppliedFixersReport()
     {
-        $expectedReport = <<<'XML'
+        return <<<'XML'
 <?xml version="1.0" encoding="UTF-8"?>
 <testsuites>
   <testsuite name="PHP CS Fixer" tests="1" assertions="2" failures="2" errors="0">
@@ -165,29 +111,11 @@ XML;
   </testsuite>
 </testsuites>
 XML;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here_1', 'some_fixer_name_here_2'),
-                    ),
-                ),
-                0,
-                0,
-                true,
-                false,
-                false
-            )
-        );
-
-        $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd));
-        $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport);
     }
 
-    public function testGenerateWithTimeAndMemory()
+    public function createWithTimeAndMemoryReport()
     {
-        $expectedReport = <<<'XML'
+        return <<<'XML'
 <?xml version="1.0" encoding="UTF-8"?>
 <testsuites>
   <testsuite name="PHP CS Fixer" tests="1" assertions="1" failures="1" errors="0" time="1.234">
@@ -197,29 +125,11 @@ XML;
   </testsuite>
 </testsuites>
 XML;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here'),
-                    ),
-                ),
-                1234,
-                0,
-                false,
-                false,
-                false
-            )
-        );
-
-        $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd));
-        $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport);
     }
 
-    public function testGenerateComplex()
+    public function createComplexReport()
     {
-        $expectedReport = <<<'XML'
+        return <<<'XML'
 <?xml version="1.0"?>
 <testsuites>
   <testsuite assertions="3" errors="0" failures="3" name="PHP CS Fixer" tests="2" time="1.234">
@@ -247,28 +157,19 @@ another diff here ;)</failure>
   </testsuite>
 </testsuites>
 XML;
+    }
 
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here_1', 'some_fixer_name_here_2'),
-                        'diff' => 'this text is a diff ;)',
-                    ),
-                    'anotherFile.php' => array(
-                        'appliedFixers' => array('another_fixer_name_here'),
-                        'diff' => 'another diff here ;)',
-                    ),
-                ),
-                1234,
-                0,
-                true,
-                true,
-                false
-            )
-        );
+    protected function assertFormat($expected, $input)
+    {
+        $formatter = new OutputFormatter();
+        $input = $formatter->format($input);
 
-        $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd));
-        $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport);
+        $this->assertThat($input, new XMLMatchesXSDConstraint(self::$xsd));
+        $this->assertXmlStringEqualsXmlString($expected, $input);
+    }
+
+    protected function createReporter()
+    {
+        return new JunitReporter();
     }
 }

+ 30 - 142
tests/Report/TextReporterTest.php

@@ -12,58 +12,27 @@
 
 namespace PhpCsFixer\Tests\Report;
 
-use PhpCsFixer\Report\ReportSummary;
 use PhpCsFixer\Report\TextReporter;
-use PHPUnit\Framework\TestCase;
 
 /**
  * @author Boris Gorbylev <ekho@ekho.name>
+ * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  *
  * @internal
  *
  * @covers \PhpCsFixer\Report\TextReporter
  */
-final class TextReporterTest extends TestCase
+final class TextReporterTest extends AbstractReporterTestCase
 {
-    /** @var TextReporter */
-    private $reporter;
-
-    protected function setUp()
-    {
-        $this->reporter = new TextReporter();
-    }
-
-    /**
-     * @covers \PhpCsFixer\Report\TextReporter::getFormat
-     */
-    public function testGetFormat()
-    {
-        $this->assertSame('txt', $this->reporter->getFormat());
-    }
-
-    public function testGenerateNoErrors()
+    public function createNoErrorReport()
     {
-        $expectedReport = <<<'TEXT'
+        return <<<'TEXT'
 TEXT;
-
-        $this->assertSame(
-            $expectedReport,
-            $this->reporter->generate(
-                new ReportSummary(
-                    array(),
-                    0,
-                    0,
-                    false,
-                    false,
-                    false
-                )
-            )
-        );
     }
 
-    public function testGenerateSimple()
+    public function createSimpleReport()
     {
-        $expectedReport = str_replace(
+        return str_replace(
             "\n",
             PHP_EOL,
             <<<'TEXT'
@@ -71,29 +40,11 @@ TEXT;
 
 TEXT
         );
-
-        $this->assertSame(
-            $expectedReport,
-            $this->reporter->generate(
-                new ReportSummary(
-                    array(
-                        'someFile.php' => array(
-                            'appliedFixers' => array('some_fixer_name_here'),
-                        ),
-                    ),
-                    0,
-                    0,
-                    false,
-                    false,
-                    false
-                )
-            )
-        );
     }
 
-    public function testGenerateWithDiff()
+    public function createWithDiffReport()
     {
-        $expectedReport = str_replace(
+        return str_replace(
             "\n",
             PHP_EOL,
             <<<'TEXT'
@@ -105,60 +56,23 @@ this text is a diff ;)
 
 TEXT
         );
-
-        $this->assertSame(
-            $expectedReport,
-            $this->reporter->generate(
-                new ReportSummary(
-                    array(
-                        'someFile.php' => array(
-                            'appliedFixers' => array('some_fixer_name_here'),
-                            'diff' => 'this text is a diff ;)',
-                        ),
-                    ),
-                    0,
-                    0,
-                    false,
-                    false,
-                    false
-                )
-            )
-        );
     }
 
-    public function testGenerateWithAppliedFixers()
+    public function createWithAppliedFixersReport()
     {
-        $expectedReport = str_replace(
+        return str_replace(
             "\n",
             PHP_EOL,
             <<<'TEXT'
-   1) someFile.php (some_fixer_name_here)
+   1) someFile.php (some_fixer_name_here_1, some_fixer_name_here_2)
 
 TEXT
         );
-
-        $this->assertSame(
-            $expectedReport,
-            $this->reporter->generate(
-                new ReportSummary(
-                    array(
-                        'someFile.php' => array(
-                            'appliedFixers' => array('some_fixer_name_here'),
-                        ),
-                    ),
-                    0,
-                    0,
-                    true,
-                    false,
-                    false
-                )
-            )
-        );
     }
 
-    public function testGenerateWithTimeAndMemory()
+    public function createWithTimeAndMemoryReport()
     {
-        $expectedReport = str_replace(
+        return str_replace(
             "\n",
             PHP_EOL,
             <<<'TEXT'
@@ -168,33 +82,15 @@ Fixed all files in 1.234 seconds, 2.500 MB memory used
 
 TEXT
         );
-
-        $this->assertSame(
-            $expectedReport,
-            $this->reporter->generate(
-                new ReportSummary(
-                    array(
-                        'someFile.php' => array(
-                            'appliedFixers' => array('some_fixer_name_here'),
-                        ),
-                    ),
-                    1234,
-                    2.5 * 1024 * 1024,
-                    false,
-                    false,
-                    false
-                )
-            )
-        );
     }
 
-    public function testGenerateComplexWithDecoratedOutput()
+    public function createComplexReport()
     {
-        $expectedReport = str_replace(
+        return str_replace(
             "\n",
             PHP_EOL,
             <<<'TEXT'
-   1) someFile.php (<comment>some_fixer_name_here</comment>)
+   1) someFile.php (<comment>some_fixer_name_here_1, some_fixer_name_here_2</comment>)
 <comment>      ---------- begin diff ----------</comment>
 this text is a diff ;)
 <comment>      ----------- end diff -----------</comment>
@@ -209,28 +105,20 @@ Checked all files in 1.234 seconds, 2.500 MB memory used
 
 TEXT
         );
+    }
 
-        $this->assertSame(
-            $expectedReport,
-            $this->reporter->generate(
-                new ReportSummary(
-                    array(
-                        'someFile.php' => array(
-                            'appliedFixers' => array('some_fixer_name_here'),
-                            'diff' => 'this text is a diff ;)',
-                        ),
-                        'anotherFile.php' => array(
-                            'appliedFixers' => array('another_fixer_name_here'),
-                            'diff' => 'another diff here ;)',
-                        ),
-                    ),
-                    1234,
-                    2.5 * 1024 * 1024,
-                    true,
-                    true,
-                    true
-                )
-            )
-        );
+    protected function createReporter()
+    {
+        return new TextReporter();
+    }
+
+    protected function getFormat()
+    {
+        return 'txt';
+    }
+
+    protected function assertFormat($expected, $input)
+    {
+        $this->assertSame($expected, $input);
     }
 }

+ 42 - 139
tests/Report/XmlReporterTest.php

@@ -13,68 +13,47 @@
 namespace PhpCsFixer\Tests\Report;
 
 use GeckoPackages\PHPUnit\Constraints\XML\XMLMatchesXSDConstraint;
-use PhpCsFixer\Report\ReportSummary;
 use PhpCsFixer\Report\XmlReporter;
-use PHPUnit\Framework\TestCase;
+use Symfony\Component\Console\Formatter\OutputFormatter;
 
 /**
  * @author Boris Gorbylev <ekho@ekho.name>
+ * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  *
  * @internal
  *
  * @covers \PhpCsFixer\Report\XmlReporter
  */
-final class XmlReporterTest extends TestCase
+final class XmlReporterTest extends AbstractReporterTestCase
 {
-    /** @var XmlReporter */
-    private $reporter;
-
     /**
      * @var string
      */
-    private $xsd;
+    private static $xsd;
 
-    protected function setUp()
+    public static function setUpBeforeClass()
     {
-        $this->reporter = new XmlReporter();
-        $this->xsd = file_get_contents(__DIR__.'/../../doc/xml.xsd');
+        self::$xsd = file_get_contents(__DIR__.'/../../doc/xml.xsd');
     }
 
-    /**
-     * @covers \PhpCsFixer\Report\XmlReporter::getFormat
-     */
-    public function testGetFormat()
+    public static function tearDownAfterClass()
     {
-        $this->assertSame('xml', $this->reporter->getFormat());
+        self::$xsd = null;
     }
 
-    public function testGenerateNoErrors()
+    public function createNoErrorReport()
     {
-        $expectedReport = <<<'XML'
+        return <<<'XML'
 <?xml version="1.0" encoding="UTF-8"?>
 <report>
   <files />
 </report>
 XML;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(),
-                0,
-                0,
-                false,
-                false,
-                false
-            )
-        );
-
-        $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd));
-        $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport);
     }
 
-    public function testGenerateSimple()
+    public function createSimpleReport()
     {
-        $expectedReport = <<<'XML'
+        return <<<'XML'
 <?xml version="1.0" encoding="UTF-8"?>
 <report>
   <files>
@@ -82,29 +61,11 @@ XML;
   </files>
 </report>
 XML;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here'),
-                    ),
-                ),
-                0,
-                0,
-                false,
-                false,
-                false
-            )
-        );
-
-        $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd));
-        $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport);
     }
 
-    public function testGenerateWithDiff()
+    public function createWithDiffReport()
     {
-        $expectedReport = <<<'XML'
+        return <<<'XML'
 <?xml version="1.0" encoding="UTF-8"?>
 <report>
   <files>
@@ -114,64 +75,28 @@ XML;
   </files>
 </report>
 XML;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here'),
-                        'diff' => 'this text is a diff ;)',
-                    ),
-                ),
-                0,
-                0,
-                false,
-                false,
-                false
-            )
-        );
-
-        $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd));
-        $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport);
     }
 
-    public function testGenerateWithAppliedFixers()
+    public function createWithAppliedFixersReport()
     {
-        $expectedReport = <<<'XML'
+        return <<<'XML'
 <?xml version="1.0" encoding="UTF-8"?>
 <report>
   <files>
     <file id="1" name="someFile.php">
       <applied_fixers>
-        <applied_fixer name="some_fixer_name_here"/>
+        <applied_fixer name="some_fixer_name_here_1"/>
+        <applied_fixer name="some_fixer_name_here_2"/>
       </applied_fixers>
     </file>
   </files>
 </report>
 XML;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here'),
-                    ),
-                ),
-                0,
-                0,
-                true,
-                false,
-                false
-            )
-        );
-
-        $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd));
-        $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport);
     }
 
-    public function testGenerateWithTimeAndMemory()
+    public function createWithTimeAndMemoryReport()
     {
-        $expectedReport = <<<'XML'
+        return <<<'XML'
 <?xml version="1.0" encoding="UTF-8"?>
 <report>
   <files>
@@ -183,42 +108,24 @@ XML;
   <memory value="2.5" unit="MB"/>
 </report>
 XML;
-
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here'),
-                    ),
-                ),
-                1234,
-                2.5 * 1024 * 1024,
-                false,
-                false,
-                false
-            )
-        );
-
-        $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd));
-        $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport);
     }
 
-    public function testGenerateComplex()
+    public function createComplexReport()
     {
-        $expectedReport = <<<'XML'
+        return <<<'XML'
 <?xml version="1.0" encoding="UTF-8"?>
 <report>
   <files>
     <file id="1" name="someFile.php">
       <applied_fixers>
-        <applied_fixer name="some_fixer_name_here"/>
+        <applied_fixer name="some_fixer_name_here_1"/>
+        <applied_fixer name="some_fixer_name_here_2"/>
       </applied_fixers>
       <diff>this text is a diff ;)</diff>
     </file>
     <file id="2" name="anotherFile.php">
       <applied_fixers>
-        <applied_fixer name="another_fixer_name_here_1"/>
-        <applied_fixer name="another_fixer_name_here_2"/>
+        <applied_fixer name="another_fixer_name_here"/>
       </applied_fixers>
       <diff>another diff here ;)</diff>
     </file>
@@ -229,28 +136,24 @@ XML;
   <memory value="2.5" unit="MB"/>
 </report>
 XML;
+    }
+
+    protected function createReporter()
+    {
+        return new XmlReporter();
+    }
 
-        $actualReport = $this->reporter->generate(
-            new ReportSummary(
-                array(
-                    'someFile.php' => array(
-                        'appliedFixers' => array('some_fixer_name_here'),
-                        'diff' => 'this text is a diff ;)',
-                    ),
-                    'anotherFile.php' => array(
-                        'appliedFixers' => array('another_fixer_name_here_1', 'another_fixer_name_here_2'),
-                        'diff' => 'another diff here ;)',
-                    ),
-                ),
-                1234,
-                2.5 * 1024 * 1024,
-                true,
-                false,
-                false
-            )
-        );
+    protected function getFormat()
+    {
+        return 'xml';
+    }
+
+    protected function assertFormat($expected, $input)
+    {
+        $formatter = new OutputFormatter();
+        $input = $formatter->format($input);
 
-        $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd));
-        $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport);
+        $this->assertThat($input, new XMLMatchesXSDConstraint(self::$xsd));
+        $this->assertXmlStringEqualsXmlString($expected, $input);
     }
 }