diff --git a/bin/phuml b/bin/phuml index 6ce3536..e239417 100755 --- a/bin/phuml +++ b/bin/phuml @@ -25,10 +25,6 @@ if (!$installed) { } use PhUml\Console\PhUmlApplication; -use PhUml\Console\ProgressDisplay; -use Symfony\Component\Console\Input\ArgvInput; -use Symfony\Component\Console\Output\ConsoleOutput; -$output = new ConsoleOutput(); -$application = new PhUmlApplication(new ProgressDisplay($output)); -$application->run(new ArgvInput(), $output); +$application = new PhUmlApplication(); +$application->run(); diff --git a/src/Console/Commands/GenerateClassDiagramCommand.php b/src/Console/Commands/GenerateClassDiagramCommand.php index b68740d..d8b74ad 100644 --- a/src/Console/Commands/GenerateClassDiagramCommand.php +++ b/src/Console/Commands/GenerateClassDiagramCommand.php @@ -11,9 +11,11 @@ use PhUml\Configuration\ClassDiagramConfiguration; use PhUml\Configuration\DigraphBuilder; use PhUml\Configuration\DigraphConfiguration; +use PhUml\Console\ConsoleProgressDisplay; use PhUml\Generators\ClassDiagramGenerator; use PhUml\Processors\DotProcessor; use PhUml\Processors\NeatoProcessor; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -34,7 +36,7 @@ * * @see WithDigraphConfiguration::addDigraphOptions() for more details about the rest of the options */ -final class GenerateClassDiagramCommand extends GeneratorCommand +final class GenerateClassDiagramCommand extends Command { use WithDigraphConfiguration; @@ -91,9 +93,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $builder->digraphProcessor(), $configuration->isDotProcessor() ? new DotProcessor() : new NeatoProcessor() ); - $classDiagramGenerator->attach($this->display); - $classDiagramGenerator->generate($codeFinder, $classDiagramPath); + $classDiagramGenerator->generate($codeFinder, $classDiagramPath, new ConsoleProgressDisplay($output)); return self::SUCCESS; } diff --git a/src/Console/Commands/GenerateDotFileCommand.php b/src/Console/Commands/GenerateDotFileCommand.php index 7ea5077..768ad04 100644 --- a/src/Console/Commands/GenerateDotFileCommand.php +++ b/src/Console/Commands/GenerateDotFileCommand.php @@ -9,7 +9,9 @@ use PhUml\Configuration\DigraphBuilder; use PhUml\Configuration\DigraphConfiguration; +use PhUml\Console\ConsoleProgressDisplay; use PhUml\Generators\DotFileGenerator; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -25,7 +27,7 @@ * * @see WithDigraphConfiguration::addDigraphOptions() for more details about all the available options */ -final class GenerateDotFileCommand extends GeneratorCommand +final class GenerateDotFileCommand extends Command { use WithDigraphConfiguration; @@ -67,11 +69,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $builder = new DigraphBuilder(new DigraphConfiguration($generatorInput->options())); $dotFileGenerator = new DotFileGenerator($builder->codeParser(), $builder->digraphProcessor()); - $dotFileGenerator->attach($this->display); $codeFinder = $builder->codeFinder($codebasePath); - $dotFileGenerator->generate($codeFinder, $dotFilePath); + $dotFileGenerator->generate($codeFinder, $dotFilePath, new ConsoleProgressDisplay($output)); return self::SUCCESS; } diff --git a/src/Console/Commands/GenerateStatisticsCommand.php b/src/Console/Commands/GenerateStatisticsCommand.php index 7898e94..2af223b 100644 --- a/src/Console/Commands/GenerateStatisticsCommand.php +++ b/src/Console/Commands/GenerateStatisticsCommand.php @@ -7,10 +7,12 @@ namespace PhUml\Console\Commands; +use PhUml\Console\ConsoleProgressDisplay; use PhUml\Generators\StatisticsGenerator; use PhUml\Parser\Code\PhpCodeParser; use PhUml\Parser\CodeParser; use PhUml\Processors\StatisticsProcessor; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\InvalidArgumentException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -29,7 +31,7 @@ * * 1. `recursive`. If present it will look recursively within the `directory` provided */ -final class GenerateStatisticsCommand extends GeneratorCommand +final class GenerateStatisticsCommand extends Command { /** * @throws InvalidArgumentException @@ -73,11 +75,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $statisticsFilePath = $statisticsInput->outputFile(); $statisticsGenerator = new StatisticsGenerator(new CodeParser(new PhpCodeParser()), new StatisticsProcessor()); - $statisticsGenerator->attach($this->display); $codeFinder = $statisticsInput->codeFinder(); - $statisticsGenerator->generate($codeFinder, $statisticsFilePath); + $statisticsGenerator->generate($codeFinder, $statisticsFilePath, new ConsoleProgressDisplay($output)); return self::SUCCESS; } diff --git a/src/Console/Commands/GeneratorCommand.php b/src/Console/Commands/GeneratorCommand.php deleted file mode 100644 index 0e33e71..0000000 --- a/src/Console/Commands/GeneratorCommand.php +++ /dev/null @@ -1,27 +0,0 @@ -display = $display; - } -} diff --git a/src/Console/ProgressDisplay.php b/src/Console/ConsoleProgressDisplay.php similarity index 84% rename from src/Console/ProgressDisplay.php rename to src/Console/ConsoleProgressDisplay.php index 3e245f4..2501279 100644 --- a/src/Console/ProgressDisplay.php +++ b/src/Console/ConsoleProgressDisplay.php @@ -7,16 +7,16 @@ namespace PhUml\Console; -use PhUml\Generators\ProcessorProgressDisplay; +use PhUml\Generators\ProgressDisplay; use PhUml\Processors\Processor; use Symfony\Component\Console\Output\OutputInterface; /** * It provides visual feedback to the use about the progress of the current command * - * @see ProcessorProgressDisplay for more details about the things that are reported by this display + * @see ProgressDisplay for more details about the things that are reported by this display */ -final class ProgressDisplay implements ProcessorProgressDisplay +final class ConsoleProgressDisplay implements ProgressDisplay { private OutputInterface $output; diff --git a/src/Console/PhUmlApplication.php b/src/Console/PhUmlApplication.php index 8482ec9..db3d9e5 100644 --- a/src/Console/PhUmlApplication.php +++ b/src/Console/PhUmlApplication.php @@ -23,7 +23,7 @@ */ final class PhUmlApplication extends Application { - public function __construct(ProgressDisplay $display) + public function __construct() { // This will be replaced by Box with a version number if it's a PHAR // 1.6.1 for instance @@ -34,8 +34,8 @@ public function __construct(ProgressDisplay $display) $version = '1.6-dev'; } parent::__construct('phUML', $version); - $this->add(new GenerateClassDiagramCommand($display)); - $this->add(new GenerateStatisticsCommand($display)); - $this->add(new GenerateDotFileCommand($display)); + $this->add(new GenerateClassDiagramCommand()); + $this->add(new GenerateStatisticsCommand()); + $this->add(new GenerateDotFileCommand()); } } diff --git a/src/Generators/ClassDiagramGenerator.php b/src/Generators/ClassDiagramGenerator.php index 421afcd..13a5612 100644 --- a/src/Generators/ClassDiagramGenerator.php +++ b/src/Generators/ClassDiagramGenerator.php @@ -7,7 +7,6 @@ namespace PhUml\Generators; -use LogicException; use PhUml\Parser\CodeFinder; use PhUml\Parser\CodeParser; use PhUml\Processors\GraphvizProcessor; @@ -36,24 +35,23 @@ public function __construct( /** * The process to generate a class diagram is as follows * - * 1. The parser produces a collection of classes and interfaces + * 1. The parser produces a collection of classes, interfaces and traits * 2. The `graphviz` processor takes this collection and creates a digraph using the DOT language - * 3. Either the `neato` or `dot` will produce a `.png` class diagram from the digraph + * 3. Either the `neato` or `dot` processor will produce a `.png` class diagram from the digraph * 4. The image is saved to the given path - * - * @throws LogicException If either the image processor or the command are missing */ - public function generate(CodeFinder $finder, OutputFilePath $imagePath): void + public function generate(CodeFinder $finder, OutputFilePath $imagePath, ProgressDisplay $display): void { - $this->display()->start(); - $image = $this->generateClassDiagram($this->generateDigraph($this->parseCode($finder))); - $this->save($this->imageProcessor, $image, $imagePath); + $display->start(); + $codebase = $this->parseCode($finder, $display); + $digraph = $this->generateDigraph($codebase, $display); + $image = $this->generateClassDiagram($digraph, $display); + $this->save($this->imageProcessor, $image, $imagePath, $display); } - /** @throws LogicException If no command or image processor is provided */ - private function generateClassDiagram(OutputContent $digraph): OutputContent + private function generateClassDiagram(OutputContent $digraph, ProgressDisplay $display): OutputContent { - $this->display()->runningProcessor($this->imageProcessor); + $display->runningProcessor($this->imageProcessor); return $this->imageProcessor->process($digraph); } } diff --git a/src/Generators/DigraphGenerator.php b/src/Generators/DigraphGenerator.php index 0966396..816eeb7 100644 --- a/src/Generators/DigraphGenerator.php +++ b/src/Generators/DigraphGenerator.php @@ -22,9 +22,9 @@ public function __construct(CodeParser $parser, GraphvizProcessor $digraphProces $this->digraphProcessor = $digraphProcessor; } - protected function generateDigraph(Codebase $codebase): OutputContent + protected function generateDigraph(Codebase $codebase, ProgressDisplay $display): OutputContent { - $this->display()->runningProcessor($this->digraphProcessor); + $display->runningProcessor($this->digraphProcessor); return $this->digraphProcessor->process($codebase); } } diff --git a/src/Generators/DotFileGenerator.php b/src/Generators/DotFileGenerator.php index a0ba628..fc96f5a 100644 --- a/src/Generators/DotFileGenerator.php +++ b/src/Generators/DotFileGenerator.php @@ -7,7 +7,6 @@ namespace PhUml\Generators; -use LogicException; use PhUml\Parser\CodeFinder; use PhUml\Processors\OutputFilePath; @@ -30,15 +29,14 @@ final class DotFileGenerator extends DigraphGenerator * 1. The parser produces a collection of classes and interfaces * 2. The `graphviz` processor takes this collection and creates a digraph using the DOT language * 4. The DOT file is saved to the given path - * - * @throws LogicException If the command is missing */ - public function generate(CodeFinder $finder, OutputFilePath $dotFilePath): void + public function generate(CodeFinder $finder, OutputFilePath $dotFilePath, ProgressDisplay $display): void { - $this->display()->start(); + $display->start(); - $digraph = $this->generateDigraph($this->parseCode($finder)); + $codebase = $this->parseCode($finder, $display); + $digraph = $this->generateDigraph($codebase, $display); - $this->save($this->digraphProcessor, $digraph, $dotFilePath); + $this->save($this->digraphProcessor, $digraph, $dotFilePath, $display); } } diff --git a/src/Generators/Generator.php b/src/Generators/Generator.php index cefeaf5..6706069 100644 --- a/src/Generators/Generator.php +++ b/src/Generators/Generator.php @@ -7,7 +7,6 @@ namespace PhUml\Generators; -use LogicException; use PhUml\Code\Codebase; use PhUml\Parser\CodeFinder; use PhUml\Parser\CodeParser; @@ -19,12 +18,10 @@ * All generators will see the console commands as listeners that will provide feedback * to the end users about their progress * - * @see ProcessorProgressDisplay for the details about the events that are tracked + * @see ProgressDisplay for the details about the events that are tracked */ abstract class Generator { - private ?ProcessorProgressDisplay $display = null; - private CodeParser $parser; public function __construct(CodeParser $parser) @@ -32,32 +29,19 @@ public function __construct(CodeParser $parser) $this->parser = $parser; } - public function attach(ProcessorProgressDisplay $display): void - { - $this->display = $display; - } - - /** @throws LogicException */ - protected function display(): ProcessorProgressDisplay + protected function parseCode(CodeFinder $finder, ProgressDisplay $display): Codebase { - if ($this->display === null) { - throw new LogicException('No display was attached'); - } - return $this->display; - } - - /** - * @throws LogicException If the command is missing - */ - protected function parseCode(CodeFinder $finder): Codebase - { - $this->display()->runningParser(); + $display->runningParser(); return $this->parser->parse($finder); } - protected function save(Processor $processor, OutputContent $content, OutputFilePath $path): void - { - $this->display()->savingResult(); + protected function save( + Processor $processor, + OutputContent $content, + OutputFilePath $path, + ProgressDisplay $display + ): void { + $display->savingResult(); $processor->saveToFile($content, $path); } } diff --git a/src/Generators/ProcessorProgressDisplay.php b/src/Generators/ProgressDisplay.php similarity index 84% rename from src/Generators/ProcessorProgressDisplay.php rename to src/Generators/ProgressDisplay.php index 730fb77..23e0be9 100644 --- a/src/Generators/ProcessorProgressDisplay.php +++ b/src/Generators/ProgressDisplay.php @@ -10,13 +10,13 @@ use PhUml\Processors\Processor; /** - * Listener for the Action classes. It provides feedback before: + * It provides feedback before: * * - Running the parser * - Running a processor * - Saving the results produced by the processors */ -interface ProcessorProgressDisplay +interface ProgressDisplay { public function start(): void; diff --git a/src/Generators/StatisticsGenerator.php b/src/Generators/StatisticsGenerator.php index 9fb3483..fef881b 100644 --- a/src/Generators/StatisticsGenerator.php +++ b/src/Generators/StatisticsGenerator.php @@ -7,7 +7,6 @@ namespace PhUml\Generators; -use LogicException; use PhUml\Code\Codebase; use PhUml\Parser\CodeFinder; use PhUml\Parser\CodeParser; @@ -40,18 +39,18 @@ public function __construct(CodeParser $parser, StatisticsProcessor $statisticsP * 4. The text file with the statistics is saved to the given path * * @throws TemplateFailure If Twig fails - * @throws LogicException If the command is missing */ - public function generate(CodeFinder $finder, OutputFilePath $statisticsFilePath): void + public function generate(CodeFinder $finder, OutputFilePath $statisticsFilePath, ProgressDisplay $display): void { - $this->display()->start(); - $statistics = $this->generateStatistics($this->parseCode($finder)); - $this->save($this->statisticsProcessor, $statistics, $statisticsFilePath); + $display->start(); + $codebase = $this->parseCode($finder, $display); + $statistics = $this->generateStatistics($codebase, $display); + $this->save($this->statisticsProcessor, $statistics, $statisticsFilePath, $display); } - private function generateStatistics(Codebase $codebase): OutputContent + private function generateStatistics(Codebase $codebase, ProgressDisplay $display): OutputContent { - $this->display()->runningProcessor($this->statisticsProcessor); + $display->runningProcessor($this->statisticsProcessor); return $this->statisticsProcessor->process($codebase); } } diff --git a/tests/integration/Generators/GenerateClassDiagramWithDotTest.php b/tests/integration/Generators/GenerateClassDiagramWithDotTest.php index b8a5e65..60ec0a0 100644 --- a/tests/integration/Generators/GenerateClassDiagramWithDotTest.php +++ b/tests/integration/Generators/GenerateClassDiagramWithDotTest.php @@ -7,10 +7,9 @@ namespace PhUml\Generators; -use LogicException; use Lupka\PHPUnitCompareImages\CompareImagesTrait; use PHPUnit\Framework\TestCase; -use PhUml\Fakes\StringCodeFinder; +use PhUml\Console\ConsoleProgressDisplay; use PhUml\Graphviz\Builders\ClassGraphBuilder; use PhUml\Graphviz\Builders\EdgesBuilder; use PhUml\Parser\Code\ExternalDefinitionsResolver; @@ -21,19 +20,11 @@ use PhUml\Processors\DotProcessor; use PhUml\Processors\GraphvizProcessor; use PhUml\Processors\OutputFilePath; -use Prophecy\PhpUnit\ProphecyTrait; +use Symfony\Component\Console\Output\NullOutput; final class GenerateClassDiagramWithDotTest extends TestCase { use CompareImagesTrait; - use ProphecyTrait; - - /** @test */ - function it_fails_to_generate_diagram_if_a_command_is_not_provided() - { - $this->expectException(LogicException::class); - $this->generator->generate(new StringCodeFinder(), new OutputFilePath('wont-be-generated.png')); - } /** * @test @@ -41,13 +32,13 @@ function it_fails_to_generate_diagram_if_a_command_is_not_provided() */ function it_generates_a_class_diagram() { - $this->generator->attach($this->prophesize(ProcessorProgressDisplay::class)->reveal()); + $display = new ConsoleProgressDisplay(new NullOutput()); $directory = new CodebaseDirectory(__DIR__ . '/../../resources/.code/classes'); $finder = SourceCodeFinder::nonRecursive($directory); $diagram = new OutputFilePath(__DIR__ . '/../../resources/.output/graphviz-dot.png'); $expectedDiagram = __DIR__ . '/../../resources/images/graphviz-dot.png'; - $this->generator->generate($finder, $diagram); + $this->generator->generate($finder, $diagram, $display); $this->assertImagesSame($expectedDiagram, $diagram->value()); } @@ -58,12 +49,12 @@ function it_generates_a_class_diagram() */ function it_generates_a_class_diagram_using_a_recursive_finder() { - $this->generator->attach($this->prophesize(ProcessorProgressDisplay::class)->reveal()); + $display = new ConsoleProgressDisplay(new NullOutput()); $codeFinder = SourceCodeFinder::recursive(new CodebaseDirectory(__DIR__ . '/../../resources/.code')); $diagram = new OutputFilePath(__DIR__ . '/../../resources/.output/graphviz-dot-recursive.png'); $expectedDiagram = __DIR__ . '/../../resources/images/graphviz-dot-recursive.png'; - $this->generator->generate($codeFinder, $diagram); + $this->generator->generate($codeFinder, $diagram, $display); $this->assertImagesSame($expectedDiagram, $diagram->value()); } diff --git a/tests/integration/Generators/GenerateClassDiagramWithNeatoTest.php b/tests/integration/Generators/GenerateClassDiagramWithNeatoTest.php index 0276af8..fd8a272 100644 --- a/tests/integration/Generators/GenerateClassDiagramWithNeatoTest.php +++ b/tests/integration/Generators/GenerateClassDiagramWithNeatoTest.php @@ -7,10 +7,9 @@ namespace PhUml\Generators; -use LogicException; use Lupka\PHPUnitCompareImages\CompareImagesTrait; use PHPUnit\Framework\TestCase; -use PhUml\Fakes\StringCodeFinder; +use PhUml\Console\ConsoleProgressDisplay; use PhUml\Graphviz\Builders\ClassGraphBuilder; use PhUml\Graphviz\Builders\EdgesBuilder; use PhUml\Parser\Code\ExternalDefinitionsResolver; @@ -21,19 +20,11 @@ use PhUml\Processors\GraphvizProcessor; use PhUml\Processors\NeatoProcessor; use PhUml\Processors\OutputFilePath; -use Prophecy\PhpUnit\ProphecyTrait; +use Symfony\Component\Console\Output\NullOutput; final class GenerateClassDiagramWithNeatoTest extends TestCase { use CompareImagesTrait; - use ProphecyTrait; - - /** @test */ - function it_fails_to_generate_diagram_if_a_command_is_not_provided() - { - $this->expectException(LogicException::class); - $this->generator->generate(new StringCodeFinder(), new OutputFilePath('wont-be-generated.png')); - } /** * @test @@ -41,13 +32,13 @@ function it_fails_to_generate_diagram_if_a_command_is_not_provided() */ function it_generates_a_class_diagram() { - $this->generator->attach($this->prophesize(ProcessorProgressDisplay::class)->reveal()); + $display = new ConsoleProgressDisplay(new NullOutput()); $directory = new CodebaseDirectory(__DIR__ . '/../../resources/.code/classes'); $finder = SourceCodeFinder::nonRecursive($directory); $diagram = new OutputFilePath(__DIR__ . '/../../resources/.output/graphviz-neato.png'); $expectedDiagram = __DIR__ . '/../../resources/images/graphviz-neato.png'; - $this->generator->generate($finder, $diagram); + $this->generator->generate($finder, $diagram, $display); $this->assertImagesSame($expectedDiagram, $diagram->value()); } @@ -58,12 +49,12 @@ function it_generates_a_class_diagram() */ function it_generates_a_class_diagram_using_a_recursive_finder() { - $this->generator->attach($this->prophesize(ProcessorProgressDisplay::class)->reveal()); + $display = new ConsoleProgressDisplay(new NullOutput()); $codeFinder = SourceCodeFinder::recursive(new CodebaseDirectory(__DIR__ . '/../../resources/.code')); $diagram = new OutputFilePath(__DIR__ . '/../../resources/.output/graphviz-neato-recursive.png'); $expectedDiagram = __DIR__ . '/../../resources/images/graphviz-neato-recursive.png'; - $this->generator->generate($codeFinder, $diagram); + $this->generator->generate($codeFinder, $diagram, $display); $this->assertImagesSame($expectedDiagram, $diagram->value()); } diff --git a/tests/integration/Generators/GenerateClassDiagramWithThemeTest.php b/tests/integration/Generators/GenerateClassDiagramWithThemeTest.php index d2c9ef7..38b5764 100644 --- a/tests/integration/Generators/GenerateClassDiagramWithThemeTest.php +++ b/tests/integration/Generators/GenerateClassDiagramWithThemeTest.php @@ -9,6 +9,7 @@ use Lupka\PHPUnitCompareImages\CompareImagesTrait; use PHPUnit\Framework\TestCase; +use PhUml\Console\ConsoleProgressDisplay; use PhUml\Graphviz\Builders\ClassGraphBuilder; use PhUml\Graphviz\Builders\EdgesBuilder; use PhUml\Graphviz\Builders\InterfaceGraphBuilder; @@ -25,12 +26,11 @@ use PhUml\Processors\GraphvizProcessor; use PhUml\Processors\OutputFilePath; use PhUml\Templates\TemplateEngine; -use Prophecy\PhpUnit\ProphecyTrait; +use Symfony\Component\Console\Output\NullOutput; final class GenerateClassDiagramWithThemeTest extends TestCase { use CompareImagesTrait; - use ProphecyTrait; /** * @test @@ -43,7 +43,7 @@ function it_generates_a_class_diagram_using_the_php_theme() $expectedDiagram = __DIR__ . '/../../resources/images/graphviz-dot-php-theme.png'; $generator = $this->createGenerator('php'); - $generator->generate($codeFinder, $diagram); + $generator->generate($codeFinder, $diagram, $this->display); $this->assertImagesSame($expectedDiagram, $diagram->value()); } @@ -59,7 +59,7 @@ function it_generates_a_class_diagram_using_the_classic_theme() $expectedDiagram = __DIR__ . '/../../resources/images/graphviz-dot-classic-theme.png'; $generator = $this->createGenerator('classic'); - $generator->generate($codeFinder, $diagram); + $generator->generate($codeFinder, $diagram, $this->display); $this->assertImagesSame($expectedDiagram, $diagram->value()); } @@ -76,7 +76,9 @@ private function createGenerator(string $theme): ClassDiagramGenerator ), new DotProcessor() ); - $generator->attach($this->prophesize(ProcessorProgressDisplay::class)->reveal()); + $this->display = new ConsoleProgressDisplay(new NullOutput()); return $generator; } + + private ?ConsoleProgressDisplay $display = null; } diff --git a/tests/integration/Generators/GenerateClassDiagramWithoutEmptyBlocksTest.php b/tests/integration/Generators/GenerateClassDiagramWithoutEmptyBlocksTest.php index 2953210..14b675e 100644 --- a/tests/integration/Generators/GenerateClassDiagramWithoutEmptyBlocksTest.php +++ b/tests/integration/Generators/GenerateClassDiagramWithoutEmptyBlocksTest.php @@ -9,6 +9,7 @@ use Lupka\PHPUnitCompareImages\CompareImagesTrait; use PHPUnit\Framework\TestCase; +use PhUml\Console\ConsoleProgressDisplay; use PhUml\Graphviz\Builders\ClassGraphBuilder; use PhUml\Graphviz\Builders\InterfaceGraphBuilder; use PhUml\Graphviz\Builders\TraitGraphBuilder; @@ -23,12 +24,11 @@ use PhUml\Processors\GraphvizProcessor; use PhUml\Processors\OutputFilePath; use PhUml\Templates\TemplateEngine; -use Prophecy\PhpUnit\ProphecyTrait; +use Symfony\Component\Console\Output\NullOutput; final class GenerateClassDiagramWithoutEmptyBlocksTest extends TestCase { use CompareImagesTrait; - use ProphecyTrait; /** * @test @@ -41,7 +41,7 @@ function it_removes_empty_blocks_if_only_definition_names_are_shown() $diagram = new OutputFilePath(__DIR__ . '/../../resources/.output/graphviz-dot-without-empty-blocks.png'); $expectedDiagram = __DIR__ . '/../../resources/images/graphviz-dot-without-empty-blocks.png'; - $this->generator->generate($finder, $diagram); + $this->generator->generate($finder, $diagram, $this->display); $this->assertImagesSame($expectedDiagram, $diagram->value()); } @@ -60,8 +60,10 @@ function let() ), new DotProcessor() ); - $this->generator->attach($this->prophesize(ProcessorProgressDisplay::class)->reveal()); + $this->display = new ConsoleProgressDisplay(new NullOutput()); } private ?ClassDiagramGenerator $generator = null; + + private ?ConsoleProgressDisplay $display = null; } diff --git a/tests/src/Fakes/StringCodeFinder.php b/tests/src/Fakes/StringCodeFinder.php index 7a85f2f..5bbae5a 100644 --- a/tests/src/Fakes/StringCodeFinder.php +++ b/tests/src/Fakes/StringCodeFinder.php @@ -19,7 +19,7 @@ public function __construct() $this->files = []; } - public function add(string $definition) + public function add(string $definition): void { $this->files[] = $definition; } diff --git a/tests/src/Fakes/TextInMemoryOutput.php b/tests/src/Fakes/TextInMemoryOutput.php deleted file mode 100644 index 1c5801e..0000000 --- a/tests/src/Fakes/TextInMemoryOutput.php +++ /dev/null @@ -1,82 +0,0 @@ -output; - } - - public function write($messages, $newline = false, $options = 0) - { - $this->output .= $messages; - } - - public function writeln($messages, $options = 0) - { - $this->output .= $messages . "\n"; - } - - public function setVerbosity($level) - { - // nothing to do - } - - public function getVerbosity() - { - return self::VERBOSITY_QUIET; - } - - public function isQuiet() - { - return true; - } - - public function isVerbose() - { - return false; - } - - public function isVeryVerbose() - { - return false; - } - - public function isDebug() - { - return false; - } - - public function setDecorated($decorated) - { - // do nothing - } - - public function isDecorated() - { - return false; - } - - public function setFormatter(OutputFormatterInterface $formatter) - { - // do nothing - } - - public function getFormatter() - { - return new OutputFormatter(); - } -} diff --git a/tests/unit/Console/Commands/GenerateClassDiagramCommandTest.php b/tests/unit/Console/Commands/GenerateClassDiagramCommandTest.php index 48c7929..77a3ad1 100644 --- a/tests/unit/Console/Commands/GenerateClassDiagramCommandTest.php +++ b/tests/unit/Console/Commands/GenerateClassDiagramCommandTest.php @@ -9,8 +9,6 @@ use PHPUnit\Framework\TestCase; use PhUml\Console\PhUmlApplication; -use PhUml\Console\ProgressDisplay; -use PhUml\Fakes\TextInMemoryOutput; use PhUml\Parser\InvalidDirectory; use RuntimeException; use Symfony\Component\Console\Command\Command; @@ -149,7 +147,7 @@ function it_generates_a_class_diagram_with_a_specific_theme() /** @before */ function let() { - $application = new PhUmlApplication(new ProgressDisplay(new TextInMemoryOutput())); + $application = new PhUmlApplication(); $this->command = $application->find('phuml:diagram'); $this->tester = new CommandTester($this->command); $this->pathToCode = __DIR__ . '/../../../resources/.code'; diff --git a/tests/unit/Console/Commands/GenerateDotFileCommandTest.php b/tests/unit/Console/Commands/GenerateDotFileCommandTest.php index e018260..f3854e8 100644 --- a/tests/unit/Console/Commands/GenerateDotFileCommandTest.php +++ b/tests/unit/Console/Commands/GenerateDotFileCommandTest.php @@ -9,8 +9,6 @@ use PHPUnit\Framework\TestCase; use PhUml\Console\PhUmlApplication; -use PhUml\Console\ProgressDisplay; -use PhUml\Fakes\TextInMemoryOutput; use PhUml\Parser\InvalidDirectory; use RuntimeException; use Symfony\Component\Console\Command\Command; @@ -89,7 +87,7 @@ function it_generates_a_dot_file_excluding_private_and_protected_members() /** @before */ function configureCommandTester() { - $application = new PhUmlApplication(new ProgressDisplay(new TextInMemoryOutput())); + $application = new PhUmlApplication(); $this->command = $application->find('phuml:dot'); $this->tester = new CommandTester($this->command); $this->pathToCode = __DIR__ . '/../../../resources/.code'; diff --git a/tests/unit/Console/Commands/GenerateStatisticsCommandTest.php b/tests/unit/Console/Commands/GenerateStatisticsCommandTest.php index 5f007dc..3153ed7 100644 --- a/tests/unit/Console/Commands/GenerateStatisticsCommandTest.php +++ b/tests/unit/Console/Commands/GenerateStatisticsCommandTest.php @@ -9,8 +9,6 @@ use PHPUnit\Framework\TestCase; use PhUml\Console\PhUmlApplication; -use PhUml\Console\ProgressDisplay; -use PhUml\Fakes\TextInMemoryOutput; use PhUml\Parser\InvalidDirectory; use RuntimeException; use Symfony\Component\Console\Command\Command; @@ -57,7 +55,7 @@ function it_generates_the_statistics_of_a_given_directory_using_the_recursive_op /** @before */ function let() { - $application = new PhUmlApplication(new ProgressDisplay(new TextInMemoryOutput())); + $application = new PhUmlApplication(); $this->command = $application->find('phuml:statistics'); $this->tester = new CommandTester($this->command); $this->statistics = __DIR__ . '/../../../resources/.output/statistics.txt'; diff --git a/tests/unit/Console/ProgressDisplayTest.php b/tests/unit/Console/ProgressDisplayTest.php index a0b9b57..2e5f077 100644 --- a/tests/unit/Console/ProgressDisplayTest.php +++ b/tests/unit/Console/ProgressDisplayTest.php @@ -55,10 +55,10 @@ function it_displays_saving_result_message() public function let() { $this->output = new BufferedOutput(); - $this->display = new ProgressDisplay($this->output); + $this->display = new ConsoleProgressDisplay($this->output); } private BufferedOutput $output; - private ProgressDisplay $display; + private ConsoleProgressDisplay $display; } diff --git a/tests/unit/Generators/GenerateDotFileTest.php b/tests/unit/Generators/GenerateDotFileTest.php index 4ef905b..bf390ff 100644 --- a/tests/unit/Generators/GenerateDotFileTest.php +++ b/tests/unit/Generators/GenerateDotFileTest.php @@ -7,11 +7,10 @@ namespace PhUml\Generators; -use LogicException; use PHPUnit\Framework\TestCase; +use PhUml\Console\ConsoleProgressDisplay; use PhUml\Fakes\ExternalNumericIdDefinitionsResolver; use PhUml\Fakes\NumericIdClassDefinitionBuilder; -use PhUml\Fakes\StringCodeFinder; use PhUml\Fakes\WithDotLanguageAssertions; use PhUml\Fakes\WithNumericIds; use PhUml\Parser\Code\PhpCodeParser; @@ -21,30 +20,19 @@ use PhUml\Processors\GraphvizProcessor; use PhUml\Processors\OutputFilePath; use PhUml\TestBuilders\A; -use Prophecy\PhpUnit\ProphecyTrait; +use Symfony\Component\Console\Output\NullOutput; final class GenerateDotFileTest extends TestCase { use WithNumericIds; use WithDotLanguageAssertions; - use ProphecyTrait; - - /** @test */ - function it_fails_to_generate_the_dot_file_if_a_command_is_not_provided() - { - $generator = new DotFileGenerator(new CodeParser(new PhpCodeParser()), new GraphvizProcessor()); - - $this->expectException(LogicException::class); - - $generator->generate(new StringCodeFinder(), new OutputFilePath('wont-be-generated.gv')); - } /** @test */ function it_creates_the_dot_file_of_a_directory() { $finder = SourceCodeFinder::nonRecursive(new CodebaseDirectory($this->pathToCode)); - $this->generator->generate($finder, $this->pathToDotFile); + $this->generator->generate($finder, $this->pathToDotFile, $this->display); $this->resetIds(); $digraphInDotFormat = file_get_contents($this->pathToDotFile->value()); @@ -57,7 +45,7 @@ function it_creates_the_dot_file_of_a_directory_using_a_recursive_finder() { $finder = SourceCodeFinder::recursive(new CodebaseDirectory($this->pathToCode)); - $this->generator->generate($finder, $this->pathToDotFile); + $this->generator->generate($finder, $this->pathToDotFile, $this->display); $this->resetIds(); $base = A::numericIdClassNamed('plBase'); @@ -122,12 +110,14 @@ function let() ), new GraphvizProcessor() ); - $this->generator->attach($this->prophesize(ProcessorProgressDisplay::class)->reveal()); + $this->display = new ConsoleProgressDisplay(new NullOutput()); } private ?DotFileGenerator $generator = null; private ?OutputFilePath $pathToDotFile = null; + private ?ProgressDisplay $display = null; + private ?string $pathToCode = null; } diff --git a/tests/unit/Generators/GenerateStatisticsTest.php b/tests/unit/Generators/GenerateStatisticsTest.php index 2d2c21d..5de2577 100644 --- a/tests/unit/Generators/GenerateStatisticsTest.php +++ b/tests/unit/Generators/GenerateStatisticsTest.php @@ -7,9 +7,8 @@ namespace PhUml\Generators; -use LogicException; use PHPUnit\Framework\TestCase; -use PhUml\Fakes\StringCodeFinder; +use PhUml\Console\ConsoleProgressDisplay; use PhUml\Parser\Code\ExternalDefinitionsResolver; use PhUml\Parser\Code\PhpCodeParser; use PhUml\Parser\CodebaseDirectory; @@ -17,21 +16,10 @@ use PhUml\Parser\SourceCodeFinder; use PhUml\Processors\OutputFilePath; use PhUml\Processors\StatisticsProcessor; -use Prophecy\PhpUnit\ProphecyTrait; +use Symfony\Component\Console\Output\NullOutput; final class GenerateStatisticsTest extends TestCase { - use ProphecyTrait; - - /** @test */ - function it_fails_to_generate_the_statistics_if_a_command_is_not_provided() - { - $generator = new StatisticsGenerator(new CodeParser(new PhpCodeParser()), new StatisticsProcessor()); - - $this->expectException(LogicException::class); - $generator->generate(new StringCodeFinder(), new OutputFilePath('wont-be-generated.txt')); - } - /** @test */ function it_shows_the_statistics_of_a_directory() { @@ -62,12 +50,11 @@ function it_shows_the_statistics_of_a_directory() Functions per class: 5.5 STATS; - $generator = new StatisticsGenerator(new CodeParser(new PhpCodeParser()), new StatisticsProcessor()); - $generator->attach($this->prophesize(ProcessorProgressDisplay::class)->reveal()); + $display = new ConsoleProgressDisplay(new NullOutput()); $finder = SourceCodeFinder::nonRecursive(new CodebaseDirectory($this->pathToCode)); - $generator->generate($finder, $this->statisticsFile); + $generator->generate($finder, $this->statisticsFile, $display); $this->assertStringEqualsFile($this->statisticsFile->value(), $statistics); } @@ -102,13 +89,12 @@ function it_shows_the_statistics_of_a_directory_using_a_recursive_finder() Functions per class: 4.35 STATS; - $parser = new CodeParser(new PhpCodeParser(), [new ExternalDefinitionsResolver()]); $generator = new StatisticsGenerator($parser, new StatisticsProcessor()); - $generator->attach($this->prophesize(ProcessorProgressDisplay::class)->reveal()); + $display = new ConsoleProgressDisplay(new NullOutput()); $finder = SourceCodeFinder::recursive(new CodebaseDirectory($this->pathToCode)); - $generator->generate($finder, $this->statisticsFile); + $generator->generate($finder, $this->statisticsFile, $display); $this->assertStringEqualsFile($this->statisticsFile->value(), $statistics); }