123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?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\ReportSummary;
- use PhpCsFixer\Report\TextReporter;
- /**
- * @author Boris Gorbylev <ekho@ekho.name>
- *
- * @internal
- */
- final class TextReporterTest extends \PHPUnit_Framework_TestCase
- {
- /** @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()
- {
- $expectedReport = <<<'TEXT'
- TEXT;
- $this->assertSame(
- $expectedReport,
- $this->reporter->generate(
- new ReportSummary(
- array(),
- 0,
- 0,
- false,
- false,
- false
- )
- )
- );
- }
- public function testGenerateSimple()
- {
- $expectedReport = str_replace("\n", PHP_EOL, <<<'TEXT'
- 1) someFile.php
- 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()
- {
- $expectedReport = str_replace("\n", PHP_EOL, <<<'TEXT'
- 1) someFile.php
- ---------- begin diff ----------
- this text is a diff ;)
- ----------- end 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()
- {
- $expectedReport = str_replace("\n", PHP_EOL, <<<'TEXT'
- 1) someFile.php (some_fixer_name_here)
- 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()
- {
- $expectedReport = str_replace("\n", PHP_EOL, <<<'TEXT'
- 1) someFile.php
- 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()
- {
- $expectedReport = str_replace("\n", PHP_EOL, <<<'TEXT'
- 1) someFile.php (<comment>some_fixer_name_here</comment>)
- <comment> ---------- begin diff ----------</comment>
- this text is a diff ;)
- <comment> ----------- end diff -----------</comment>
- 2) anotherFile.php (<comment>another_fixer_name_here</comment>)
- <comment> ---------- begin diff ----------</comment>
- another diff here ;)
- <comment> ----------- end diff -----------</comment>
- 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
- )
- )
- );
- }
- }
|