Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php declare(strict_types=1); /* * This file is part of PHP CS Fixer. * * (c) Fabien..
Decoded Output download
<?php
declare(strict_types=1);
/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <[email protected]>
* Dariusz Rumiski <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace PhpCsFixer\Tests\Console\Report\ListSetsReport;
use PhpCsFixer\Console\Report\ListSetsReport\ReporterFactory;
use PhpCsFixer\Console\Report\ListSetsReport\ReporterInterface;
use PhpCsFixer\Console\Report\ListSetsReport\ReportSummary;
use PhpCsFixer\Tests\TestCase;
/**
* @author Boris Gorbylev <[email protected]>
* @author Dariusz Rumiski <[email protected]>
*
* @internal
*
* @covers \PhpCsFixer\Console\Report\ListSetsReport\ReporterFactory
*/
final class ReporterFactoryTest extends TestCase
{
public function testInterfaceIsFluent(): void
{
$builder = new ReporterFactory();
$testInstance = $builder->registerBuiltInReporters();
self::assertSame($builder, $testInstance);
$double = $this->createReporterDouble('r1');
$testInstance = $builder->registerReporter($double);
self::assertSame($builder, $testInstance);
}
public function testRegisterBuiltInReports(): void
{
$builder = new ReporterFactory();
self::assertCount(0, $builder->getFormats());
$builder->registerBuiltInReporters();
self::assertSame(
['json', 'txt'],
$builder->getFormats()
);
}
public function testThatCanRegisterAndGetReports(): void
{
$builder = new ReporterFactory();
$r1 = $this->createReporterDouble('r1');
$r2 = $this->createReporterDouble('r2');
$r3 = $this->createReporterDouble('r3');
$builder->registerReporter($r1);
$builder->registerReporter($r2);
$builder->registerReporter($r3);
self::assertSame($r1, $builder->getReporter('r1'));
self::assertSame($r2, $builder->getReporter('r2'));
self::assertSame($r3, $builder->getReporter('r3'));
}
public function testGetFormats(): void
{
$builder = new ReporterFactory();
$r1 = $this->createReporterDouble('r1');
$r2 = $this->createReporterDouble('r2');
$r3 = $this->createReporterDouble('r3');
$builder->registerReporter($r1);
$builder->registerReporter($r2);
$builder->registerReporter($r3);
self::assertSame(['r1', 'r2', 'r3'], $builder->getFormats());
}
public function testRegisterReportWithOccupiedFormat(): void
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('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(): void
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Reporter for format "non_registered_format" is not registered.');
$builder = new ReporterFactory();
$builder->getReporter('non_registered_format');
}
private function createReporterDouble(string $format): ReporterInterface
{
return new class($format) implements ReporterInterface {
private string $format;
public function __construct(string $format)
{
$this->format = $format;
}
public function getFormat(): string
{
return $this->format;
}
public function generate(ReportSummary $reportSummary): string
{
throw new \LogicException('Not implemented.');
}
};
}
}
?>
Did this file decode correctly?
Original Code
<?php
declare(strict_types=1);
/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <[email protected]>
* Dariusz Rumiski <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace PhpCsFixer\Tests\Console\Report\ListSetsReport;
use PhpCsFixer\Console\Report\ListSetsReport\ReporterFactory;
use PhpCsFixer\Console\Report\ListSetsReport\ReporterInterface;
use PhpCsFixer\Console\Report\ListSetsReport\ReportSummary;
use PhpCsFixer\Tests\TestCase;
/**
* @author Boris Gorbylev <[email protected]>
* @author Dariusz Rumiski <[email protected]>
*
* @internal
*
* @covers \PhpCsFixer\Console\Report\ListSetsReport\ReporterFactory
*/
final class ReporterFactoryTest extends TestCase
{
public function testInterfaceIsFluent(): void
{
$builder = new ReporterFactory();
$testInstance = $builder->registerBuiltInReporters();
self::assertSame($builder, $testInstance);
$double = $this->createReporterDouble('r1');
$testInstance = $builder->registerReporter($double);
self::assertSame($builder, $testInstance);
}
public function testRegisterBuiltInReports(): void
{
$builder = new ReporterFactory();
self::assertCount(0, $builder->getFormats());
$builder->registerBuiltInReporters();
self::assertSame(
['json', 'txt'],
$builder->getFormats()
);
}
public function testThatCanRegisterAndGetReports(): void
{
$builder = new ReporterFactory();
$r1 = $this->createReporterDouble('r1');
$r2 = $this->createReporterDouble('r2');
$r3 = $this->createReporterDouble('r3');
$builder->registerReporter($r1);
$builder->registerReporter($r2);
$builder->registerReporter($r3);
self::assertSame($r1, $builder->getReporter('r1'));
self::assertSame($r2, $builder->getReporter('r2'));
self::assertSame($r3, $builder->getReporter('r3'));
}
public function testGetFormats(): void
{
$builder = new ReporterFactory();
$r1 = $this->createReporterDouble('r1');
$r2 = $this->createReporterDouble('r2');
$r3 = $this->createReporterDouble('r3');
$builder->registerReporter($r1);
$builder->registerReporter($r2);
$builder->registerReporter($r3);
self::assertSame(['r1', 'r2', 'r3'], $builder->getFormats());
}
public function testRegisterReportWithOccupiedFormat(): void
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('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(): void
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Reporter for format "non_registered_format" is not registered.');
$builder = new ReporterFactory();
$builder->getReporter('non_registered_format');
}
private function createReporterDouble(string $format): ReporterInterface
{
return new class($format) implements ReporterInterface {
private string $format;
public function __construct(string $format)
{
$this->format = $format;
}
public function getFormat(): string
{
return $this->format;
}
public function generate(ReportSummary $reportSummary): string
{
throw new \LogicException('Not implemented.');
}
};
}
}
Function Calls
None |
Stats
MD5 | f0e44755961d15a56e67412175d2a743 |
Eval Count | 0 |
Decode Time | 106 ms |