123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?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\ReporterFactory;
- use PHPUnit\Framework\TestCase;
- /**
- * @author Boris Gorbylev <ekho@ekho.name>
- *
- * @internal
- *
- * @covers \PhpCsFixer\Report\ReporterFactory
- */
- final class ReporterFactoryTest extends TestCase
- {
- public function testCreate()
- {
- $factory = ReporterFactory::create();
- $this->assertInstanceOf(\PhpCsFixer\Report\ReporterFactory::class, $factory);
- }
- public function testInterfaceIsFluent()
- {
- $builder = new ReporterFactory();
- $testInstance = $builder->registerBuiltInReporters();
- $this->assertSame($builder, $testInstance);
- $double = $this->createReporterDouble('r1');
- $testInstance = $builder->registerReporter($double);
- $this->assertSame($builder, $testInstance);
- }
- public function testRegisterBuiltInReports()
- {
- $builder = new ReporterFactory();
- $this->assertCount(0, $builder->getFormats());
- $builder->registerBuiltInReporters();
- $this->assertSame(
- ['checkstyle', 'json', 'junit', 'txt', 'xml'],
- $builder->getFormats()
- );
- }
- public function testThatCanRegisterAndGetReports()
- {
- $builder = new ReporterFactory();
- $r1 = $this->createReporterDouble('r1');
- $r2 = $this->createReporterDouble('r2');
- $r3 = $this->createReporterDouble('r3');
- $builder->registerReporter($r1);
- $builder->registerReporter($r2);
- $builder->registerReporter($r3);
- $this->assertSame($r1, $builder->getReporter('r1'));
- $this->assertSame($r2, $builder->getReporter('r2'));
- $this->assertSame($r3, $builder->getReporter('r3'));
- }
- public function testGetFormats()
- {
- $builder = new ReporterFactory();
- $r1 = $this->createReporterDouble('r1');
- $r2 = $this->createReporterDouble('r2');
- $r3 = $this->createReporterDouble('r3');
- $builder->registerReporter($r1);
- $builder->registerReporter($r2);
- $builder->registerReporter($r3);
- $this->assertSame(['r1', 'r2', 'r3'], $builder->getFormats());
- }
- public function testRegisterReportWithOccupiedFormat()
- {
- $this->setExpectedException(
- \UnexpectedValueException::class,
- 'Reporter for format "non_unique_name" is already registered.'
- );
- $factory = new ReporterFactory();
- $r1 = $this->createReporterDouble('non_unique_name');
- $r2 = $this->createReporterDouble('non_unique_name');
- $factory->registerReporter($r1);
- $factory->registerReporter($r2);
- }
- public function testGetNonRegisteredReport()
- {
- $this->setExpectedException(
- \UnexpectedValueException::class,
- 'Reporter for format "non_registered_format" is not registered.'
- );
- $builder = new ReporterFactory();
- $builder->getReporter('non_registered_format');
- }
- private function createReporterDouble($format)
- {
- $reporter = $this->prophesize(\PhpCsFixer\Report\ReporterInterface::class);
- $reporter->getFormat()->willReturn($format);
- return $reporter->reveal();
- }
- }
|