Skip to content

Commit

Permalink
Enhanced test coverage and updated documentation
Browse files Browse the repository at this point in the history
This commit includes a new test case to strengthen validation of empty strings in the RegexTest.php. Also, the schema in example_full.yml has been greatly expanded to encompass additional rules and aggregate rules for more comprehensive validation. Apart from that, the README.md content structure has been modified for better clarity and readability.
  • Loading branch information
Denis Smet committed Mar 17, 2024
1 parent eeae857 commit d17c81a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@ Integrating CSV validation into CI processes promotes higher data integrity, rel
* [demo.csv](tests/fixtures/demo.csv)


## Usage

Also see demo in the [GitHub Actions](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/demo.yml) file.

### Schema Definition
Define your CSV validation schema in a YAML file.
Define your CSV validation schema in a [YAML](schema-examples/full.yml). Other formats are also available: , [JSON](schema-examples/full.json), [PHP](schema-examples/full.php).

This example defines a simple schema for a CSV file with a header row, specifying that the `id` column must not be empty and must contain integer values.
Also, it checks that the `name` column has a minimum length of 3 characters.
Expand All @@ -74,6 +70,9 @@ columns:

```


### Full description of the scheme

In the [example Yml file](schema-examples/full.yml) you can find a detailed description of all features.
It's also covered by tests, so it's always up-to-date.

Expand All @@ -85,10 +84,6 @@ It's also covered by tests, so it's always up-to-date.
* You are always free to add your option anywhere (except the `rules` list) and it will be ignored. I find it convenient for additional integrations and customization.


### Schema file examples

Available formats: [YAML](schema-examples/full.yml), [JSON](schema-examples/full.json), [PHP](schema-examples/full.php).

```yml
# It's a full example of the CSV schema file in YAML format.

Expand Down Expand Up @@ -223,6 +218,11 @@ columns:
```


## Usage

You can find launch examples in the [workflow demo](https://github.com/JBZoo/Csv-Blueprint/actions/workflows/demo.yml).


### As GitHub Action

```yml
Expand Down Expand Up @@ -436,6 +436,8 @@ It's random ideas and plans. No orderings and deadlines. <u>But batch processing

**Validation**
* More aggregate rules.
* More cell rules.
* `required` flag for the column.
* Custom cell rule as a callback. It's useful when you have a complex rule that can't be described in the schema file.
* Custom agregate rule as a callback. It's useful when you have a complex rule that can't be described in the schema file.
* Configurable keyword for null/empty values. By default, it's an empty string. But you will use `null`, `nil`, `none`, `empty`, etc. Overridable on the column level.
Expand Down
1 change: 1 addition & 0 deletions tests/Rules/Cell/RegexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function testPositive(): void
isSame('', $rule->test('abc'));
isSame('', $rule->test('aaa'));
isSame('', $rule->test('a'));
isSame('', $rule->test(''));

$rule = $this->create('^a');
isSame('', $rule->test('abc'));
Expand Down
39 changes: 39 additions & 0 deletions tests/schemas/example_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,46 @@ csv: # How to parse file before validation
columns:
- name: General available options # Can be optional if csv\header: false. If set, then header must contain this value
required: true # If true, then column must be present in the file
rules:
is_ip6: true
dateperiod_: true
dateinterval_: true
bic: true
iban: true
card_number: true
country_code: true
currency_code: true
is_positive: true
is_negative: true
is_zero: true
is_even: true
is_odd: true
is_prime: true
is_time: true
is_timezone: true
is_timezone_offset: true
aggregate_rules:
sum_: true
avg_: true
median_: true
mode_: true
range_: true
variance_: true
stddev_: true
percentile_: true
quantile_: true
count_: true
count_distinct_: true
count_empty_: true
count_not_empty_: true
count_null_: true
count_not_null_: true
count_zero_: true
count_positive_: true
count_negative_: true
count_even_: true
count_odd_: true
count_prime_: true
sorted: asc # asc, desc, none
sorted_flag: SORT_NATURAL # See sort flags: https://www.php.net/manual/en/function.sort.php
count_min: 1
Expand Down

0 comments on commit d17c81a

Please sign in to comment.