Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove condition in validation check for CSV files #151

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ You can find launch examples in the [workflow demo](https://github.com/JBZoo/Csv
with:
# Specify the path(s) to the CSV files you want to validate.
# This can include a direct path to a file or a directory to search with a maximum depth of 10 levels.
# Examples: /full/path/name.csv; p/file.csv; p/*.csv; p/**/*.csv; p/**/name-*.csv; **/*.csv
# Examples: p/file.csv; p/*.csv; p/**/*.csv; p/**/name-*.csv; **/*.csv
# Required: true
csv: './tests/**/*.csv'

# Specify the path(s) to the schema file(s), supporting YAML, JSON, or PHP formats.
# Similar to CSV paths, you can direct to specific files or search directories with glob patterns.
# Examples: /full/path/name.yml; p/file.yml; p/*.yml; p/**/*.yml; p/**/name-*.yml; **/*.yml
# Examples: p/file.yml; p/*.yml; p/**/*.yml; p/**/name-*.yml; **/*.yml
# Required: true
schema: './tests/**/*.yml'

Expand Down Expand Up @@ -976,6 +976,7 @@ In fact, this can be considered as partial inheritance.
- You can make the chain of inheritance infinitely long.
I.e. make chains of the form `grant-parent.yml` -> `parent.yml` -> `child.yml` -> `grandchild.yml` -> etc.
Of course if you like to take risks ;).
- But be careful with circular dependencies. The tool will not be able to handle them, and it can be an infinite loop.
- Any(!) of the schema files can be used alone or as a library. The syntax is the same.
- Schemas with presets validate themselves and if there are any obvious issues, you will see them when you try to use
the schema. But logical conflicts between rules are not checked (It's almost impossible from a code perspective).
Expand Down Expand Up @@ -1441,11 +1442,11 @@ Usage:
Options:
-c, --csv=CSV Specify the path(s) to the CSV files you want to validate.
This can include a direct path to a file or a directory to search with a maximum depth of 10 levels.
Examples: /full/path/name.csv; p/file.csv; p/*.csv; p/**/*.csv; p/**/name-*.csv; **/*.csv
Examples: p/file.csv; p/*.csv; p/**/*.csv; p/**/name-*.csv; **/*.csv
(multiple values allowed)
-s, --schema=SCHEMA Specify the path(s) to the schema file(s), supporting YAML, JSON, or PHP formats.
Similar to CSV paths, you can direct to specific files or search directories with glob patterns.
Examples: /full/path/name.yml; p/file.yml; p/*.yml; p/**/*.yml; p/**/name-*.yml; **/*.yml
Examples: p/file.yml; p/*.yml; p/**/*.yml; p/**/name-*.yml; **/*.yml
(multiple values allowed)
-S, --skip-schema[=SKIP-SCHEMA] Skips schema validation for quicker checks when the schema's correctness is certain.
Use any non-empty value or "yes" to activate
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ inputs:
description: |
Specify the path(s) to the CSV files you want to validate.
This can include a direct path to a file or a directory to search with a maximum depth of 10 levels.
Examples: /full/path/name.csv; p/file.csv; p/*.csv; p/**/*.csv; p/**/name-*.csv; **/*.csv
Examples: p/file.csv; p/*.csv; p/**/*.csv; p/**/name-*.csv; **/*.csv
required: true
schema:
description: |
Specify the path(s) to the schema file(s), supporting YAML, JSON, or PHP formats.
Similar to CSV paths, you can direct to specific files or search directories with glob patterns.
Examples: /full/path/name.yml; p/file.yml; p/*.yml; p/**/*.yml; p/**/name-*.yml; **/*.yml
Examples: p/file.yml; p/*.yml; p/**/*.yml; p/**/name-*.yml; **/*.yml
required: true
report:
description: 'Report format. Available options: text, table, github, gitlab, teamcity, junit.'
Expand Down
3 changes: 0 additions & 3 deletions src/Commands/ValidateCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ protected function configure(): void
'This can include a direct path to a file or a directory to search with a maximum depth of ' .
Utils::MAX_DIRECTORY_DEPTH . ' levels.',
'Examples: <info>' . \implode('</info>; <info>', [
'/full/path/name.csv',
'p/file.csv',
'p/*.csv',
'p/**/*.csv',
Expand All @@ -63,7 +62,6 @@ protected function configure(): void
'Specify the path(s) to the schema file(s), supporting YAML, JSON, or PHP formats. ',
'Similar to CSV paths, you can direct to specific files or search directories with glob patterns.',
'Examples: <info>' . \implode('</info>; <info>', [
'/full/path/name.yml',
'p/file.yml',
'p/*.yml',
'p/**/*.yml',
Expand Down Expand Up @@ -245,7 +243,6 @@ private function printSummary(
$totalSchemaFiles === 0
|| $errorInCsvCounter > 0
|| $errorInSchemaCounter > 0
|| \count($matchedFiles['schema_without_csv']) > 0
|| \count($matchedFiles['csv_without_schema']) > 0
) {
$exitCode = self::FAILURE;
Expand Down
3 changes: 2 additions & 1 deletion tests/Commands/ValidateCsvApplyAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ public function testNoPatternApplyAllAutoNegativeMany(): void
No issues in 1 CSV files.
Not used schemas:
* ./tests/schemas/demo_invalid_no_pattern.yml
Looks good!


TXT;

isSame(1, $exitCode, $actual);
isSame(0, $exitCode, $actual);
isSame($expected, $actual);
}

Expand Down
42 changes: 40 additions & 2 deletions tests/Commands/ValidateCsvBasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ public function testValidateOneCsvWithInvalidSchemaNegative(): void
isSame($expected, $actual);
}

// ###################################################################################################################

public function testInvalidSchemaNotMatched(): void
{
$options = [
Expand Down Expand Up @@ -317,4 +315,44 @@ public function testNothingFound(): void
isSame(1, $exitCode, $actual);
isSame($expected, $actual);
}

public function testNoSchemaWasAppliedToCsv(): void
{
$optionsAsString = Tools::arrayToOptionString([
'csv' => './tests/fixtures/demo.csv',
'schema' => [
'./tests/schemas/preset/child-of-child.yml',
'./tests/schemas/demo_valid.yml',
],
]);
[$actual, $exitCode] = Tools::virtualExecution('validate:csv', $optionsAsString);

$expected = <<<'TXT'
CSV Blueprint: Unknown version (PhpUnit)
Found Schemas : 2
Found CSV files : 1
Pairs by pattern: 1

Check schema syntax: 2
(1/2) OK ./tests/schemas/demo_valid.yml
(2/2) OK ./tests/schemas/preset/child-of-child.yml

CSV file validation: 1
Schema: ./tests/schemas/demo_valid.yml
OK ./tests/fixtures/demo.csv; Size: 123.34 MB

Summary:
1 pairs (schema to csv) were found based on `filename_pattern`.
No issues in 2 schemas.
No issues in 1 CSV files.
Not used schemas:
* ./tests/schemas/preset/child-of-child.yml
Looks good!


TXT;

isSame(0, $exitCode, $actual);
isSame($expected, $actual);
}
}