Skip to content

Commit

Permalink
Add tests for --verbose and --color options
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Aug 19, 2023
1 parent 6d7178a commit 8d0373d
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/test/php/PHPMD/Renderer/TextRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,82 @@ public function testRendererCreatesExpectedNumberOfTextEntries()
);
}

/**
* @return void
*/
public function testRendererSupportVerbose()
{
// Create a writer instance.
$writer = new WriterStub();
$rule = new RuleStub();
$rule->setName('LongerNamedRule');
$rule->setDescription('An other description for this rule');

$renderer = new TextRenderer();
$renderer->setWriter($writer);
$renderer->setVerbosityLevel(1);

$violations = array(
$this->getRuleViolationMock('/bar.php', 1, 42, $rule, $rule->getDescription()),
);

$report = $this->getReportWithNoViolation();
$report->expects($this->once())
->method('getRuleViolations')
->will($this->returnValue(new ArrayIterator($violations)));
$report->expects($this->once())
->method('getErrors')
->will($this->returnValue(new ArrayIterator(array())));

$renderer->start();
$renderer->renderReport($report);
$renderer->end();

$this->assertEquals(
'LongerNamedRule An other description for this rule' . PHP_EOL .
'📁 in /bar.php on line 1' . PHP_EOL .
'🔗 testruleset.xml https://phpmd.org/rules/testruleset.html#longernamedrule' . PHP_EOL . PHP_EOL,
$writer->getData()
);
}

/**
* @return void
*/
public function testRendererSupportColor()
{
// Create a writer instance.
$writer = new WriterStub();
$rule = new RuleStub();
$rule->setName('LongerNamedRule');
$rule->setDescription('An other description for this rule');

$renderer = new TextRenderer();
$renderer->setWriter($writer);
$renderer->setColored(true);

$violations = array(
$this->getRuleViolationMock('/bar.php', 1, 42, $rule, $rule->getDescription()),
);

$report = $this->getReportWithNoViolation();
$report->expects($this->once())
->method('getRuleViolations')
->will($this->returnValue(new ArrayIterator($violations)));
$report->expects($this->once())
->method('getErrors')
->will($this->returnValue(new ArrayIterator(array())));

$renderer->start();
$renderer->renderReport($report);
$renderer->end();

$this->assertEquals(
"/bar.php:1 \033[33mLongerNamedRule\033[0m \033[31mAn other description for this rule\033[0m" . PHP_EOL,
$writer->getData()
);
}

/**
* testRendererAddsProcessingErrorsToTextReport
*
Expand Down

0 comments on commit 8d0373d

Please sign in to comment.