Skip to content

Commit

Permalink
New Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Smet committed Mar 11, 2024
1 parent 478ea27 commit ffaccb5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/Csv/CsvFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(string $csvFilename, null|array|string $csvSchemaFil

public function getCsvFilename(): string
{
return \pathinfo((string)\realpath($this->csvFilename), \PATHINFO_BASENAME);
return $this->csvFilename;
}

public function getCsvStructure(): ParseConfig
Expand Down
11 changes: 8 additions & 3 deletions src/Validators/ErrorSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ private function renderTable(): string
{
$buffer = new BufferedOutput();
$table = (new Table($buffer))
->setHeaderTitle($this->csvFilename)
->setFooterTitle($this->csvFilename)
->setHeaderTitle($this->getTestcaseName())
->setFooterTitle($this->getTestcaseName())
->setHeaders(['Line', 'id:Column', 'Rule', 'Message'])
->setColumnMaxWidth(0, 10)
->setColumnMaxWidth(1, 20)
Expand All @@ -154,7 +154,7 @@ private function renderTable(): string

private function prepareSourceSuite(): SourceSuite
{
$suite = new SourceSuite($this->csvFilename);
$suite = new SourceSuite($this->getTestcaseName());

foreach ($this->errors as $error) {
$caseName = $error->getRuleCode() . ' at column ' . $error->getColumnName();
Expand All @@ -166,4 +166,9 @@ private function prepareSourceSuite(): SourceSuite

return $suite;
}

private function getTestcaseName(): string
{
return \pathinfo((string)\realpath((string)$this->csvFilename), \PATHINFO_BASENAME);
}
}
4 changes: 2 additions & 2 deletions tests/Blueprint/CsvReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class CsvReaderTest extends PHPUnit
public function testReadCsvFileWithoutHeader(): void
{
$csv = new CsvFile(self::CSV_SIMPLE_NO_HEADER, self::SCHEMA_SIMPLE_NO_HEADER);
isSame('simple_no_header.csv', $csv->getCsvFilename());
isSame(self::CSV_SIMPLE_NO_HEADER, $csv->getCsvFilename());

isSame([], $csv->getHeader());

Expand All @@ -50,7 +50,7 @@ public function testReadCsvFileWithoutHeader(): void
public function testReadCsvFileWithHeader(): void
{
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, self::SCHEMA_SIMPLE_HEADER);
isSame('simple_header.csv', $csv->getCsvFilename());
isSame(self::CSV_SIMPLE_HEADER, $csv->getCsvFilename());

isSame(['seq', 'bool', 'exact'], $csv->getHeader());

Expand Down
46 changes: 27 additions & 19 deletions tests/Blueprint/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,13 @@ public function testRenderTable(): void

public function testRenderTeamCity(): void
{
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, $this->getRule('seq', 'min', 3));
$out = $csv->validate()->render(ErrorSuite::RENDER_TEAMCITY);
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, $this->getRule('seq', 'min', 3));
$out = $csv->validate()->render(ErrorSuite::RENDER_TEAMCITY);
$path = self::CSV_SIMPLE_HEADER;

isContain("##teamcity[testCount count='2' ", $out);
isContain("##teamcity[testSuiteStarted name='simple_header.csv' ", $out);
isContain("##teamcity[testStarted name='min at column 0:seq' locationHint='php_qn://simple_header.csv'", $out);
isContain("##teamcity[testStarted name='min at column 0:seq' locationHint='php_qn://{$path}'", $out);
isContain("##teamcity[testFinished name='min at column 0:seq' timestamp", $out);
isContain('Value "1" is less than "3"', $out);
isContain('Value "2" is less than "3"', $out);
Expand All @@ -475,12 +476,13 @@ public function testRenderTeamCity(): void

public function testRenderGithub(): void
{
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, $this->getRule('seq', 'min', 3));
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, $this->getRule('seq', 'min', 3));
$path = self::CSV_SIMPLE_HEADER;
isSame(
\implode("\n", [
'::error file=simple_header.csv,line=2::min at column 0:seq%0AValue "1" is less than "3"',
"::error file={$path},line=2::min at column 0:seq%0AValue \"1\" is less than \"3\"",
'',
'::error file=simple_header.csv,line=3::min at column 0:seq%0AValue "2" is less than "3"',
"::error file={$path},line=3::min at column 0:seq%0AValue \"2\" is less than \"3\"",
'',
]),
$csv->validate()->render(ErrorSuite::RENDER_GITHUB),
Expand All @@ -489,44 +491,50 @@ public function testRenderGithub(): void

public function testRenderGitlab(): void
{
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, $this->getRule('seq', 'min', 3));
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, $this->getRule('seq', 'min', 3));
$path = self::CSV_SIMPLE_HEADER;

$cleanJson = json($csv->validate()->render(ErrorSuite::RENDER_GITLAB))->getArrayCopy();
unset($cleanJson[0]['fingerprint'], $cleanJson[1]['fingerprint']);

isSame(
[
[
'description' => "min at column 0:seq\nValue \"1\" is less than \"3\"",
'fingerprint' => 'ec0612c9f1610d440b558fff51bbceed086a0212cdeb14d79d09c8a9bd108487',
'severity' => 'major',
'location' => [
'path' => 'simple_header.csv',
// 'fingerprint' => '2c2639beb20e2e9ea13a414ce91865522f6e1885abcf1f99ada44de007cdb01f',
'severity' => 'major',
'location' => [
'path' => $path,
'lines' => ['begin' => 2],
],
],
[
'description' => "min at column 0:seq\nValue \"2\" is less than \"3\"",
'fingerprint' => '51f82750d029c395dec5f2f5c1c4eb841e43c1ea6b8ece9ee31126a3e22620cb',
'severity' => 'major',
'location' => [
'path' => 'simple_header.csv',
// 'fingerprint' => '0cda6e2df28be9033542ab504e315d070951a206446eb7005d2060d44cfa0e45',
'severity' => 'major',
'location' => [
'path' => $path,
'lines' => ['begin' => 3],
],
],
],
json($csv->validate()->render(ErrorSuite::RENDER_GITLAB))->getArrayCopy(),
$cleanJson,
);
}

public function testRenderJUnit(): void
{
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, $this->getRule('seq', 'min', 3));
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, $this->getRule('seq', 'min', 3));
$path = self::CSV_SIMPLE_HEADER;
isSame(
\implode("\n", [
'<?xml version="1.0" encoding="UTF-8"?>',
'<testsuites>',
' <testsuite name="simple_header.csv" tests="2">',
' <testcase name="min at column 0:seq" file="simple_header.csv" line="2">',
" <testcase name=\"min at column 0:seq\" file=\"{$path}\" line=\"2\">",
' <system-out>Value "1" is less than "3"</system-out>',
' </testcase>',
' <testcase name="min at column 0:seq" file="simple_header.csv" line="3">',
" <testcase name=\"min at column 0:seq\" file=\"{$path}\" line=\"3\">",
' <system-out>Value "2" is less than "3"</system-out>',
' </testcase>',
' </testsuite>',
Expand Down

0 comments on commit ffaccb5

Please sign in to comment.