Skip to content

Commit 4ae841b

Browse files
wip
1 parent de4473a commit 4ae841b

File tree

4 files changed

+7
-36
lines changed

4 files changed

+7
-36
lines changed

src/PHPUnit/ArchRuleCheckerConstraintAdapter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Arkitect\ClassSet;
1010
use Arkitect\ClassSetRules;
1111
use Arkitect\CLI\Printer\Printer;
12+
use Arkitect\CLI\Printer\PrinterFactory;
1213
use Arkitect\CLI\Progress\VoidProgress;
1314
use Arkitect\CLI\Runner;
1415
use Arkitect\CLI\TargetPhpVersion;
@@ -40,6 +41,8 @@ class ArchRuleCheckerConstraintAdapter extends Constraint
4041
/** @var ParsingErrors */
4142
private $parsingErrors;
4243

44+
private Printer $printer;
45+
4346
public function __construct(ClassSet $classSet)
4447
{
4548
$targetPhpVersion = TargetPhpVersion::create(null);
@@ -48,6 +51,7 @@ public function __construct(ClassSet $classSet)
4851
$this->classSet = $classSet;
4952
$this->violations = new Violations();
5053
$this->parsingErrors = new ParsingErrors();
54+
$this->printer = PrinterFactory::create(Printer::FORMAT_TEXT);
5155
}
5256

5357
public function toString(): string
@@ -80,6 +84,6 @@ protected function failureDescription($other): string
8084
return "\n parsing error: ".$this->parsingErrors->toString();
8185
}
8286

83-
return "\n".$this->violations->toString(Printer::FORMAT_TEXT);
87+
return "\n".$this->printer->print($this->violations->groupedByFqcn());
8488
}
8589
}

src/Rules/Violations.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Arkitect\Rules;
66

7-
use Arkitect\CLI\Printer\PrinterFactory;
87
use Arkitect\Exceptions\IndexNotFoundException;
98

109
/**
@@ -75,13 +74,6 @@ public function groupedByFqcn(): array
7574
}, []);
7675
}
7776

78-
public function toString(string $format): string
79-
{
80-
$printer = (new PrinterFactory())->create($format);
81-
82-
return $printer->print($this->groupedByFqcn());
83-
}
84-
8577
public function toArray(): array
8678
{
8779
return $this->violations;

tests/Unit/CLI/Printer/PrinterFactoryTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class PrinterFactoryTest extends TestCase
1515
*/
1616
public function test_create_returns_json_printer_for_json_format(): void
1717
{
18-
$factory = new PrinterFactory();
19-
20-
$printer = $factory->create('json');
18+
$printer = PrinterFactory::create('json');
2119

2220
self::assertInstanceOf(JsonPrinter::class, $printer);
2321
}
@@ -27,9 +25,7 @@ public function test_create_returns_json_printer_for_json_format(): void
2725
*/
2826
public function test_create_returns_text_printer_for_non_json_format(): void
2927
{
30-
$factory = new PrinterFactory();
31-
32-
$printer = $factory->create('text');
28+
$printer = PrinterFactory::create('text');
3329

3430
self::assertInstanceOf(TextPrinter::class, $printer);
3531
}

tests/Unit/Rules/ViolationsTest.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Arkitect\Tests\Unit\Rules;
66

7-
use Arkitect\CLI\Printer\Printer;
87
use Arkitect\Exceptions\IndexNotFoundException;
98
use Arkitect\Rules\Violation;
109
use Arkitect\Rules\Violations;
@@ -48,26 +47,6 @@ public function test_count(): void
4847
self::assertEquals(2, $this->violationStore->count());
4948
}
5049

51-
public function test_to_string(): void
52-
{
53-
$violation = new Violation(
54-
'App\Controller\Foo',
55-
'should have name end with Controller'
56-
);
57-
58-
$this->violationStore->add($violation);
59-
60-
$expected = <<<'ERRORS'
61-
App\Controller\ProductController has 1 violations
62-
should implement ContainerInterface
63-
64-
App\Controller\Foo has 1 violations
65-
should have name end with Controller
66-
ERRORS;
67-
68-
self::assertStringContainsString($expected, $this->violationStore->toString(Printer::FORMAT_TEXT));
69-
}
70-
7150
public function test_get_iterable(): void
7251
{
7352
$violation = new Violation(

0 commit comments

Comments
 (0)