Skip to content

Commit

Permalink
Improvements tests and minor fixes (#9)
Browse files Browse the repository at this point in the history
- Update command description to reflect schema validation.
- Update schema option description to include supported file types.
- Add a new task to the TODO list.
- Remove unnecessary comment from the code.
  • Loading branch information
SmetDenis committed Mar 11, 2024
1 parent ed56a66 commit 9fd89b7
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 218 deletions.
25 changes: 1 addition & 24 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,13 @@ jobs:
name: Reports - ${{ matrix.php-version }}
path: build/


docker:
name: Docker
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: 🐳 Building Docker Image
run: make build-docker
Expand All @@ -193,25 +192,3 @@ jobs:
- name: Reporting example via Docker
run: make demo-docker --no-print-directory
continue-on-error: true

github-action:
name: GitHub Action
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: 👍 Valid CSV file
uses: ./
with:
csv: tests/fixtures/demo.csv
schema: tests/schemas/demo_valid.yml

- name: 👎 Invalid CSV file
uses: ./
with:
csv: tests/fixtures/demo.csv
schema: tests/schemas/demo_invalid.yml
continue-on-error: true
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ So there are options here for all occasions.
Description:
Validate CSV file by rule
Validate CSV file by schema.
Usage:
validate:csv [options]
Options:
-c, --csv=CSV CSV filepath to validate.
-s, --schema=SCHEMA Schema rule filepath.
-s, --schema=SCHEMA Schema rule filepath. It can be a .yml/.json/.php file.
-o, --output=OUTPUT Report output format. Available options: text, table, github, gitlab, teamcity, junit [default: "table"]
--no-progress Disable progress bar animation for logs. It will be used only for text output format.
--mute-errors Mute any sort of errors. So exit code will be always "0" (if it's possible).
Expand Down Expand Up @@ -445,6 +445,7 @@ It's random ideas and plans. No orderings and deadlines. <u>But batch processing

* [ ] Filename pattern validation with regex (like "all files in the folder should be in the format `/^[\d]{4}-[\d]{2}-[\d]{2}\.csv$/`").
* [ ] CSV/Schema file discovery in the folder with regex filename pattern (like `glob(./**/dir/*.csv)`).
* [ ] Build phar file and release via GitHub Actions.
* [ ] If option `--csv` is a folder, then validate all files in the folder.
* [ ] If option `--csv` is not specified, then the STDIN is used. To build a pipeline in Unix-like systems.
* [ ] If option `--schema` is not specified, then validate only super base level things (like "is it a CSV file?").
Expand Down
60 changes: 0 additions & 60 deletions src/Commands/CreateCsv.php

This file was deleted.

60 changes: 0 additions & 60 deletions src/Commands/CreateSchema.php

This file was deleted.

10 changes: 5 additions & 5 deletions src/Commands/ValidateCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,25 @@

/**
* @psalm-suppress PropertyNotSetInConstructor
* @codeCoverageIgnore
*/
final class ValidateCsv extends CliCommand
{
protected function configure(): void
{
$this
->setName('validate:csv')
->setDescription('Validate CSV file by rule')
->setDescription('Validate CSV file by schema.')
->addOption(
'csv',
'c',
InputOption::VALUE_REQUIRED,
'CSV filepath to validate. If not set or empty, then the STDIN is used.',
'CSV filepath to validate.',
)
->addOption(
'schema',
's',
InputOption::VALUE_REQUIRED,
'Schema rule filepath',
'Schema rule filepath. It can be a .yml/.json/.php file.',
)
->addOption(
'output',
Expand Down Expand Up @@ -73,7 +72,8 @@ protected function executeAction(): int

if ($this->isTextMode()) {
$this->_(
'<yellow>CSV file is not valid!</yellow> Found <e>' . $errorSuite->count() . '</e> errors.',
'<yellow>CSV file is not valid!</yellow> ' .
'Found <yellow>' . $errorSuite->count() . '<yellow> errors.',
OutLvl::E,
);
}
Expand Down
51 changes: 0 additions & 51 deletions src/Commands/ValidateDir.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Validators/ErrorSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function renderPlainText(): string
$result[] = (string)$error;
}

return \implode("\n", $result);
return \implode("\n", $result) . "\n";
}

private function renderTable(): string
Expand Down Expand Up @@ -161,7 +161,7 @@ private function prepareSourceSuite(): SourceSuite
$case = $suite->addTestCase($caseName);
$case->line = $error->getLine();
$case->file = $this->csvFilename;
$case->errOut = $error->getMessage();
$case->errOut = (string)$error;
}

return $suite;
Expand Down

0 comments on commit 9fd89b7

Please sign in to comment.