diff --git a/.github/assets/output-text.png b/.github/assets/output-text.png
new file mode 100644
index 00000000..f7685f89
Binary files /dev/null and b/.github/assets/output-text.png differ
diff --git a/Makefile b/Makefile
index d620b0aa..880e4b8a 100644
--- a/Makefile
+++ b/Makefile
@@ -76,7 +76,8 @@ demo-invalid: ##@Project Run demo invalid CSV
$(call title,"Demo - Invalid CSV")
@${PHP_BIN} ./csv-blueprint validate:csv \
--csv=./tests/fixtures/demo.csv \
- --schema=./tests/schemas/demo_invalid.yml
+ --schema=./tests/schemas/demo_invalid.yml \
+ --output=$(OUTPUT)
demo-github: ##@Project Run demo invalid CSV
diff --git a/README.md b/README.md
index ca63f6b6..686bf525 100644
--- a/README.md
+++ b/README.md
@@ -200,32 +200,41 @@ As a result of the validation process, you will receive a human-readable table w
Default output format is `table`:
```
+./csv-blueprint validate:csv --output=table
+
+
CSV : ./tests/fixtures/demo.csv
Schema : ./tests/schemas/demo_invalid.yml
-+------+------------------+--------------+-- demo.csv -------------------------------------------+
-| Line | id:Column | Rule | Message |
-+------+------------------+--------------+-------------------------------------------------------+
-| 1 | 1: | csv.header | Property "name" is not defined in schema: |
-| | | | "./tests/schemas/demo_invalid.yml" |
-| 5 | 2:Float | max | Value "74605.944" is greater than "74605" |
-| 5 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", |
-| | | | "green", "Blue"] |
-| 6 | 0:Name | min_length | Value "Carl" (legth: 4) is too short. Min length is 5 |
-| 6 | 3:Birthday | min_date | Value "1955-05-14" is less than the minimum date |
-| | | | "1955-05-15T00:00:00.000+00:00" |
-| 8 | 3:Birthday | min_date | Value "1955-05-14" is less than the minimum date |
-| | | | "1955-05-15T00:00:00.000+00:00" |
-| 9 | 3:Birthday | max_date | Value "2010-07-20" is more than the maximum date |
-| | | | "2009-01-01T00:00:00.000+00:00" |
-| 11 | 0:Name | min_length | Value "Lois" (legth: 4) is too short. Min length is 5 |
-| 11 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", |
-| | | | "green", "Blue"] |
-+------+------------------+--------------+-- demo.csv -------------------------------------------+
-
-CSV file is not valid! Found 9 errors.
+
++------+------------------+--------------+-- demo.csv --------------------------------------------+
+| Line | id:Column | Rule | Message |
++------+------------------+--------------+--------------------------------------------------------+
+| 1 | 1: | csv.header | Property "name" is not defined in schema: |
+| | | | "./tests/schemas/demo_invalid.yml" |
+| 5 | 2:Float | max | Value "74605.944" is greater than "74605" |
+| 5 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", |
+| | | | "green", "Blue"] |
+| 6 | 0:Name | min_length | Value "Carl" (length: 4) is too short. Min length is 5 |
+| 6 | 3:Birthday | min_date | Value "1955-05-14" is less than the minimum date |
+| | | | "1955-05-15T00:00:00.000+00:00" |
+| 8 | 3:Birthday | min_date | Value "1955-05-14" is less than the minimum date |
+| | | | "1955-05-15T00:00:00.000+00:00" |
+| 9 | 3:Birthday | max_date | Value "2010-07-20" is more than the maximum date |
+| | | | "2009-01-01T00:00:00.000+00:00" |
+| 11 | 0:Name | min_length | Value "Lois" (length: 4) is too short. Min length is 5 |
++------+------------------+--------------+-- demo.csv --------------------------------------------+
+
+CSV file is not valid! Found 8 errors.
```
+Optional output format `text`:
+```sh
+./csv-blueprint validate:csv --output=text
+```
+
+![Output - Text](.github/assets/output-text.png)
+
### Schema Definition
Define your CSV validation schema in a YAML file.
diff --git a/src/Commands/ValidateCsv.php b/src/Commands/ValidateCsv.php
index 637c74b4..32291220 100644
--- a/src/Commands/ValidateCsv.php
+++ b/src/Commands/ValidateCsv.php
@@ -73,7 +73,7 @@ protected function executeAction(): int
if ($this->isTextMode()) {
$this->_(
'CSV file is not valid! ' .
- 'Found ' . $errorSuite->count() . ' errors.',
+ 'Found ' . $errorSuite->count() . ' errors.',
OutLvl::E,
);
}
@@ -113,6 +113,7 @@ private function getSchemaFilepath(): string
if ($this->isTextMode()) {
$this->_('Schema : ' . \realpath($schemaFilename));
+ $this->_('');
}
return $schemaFilename;
diff --git a/src/Csv/CsvFile.php b/src/Csv/CsvFile.php
index dfd9cbd9..b5d74875 100644
--- a/src/Csv/CsvFile.php
+++ b/src/Csv/CsvFile.php
@@ -113,7 +113,7 @@ private function validateHeader(): ErrorSuite
if ($column->getName() === '') {
$error = new Error(
'csv.header',
- "Property \"name\" is not defined in schema: \"{$this->schema->getFilename()}\"",
+ "Property \"name\" is not defined in schema: \"{$this->schema->getFilename()}\"",
$column->getHumanName(),
1,
);
diff --git a/src/Validators/Error.php b/src/Validators/Error.php
index e87c7fce..9bc33fda 100644
--- a/src/Validators/Error.php
+++ b/src/Validators/Error.php
@@ -28,7 +28,7 @@ public function __construct(
public function __toString(): string
{
- return "\"{$this->getRuleCode()}\" at line {$this->getLine()}, " .
+ return "\"{$this->getRuleCode()}\" at line {$this->getLine()}, " .
"column \"{$this->getColumnName()}\". {$this->getMessage()}.";
}
@@ -37,8 +37,12 @@ public function getRuleCode(): string
return $this->ruleCode;
}
- public function getMessage(): string
+ public function getMessage(bool $noTags = false): string
{
+ if ($noTags) {
+ return \strip_tags(\rtrim($this->message));
+ }
+
return \rtrim($this->message, '.');
}
@@ -52,6 +56,11 @@ public function getLine(): int
return $this->line;
}
+ public function toCleanString(): string
+ {
+ return \strip_tags((string)$this);
+ }
+
public function toArray(): array
{
return [
diff --git a/src/Validators/ErrorSuite.php b/src/Validators/ErrorSuite.php
index 0c95d7a4..f9d128b7 100644
--- a/src/Validators/ErrorSuite.php
+++ b/src/Validators/ErrorSuite.php
@@ -144,7 +144,12 @@ private function renderTable(): string
->setColumnMaxWidth(3, 60);
foreach ($this->errors as $error) {
- $table->addRow([$error->getLine(), $error->getColumnName(), $error->getRuleCode(), $error->getMessage()]);
+ $table->addRow([
+ $error->getLine(),
+ $error->getColumnName(),
+ $error->getRuleCode(),
+ $error->getMessage(true),
+ ]);
}
$table->render();
@@ -161,7 +166,7 @@ private function prepareSourceSuite(): SourceSuite
$case = $suite->addTestCase($caseName);
$case->line = $error->getLine();
$case->file = $this->csvFilename;
- $case->errOut = (string)$error;
+ $case->errOut = $error->toCleanString();
}
return $suite;
diff --git a/src/Validators/Rules/AllowValues.php b/src/Validators/Rules/AllowValues.php
index ed83ecd4..11dbcf21 100644
--- a/src/Validators/Rules/AllowValues.php
+++ b/src/Validators/Rules/AllowValues.php
@@ -27,8 +27,8 @@ public function validateRule(?string $cellValue): ?string
}
if (!\in_array($cellValue, $allowedValues, true)) {
- return "Value \"{$cellValue}\" is not allowed. " .
- 'Allowed values: ["' . \implode('", "', $allowedValues) . '"]';
+ return "Value \"{$cellValue}\" is not allowed. " .
+ 'Allowed values: ["' . \implode('", "', $allowedValues) . '"]';
}
return null;
diff --git a/src/Validators/Rules/DateFormat.php b/src/Validators/Rules/DateFormat.php
index 3e3e45ea..ec3f80da 100644
--- a/src/Validators/Rules/DateFormat.php
+++ b/src/Validators/Rules/DateFormat.php
@@ -31,7 +31,8 @@ public function validateRule(?string $cellValue): ?string
$date = \DateTimeImmutable::createFromFormat($expectedDateFormat, $cellValue);
if ($date === false || $date->format($expectedDateFormat) !== $cellValue) {
- return "Date format of value \"{$cellValue}\" is not valid. Expected format: \"{$expectedDateFormat}\"";
+ return "Date format of value \"{$cellValue}\" is not valid. " .
+ "Expected format: \"{$expectedDateFormat}\"";
}
return null;
diff --git a/src/Validators/Rules/ExactValue.php b/src/Validators/Rules/ExactValue.php
index 31f71d80..317aa0cb 100644
--- a/src/Validators/Rules/ExactValue.php
+++ b/src/Validators/Rules/ExactValue.php
@@ -21,7 +21,8 @@ final class ExactValue extends AbstarctRule
public function validateRule(?string $cellValue): ?string
{
if ($this->getOptionAsString() !== (string)$cellValue) {
- return "Value \"{$cellValue}\" is not strict equal to \"{$this->getOptionAsString()}\"";
+ return "Value \"{$cellValue}\" is not strict equal to " .
+ "\"{$this->getOptionAsString()}\"";
}
return null;
diff --git a/src/Validators/Rules/IsDomain.php b/src/Validators/Rules/IsDomain.php
index 88bea459..e815db76 100644
--- a/src/Validators/Rules/IsDomain.php
+++ b/src/Validators/Rules/IsDomain.php
@@ -27,7 +27,7 @@ public function validateRule(?string $cellValue): ?string
$domainPattern = '/^(?!-)[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,})$/';
if (\preg_match($domainPattern, (string)$cellValue) === 0) {
- return "Value \"{$cellValue}\" is not a valid domain";
+ return "Value \"{$cellValue}\" is not a valid domain";
}
return null;
diff --git a/src/Validators/Rules/IsEmail.php b/src/Validators/Rules/IsEmail.php
index 010f51ea..f26cc9dc 100644
--- a/src/Validators/Rules/IsEmail.php
+++ b/src/Validators/Rules/IsEmail.php
@@ -25,7 +25,7 @@ public function validateRule(?string $cellValue): ?string
}
if (\filter_var($cellValue, \FILTER_VALIDATE_EMAIL) === false) {
- return "Value \"{$cellValue}\" is not a valid email";
+ return "Value \"{$cellValue}\" is not a valid email";
}
return null;
diff --git a/src/Validators/Rules/IsFloat.php b/src/Validators/Rules/IsFloat.php
index 74b61dea..644b11aa 100644
--- a/src/Validators/Rules/IsFloat.php
+++ b/src/Validators/Rules/IsFloat.php
@@ -25,7 +25,7 @@ public function validateRule(?string $cellValue): ?string
}
if (\preg_match('/^-?\d+(\.\d+)?$/', (string)$cellValue) === 0) {
- return "Value \"{$cellValue}\" is not a float number";
+ return "Value \"{$cellValue}\" is not a float number";
}
return null;
diff --git a/src/Validators/Rules/IsInt.php b/src/Validators/Rules/IsInt.php
index 069fca8f..4581f04a 100644
--- a/src/Validators/Rules/IsInt.php
+++ b/src/Validators/Rules/IsInt.php
@@ -25,7 +25,7 @@ public function validateRule(?string $cellValue): ?string
}
if (\preg_match('/^-?\d+$/', (string)$cellValue) === 0) {
- return "Value \"{$cellValue}\" is not an integer";
+ return "Value \"{$cellValue}\" is not an integer";
}
return null;
diff --git a/src/Validators/Rules/IsIp.php b/src/Validators/Rules/IsIp.php
index 814c3bf1..ccc5fc98 100644
--- a/src/Validators/Rules/IsIp.php
+++ b/src/Validators/Rules/IsIp.php
@@ -25,7 +25,7 @@ public function validateRule(?string $cellValue): ?string
}
if (\filter_var($cellValue, \FILTER_VALIDATE_IP) === false) {
- return "Value \"{$cellValue}\" is not a valid IP";
+ return "Value \"{$cellValue}\" is not a valid IP";
}
return null;
diff --git a/src/Validators/Rules/IsLatitude.php b/src/Validators/Rules/IsLatitude.php
index 5085519e..7a670fb6 100644
--- a/src/Validators/Rules/IsLatitude.php
+++ b/src/Validators/Rules/IsLatitude.php
@@ -34,7 +34,7 @@ public function validateRule(?string $cellValue): ?string
$latitude = (float)$cellValue;
if ($latitude < $this->min || $latitude > $this->max) {
- return "Value \"{$cellValue}\" is not a valid latitude ({$this->min} <= x <= {$this->max})";
+ return "Value \"{$cellValue}\" is not a valid latitude ({$this->min} -> {$this->max})";
}
return null;
diff --git a/src/Validators/Rules/IsLongitude.php b/src/Validators/Rules/IsLongitude.php
index 97b06c28..31f2a53b 100644
--- a/src/Validators/Rules/IsLongitude.php
+++ b/src/Validators/Rules/IsLongitude.php
@@ -34,7 +34,8 @@ public function validateRule(?string $cellValue): ?string
$longitude = (float)$cellValue;
if ($longitude < $this->min || $longitude > $this->max) {
- return "Value \"{$cellValue}\" is not a valid longitude ({$this->min} <= x <= {$this->max})";
+ return "Value \"{$cellValue}\" is not a valid longitude " .
+ "({$this->min} -> {$this->max})";
}
return null;
diff --git a/src/Validators/Rules/IsUrl.php b/src/Validators/Rules/IsUrl.php
index 8bc1a242..f2fba082 100644
--- a/src/Validators/Rules/IsUrl.php
+++ b/src/Validators/Rules/IsUrl.php
@@ -25,7 +25,7 @@ public function validateRule(?string $cellValue): ?string
}
if (\filter_var($cellValue, \FILTER_VALIDATE_URL) === false) {
- return "Value \"{$cellValue}\" is not a valid URL";
+ return "Value \"{$cellValue}\" is not a valid URL";
}
return null;
diff --git a/src/Validators/Rules/Max.php b/src/Validators/Rules/Max.php
index 9ce9b0a8..7a0cb9bc 100644
--- a/src/Validators/Rules/Max.php
+++ b/src/Validators/Rules/Max.php
@@ -26,7 +26,7 @@ public function validateRule(?string $cellValue): ?string
}
if ($this->getOptionAsFloat() < (float)$cellValue) {
- return "Value \"{$cellValue}\" is greater than \"{$this->getOptionAsFloat()}\"";
+ return "Value \"{$cellValue}\" is greater than \"{$this->getOptionAsFloat()}\"";
}
return null;
diff --git a/src/Validators/Rules/MaxDate.php b/src/Validators/Rules/MaxDate.php
index 434ceeb2..3dc0612f 100644
--- a/src/Validators/Rules/MaxDate.php
+++ b/src/Validators/Rules/MaxDate.php
@@ -24,8 +24,8 @@ public function validateRule(?string $cellValue): ?string
$cellDate = new \DateTimeImmutable((string)$cellValue);
if ($cellDate->getTimestamp() > $minDate->getTimestamp()) {
- return "Value \"{$cellValue}\" is more than the maximum " .
- "date \"{$minDate->format(\DATE_RFC3339_EXTENDED)}\"";
+ return "Value \"{$cellValue}\" is more than the maximum " .
+ "date \"{$minDate->format(\DATE_RFC3339_EXTENDED)}\"";
}
return null;
diff --git a/src/Validators/Rules/MaxLength.php b/src/Validators/Rules/MaxLength.php
index 6cac2d8f..515cdb74 100644
--- a/src/Validators/Rules/MaxLength.php
+++ b/src/Validators/Rules/MaxLength.php
@@ -24,7 +24,8 @@ public function validateRule(?string $cellValue): ?string
$length = \mb_strlen((string)$cellValue);
if ($length > $minLength) {
- return "Value \"{$cellValue}\" (legth: {$length}) is too long. Max length is {$minLength}";
+ return "Value \"{$cellValue}\" (length: {$length}) is too long. " .
+ "Max length is {$minLength}";
}
return null;
diff --git a/src/Validators/Rules/Min.php b/src/Validators/Rules/Min.php
index 06ec2e21..ee340fcb 100644
--- a/src/Validators/Rules/Min.php
+++ b/src/Validators/Rules/Min.php
@@ -26,7 +26,7 @@ public function validateRule(?string $cellValue): ?string
}
if ($this->getOptionAsFloat() > (float)$cellValue) {
- return "Value \"{$cellValue}\" is less than \"{$this->getOptionAsFloat()}\"";
+ return "Value \"{$cellValue}\" is less than \"{$this->getOptionAsFloat()}\"";
}
return null;
diff --git a/src/Validators/Rules/MinDate.php b/src/Validators/Rules/MinDate.php
index 225a4c43..e9435a6b 100644
--- a/src/Validators/Rules/MinDate.php
+++ b/src/Validators/Rules/MinDate.php
@@ -24,8 +24,8 @@ public function validateRule(?string $cellValue): ?string
$cellDate = new \DateTimeImmutable((string)$cellValue);
if ($cellDate->getTimestamp() < $minDate->getTimestamp()) {
- return "Value \"{$cellValue}\" is less than the minimum " .
- "date \"{$minDate->format(\DATE_RFC3339_EXTENDED)}\"";
+ return "Value \"{$cellValue}\" is less than the minimum " .
+ "date \"{$minDate->format(\DATE_RFC3339_EXTENDED)}\"";
}
return null;
diff --git a/src/Validators/Rules/MinLength.php b/src/Validators/Rules/MinLength.php
index dab97808..10120131 100644
--- a/src/Validators/Rules/MinLength.php
+++ b/src/Validators/Rules/MinLength.php
@@ -24,7 +24,8 @@ public function validateRule(?string $cellValue): ?string
$length = \mb_strlen((string)$cellValue);
if ($length < $minLength) {
- return "Value \"{$cellValue}\" (legth: {$length}) is too short. Min length is {$minLength}";
+ return "Value \"{$cellValue}\" (length: {$length}) is too short. " .
+ "Min length is {$minLength}";
}
return null;
diff --git a/src/Validators/Rules/OnlyCapitalize.php b/src/Validators/Rules/OnlyCapitalize.php
index 49771bfd..99b011f2 100644
--- a/src/Validators/Rules/OnlyCapitalize.php
+++ b/src/Validators/Rules/OnlyCapitalize.php
@@ -25,7 +25,7 @@ public function validateRule(?string $cellValue): ?string
}
if ($cellValue !== null && $cellValue !== \ucfirst($cellValue)) {
- return "Value \"{$cellValue}\" should be in capitalize";
+ return "Value \"{$cellValue}\" should be in capitalize";
}
return null;
diff --git a/src/Validators/Rules/OnlyLowercase.php b/src/Validators/Rules/OnlyLowercase.php
index 3e4c8e4c..54bd838e 100644
--- a/src/Validators/Rules/OnlyLowercase.php
+++ b/src/Validators/Rules/OnlyLowercase.php
@@ -25,7 +25,7 @@ public function validateRule(?string $cellValue): ?string
}
if ($cellValue !== null && $cellValue !== \mb_strtolower($cellValue)) {
- return "Value \"{$cellValue}\" should be in lowercase";
+ return "Value \"{$cellValue}\" should be in lowercase";
}
return null;
diff --git a/src/Validators/Rules/OnlyTrimed.php b/src/Validators/Rules/OnlyTrimed.php
index 1da94d95..60d3b0c8 100644
--- a/src/Validators/Rules/OnlyTrimed.php
+++ b/src/Validators/Rules/OnlyTrimed.php
@@ -25,7 +25,7 @@ public function validateRule(?string $cellValue): ?string
}
if (\trim((string)$cellValue) !== (string)$cellValue) {
- return "Value \"{$cellValue}\" is not trimmed";
+ return "Value \"{$cellValue}\" is not trimmed";
}
return null;
diff --git a/src/Validators/Rules/OnlyUppercase.php b/src/Validators/Rules/OnlyUppercase.php
index f3014b36..6546547e 100644
--- a/src/Validators/Rules/OnlyUppercase.php
+++ b/src/Validators/Rules/OnlyUppercase.php
@@ -25,7 +25,7 @@ public function validateRule(?string $cellValue): ?string
}
if ($cellValue !== null && \mb_strtoupper($cellValue, 'UTF-8') !== $cellValue) {
- return "Value \"{$cellValue}\" is not uppercase";
+ return "Value \"{$cellValue}\" is not uppercase";
}
return null;
diff --git a/src/Validators/Rules/Precision.php b/src/Validators/Rules/Precision.php
index e1bfe56c..f6106e31 100644
--- a/src/Validators/Rules/Precision.php
+++ b/src/Validators/Rules/Precision.php
@@ -23,8 +23,8 @@ public function validateRule(?string $cellValue): ?string
$valuePrecision = self::getFloatPrecision($cellValue);
if ($this->getOptionAsInt() !== $valuePrecision) {
- return "Value \"{$cellValue}\" has a precision of {$valuePrecision} " .
- "but should have a precision of {$this->getOptionAsInt()}";
+ return "Value \"{$cellValue}\" has a precision of {$valuePrecision} " .
+ "but should have a precision of {$this->getOptionAsInt()}";
}
return null;
diff --git a/src/Validators/Rules/Regex.php b/src/Validators/Rules/Regex.php
index 27b707ea..356cbdb1 100644
--- a/src/Validators/Rules/Regex.php
+++ b/src/Validators/Rules/Regex.php
@@ -29,7 +29,7 @@ public function validateRule(?string $cellValue): ?string
}
if (\preg_match($regex, (string)$cellValue) === 0) {
- return "Value \"{$cellValue}\" does not match the pattern \"{$regex}\"";
+ return "Value \"{$cellValue}\" does not match the pattern \"{$regex}\"";
}
return null;
diff --git a/src/Validators/Rules/UsaMarketName.php b/src/Validators/Rules/UsaMarketName.php
index 365bf4c5..0979b6ea 100644
--- a/src/Validators/Rules/UsaMarketName.php
+++ b/src/Validators/Rules/UsaMarketName.php
@@ -25,8 +25,8 @@ public function validateRule(?string $cellValue): ?string
}
if (\preg_match('/^[A-Za-z0-9\s-]+, [A-Z]{2}$/u', (string)$cellValue) === 0) {
- return "Invalid market name format for value \"{$cellValue}\". " .
- 'Market name must have format "New York, NY"';
+ return "Invalid market name format for value \"{$cellValue}\". " .
+ 'Market name must have format "New York, NY"';
}
return null;
diff --git a/tests/Blueprint/CommandsTest.php b/tests/Blueprint/CommandsTest.php
index 519cf54e..15020dd7 100644
--- a/tests/Blueprint/CommandsTest.php
+++ b/tests/Blueprint/CommandsTest.php
@@ -101,6 +101,7 @@ public function testCreateValidatePositive(): void
$expected = \implode("\n", [
"CSV : {$rootPath}/tests/fixtures/demo.csv",
"Schema : {$rootPath}/tests/schemas/demo_valid.yml",
+ '',
'Looks good!',
'',
]);
@@ -121,23 +122,24 @@ public function testCreateValidateNegative(): void
$expected = \implode("\n", [
"CSV : {$rootPath}/tests/fixtures/demo.csv",
"Schema : {$rootPath}/tests/schemas/demo_invalid.yml",
- '+------+------------------+--------------+-- demo.csv -------------------------------------------+',
- '| Line | id:Column | Rule | Message |',
- '+------+------------------+--------------+-------------------------------------------------------+',
- '| 1 | 1: | csv.header | Property "name" is not defined in schema: |',
- '| | | | "./tests/schemas/demo_invalid.yml" |',
- '| 5 | 2:Float | max | Value "74605.944" is greater than "74605" |',
- '| 5 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", |',
- '| | | | "green", "Blue"] |',
- '| 6 | 0:Name | min_length | Value "Carl" (legth: 4) is too short. Min length is 5 |',
- '| 6 | 3:Birthday | min_date | Value "1955-05-14" is less than the minimum date |',
- '| | | | "1955-05-15T00:00:00.000+00:00" |',
- '| 8 | 3:Birthday | min_date | Value "1955-05-14" is less than the minimum date |',
- '| | | | "1955-05-15T00:00:00.000+00:00" |',
- '| 9 | 3:Birthday | max_date | Value "2010-07-20" is more than the maximum date |',
- '| | | | "2009-01-01T00:00:00.000+00:00" |',
- '| 11 | 0:Name | min_length | Value "Lois" (legth: 4) is too short. Min length is 5 |',
- '+------+------------------+--------------+-- demo.csv -------------------------------------------+',
+ '',
+ '+------+------------------+--------------+-- demo.csv --------------------------------------------+',
+ '| Line | id:Column | Rule | Message |',
+ '+------+------------------+--------------+--------------------------------------------------------+',
+ '| 1 | 1: | csv.header | Property "name" is not defined in schema: |',
+ '| | | | "./tests/schemas/demo_invalid.yml" |',
+ '| 5 | 2:Float | max | Value "74605.944" is greater than "74605" |',
+ '| 5 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", |',
+ '| | | | "green", "Blue"] |',
+ '| 6 | 0:Name | min_length | Value "Carl" (length: 4) is too short. Min length is 5 |',
+ '| 6 | 3:Birthday | min_date | Value "1955-05-14" is less than the minimum date |',
+ '| | | | "1955-05-15T00:00:00.000+00:00" |',
+ '| 8 | 3:Birthday | min_date | Value "1955-05-14" is less than the minimum date |',
+ '| | | | "1955-05-15T00:00:00.000+00:00" |',
+ '| 9 | 3:Birthday | max_date | Value "2010-07-20" is more than the maximum date |',
+ '| | | | "2009-01-01T00:00:00.000+00:00" |',
+ '| 11 | 0:Name | min_length | Value "Lois" (length: 4) is too short. Min length is 5 |',
+ '+------+------------------+--------------+-- demo.csv --------------------------------------------+',
'',
'CSV file is not valid! Found 8 errors.',
'',
@@ -145,6 +147,15 @@ public function testCreateValidateNegative(): void
isSame(1, $exitCode);
isSame($expected, $actual);
+
+ isFileContains(\implode("\n", [
+ '```',
+ './csv-blueprint validate:csv --output=table',
+ '',
+ '',
+ \str_replace($rootPath, '.', $expected),
+ '```',
+ ]), PROJECT_ROOT . '/README.md');
}
public function testCreateValidateNegativeText(): void
@@ -160,7 +171,7 @@ public function testCreateValidateNegativeText(): void
$expected = \implode("\n", [
"CSV : {$rootPath}/tests/fixtures/demo.csv",
"Schema : {$rootPath}/tests/schemas/demo_invalid.yml",
-
+ '',
'"csv.header" at line 1, column "1:". Property "name" is not defined in schema: ' .
"\"{$rootPath}/tests/schemas/demo_invalid.yml\".",
@@ -169,7 +180,7 @@ public function testCreateValidateNegativeText(): void
'"allow_values" at line 5, column "4:Favorite color". Value "blue" is not allowed. ' .
'Allowed values: ["red", "green", "Blue"].',
- '"min_length" at line 6, column "0:Name". Value "Carl" (legth: 4) is too short. ' .
+ '"min_length" at line 6, column "0:Name". Value "Carl" (length: 4) is too short. ' .
'Min length is 5.',
'"min_date" at line 6, column "3:Birthday". Value "1955-05-14" is less than the ' .
@@ -181,7 +192,7 @@ public function testCreateValidateNegativeText(): void
'"max_date" at line 9, column "3:Birthday". Value "2010-07-20" is more than the ' .
'maximum date "2009-01-01T00:00:00.000+00:00".',
- '"min_length" at line 11, column "0:Name". Value "Lois" (legth: 4) is too short. ' .
+ '"min_length" at line 11, column "0:Name". Value "Lois" (length: 4) is too short. ' .
'Min length is 5.',
'',
diff --git a/tests/Blueprint/RulesTest.php b/tests/Blueprint/RulesTest.php
index 3e4cc685..43eb878f 100644
--- a/tests/Blueprint/RulesTest.php
+++ b/tests/Blueprint/RulesTest.php
@@ -64,12 +64,12 @@ public function testAllowValues(): void
isSame(
'"allow_values" at line 0, column "prop". ' .
'Value "" is not allowed. Allowed values: ["1", "2", "3"].',
- (string)$rule->validate(''),
+ \strip_tags((string)$rule->validate('')),
);
isSame(
'"allow_values" at line 0, column "prop". ' .
'Value "invalid" is not allowed. Allowed values: ["1", "2", "3"].',
- (string)$rule->validate('invalid'),
+ \strip_tags((string)$rule->validate('invalid')),
);
$rule = new AllowValues('prop', ['1', '2', '3', '']);
@@ -86,12 +86,12 @@ public function testDateFormat(): void
isSame(
'"date_format" at line 0, column "prop". ' .
'Date format of value "" is not valid. Expected format: "Y-m-d".',
- (string)$rule->validate(''),
+ \strip_tags((string)$rule->validate('')),
);
isSame(
'"date_format" at line 0, column "prop". ' .
'Date format of value "2000-01-02 12:34:56" is not valid. Expected format: "Y-m-d".',
- (string)$rule->validate('2000-01-02 12:34:56'),
+ \strip_tags((string)$rule->validate('2000-01-02 12:34:56')),
);
}
@@ -101,11 +101,11 @@ public function testExactValue(): void
isSame(null, $rule->validate('123'));
isSame(
'"exact_value" at line 0, column "prop". Value "" is not strict equal to "123".',
- (string)$rule->validate(''),
+ \strip_tags((string)$rule->validate('')),
);
isSame(
'"exact_value" at line 0, column "prop". Value "2000-01-02" is not strict equal to "123".',
- (string)$rule->validate('2000-01-02'),
+ \strip_tags((string)$rule->validate('2000-01-02')),
);
}
@@ -120,11 +120,11 @@ public function testIsBool(): void
isSame(null, $rule->validate('False'));
isSame(
'"is_bool" at line 0, column "prop". Value "" is not allowed. Allowed values: ["true", "false"].',
- (string)$rule->validate(''),
+ \strip_tags((string)$rule->validate('')),
);
isSame(
'"is_bool" at line 0, column "prop". Value "1" is not allowed. Allowed values: ["true", "false"].',
- (string)$rule->validate('1'),
+ \strip_tags((string)$rule->validate('1')),
);
$rule = new IsBool('prop', false);
@@ -142,11 +142,11 @@ public function testIsDomain(): void
isSame(null, $rule->validate('sub-sub-example.qwerty'));
isSame(
'"is_domain" at line 0, column "prop". Value "example" is not a valid domain.',
- (string)$rule->validate('example'),
+ \strip_tags((string)$rule->validate('example')),
);
isSame(
'"is_domain" at line 0, column "prop". Value "" is not a valid domain.',
- (string)$rule->validate(''),
+ \strip_tags((string)$rule->validate('')),
);
$rule = new IsDomain('prop', false);
@@ -160,7 +160,7 @@ public function testIsEmail(): void
isSame(null, $rule->validate('user@sub.example.com'));
isSame(
'"is_email" at line 0, column "prop". Value "user:pass@example.com" is not a valid email.',
- (string)$rule->validate('user:pass@example.com'),
+ \strip_tags((string)$rule->validate('user:pass@example.com')),
);
$rule = new IsEmail('prop', false);
@@ -178,15 +178,15 @@ public function testIsFloat(): void
isSame(null, $rule->validate('-1.0'));
isSame(
'"is_float" at line 0, column "prop". Value "1.000.000" is not a float number.',
- (string)$rule->validate('1.000.000'),
+ \strip_tags((string)$rule->validate('1.000.000')),
);
isSame(
'"is_float" at line 0, column "prop". Value "" is not a float number.',
- (string)$rule->validate(''),
+ \strip_tags((string)$rule->validate('')),
);
isSame(
'"is_float" at line 0, column "prop". Value " 1" is not a float number.',
- (string)$rule->validate(' 1'),
+ \strip_tags((string)$rule->validate(' 1')),
);
$rule = new IsFloat('prop', false);
@@ -203,27 +203,27 @@ public function testIsInt(): void
isSame(null, $rule->validate('-1'));
isSame(
'"is_int" at line 0, column "prop". Value "1.000.000" is not an integer.',
- (string)$rule->validate('1.000.000'),
+ \strip_tags((string)$rule->validate('1.000.000')),
);
isSame(
'"is_int" at line 0, column "prop". Value "1.1" is not an integer.',
- (string)$rule->validate('1.1'),
+ \strip_tags((string)$rule->validate('1.1')),
);
isSame(
'"is_int" at line 0, column "prop". Value "1.0" is not an integer.',
- (string)$rule->validate('1.0'),
+ \strip_tags((string)$rule->validate('1.0')),
);
isSame(
'"is_int" at line 0, column "prop". Value "" is not an integer.',
- (string)$rule->validate(''),
+ \strip_tags((string)$rule->validate('')),
);
isSame(
'"is_int" at line 0, column "prop". Value " 1" is not an integer.',
- (string)$rule->validate(' 1'),
+ \strip_tags((string)$rule->validate(' 1')),
);
isSame(
'"is_int" at line 0, column "prop". Value "1 " is not an integer.',
- (string)$rule->validate('1 '),
+ \strip_tags((string)$rule->validate('1 ')),
);
$rule = new IsInt('prop', false);
@@ -237,7 +237,7 @@ public function testIsIp(): void
isSame(null, $rule->validate('0.0.0.0'));
isSame(
'"is_ip" at line 0, column "prop". Value "1.2.3" is not a valid IP.',
- (string)$rule->validate('1.2.3'),
+ \strip_tags((string)$rule->validate('1.2.3')),
);
}
@@ -248,16 +248,16 @@ public function testIsLatitude(): void
isSame(null, $rule->validate('90'));
isSame(null, $rule->validate('-90'));
isSame(
- '"is_latitude" at line 0, column "prop". Value "123" is not a valid latitude (-90 <= x <= 90).',
- (string)$rule->validate('123'),
+ '"is_latitude" at line 0, column "prop". Value "123" is not a valid latitude (-90 -> 90).',
+ \strip_tags((string)$rule->validate('123')),
);
isSame(
- '"is_latitude" at line 0, column "prop". Value "90.1" is not a valid latitude (-90 <= x <= 90).',
- (string)$rule->validate('90.1'),
+ '"is_latitude" at line 0, column "prop". Value "90.1" is not a valid latitude (-90 -> 90).',
+ \strip_tags((string)$rule->validate('90.1')),
);
isSame(
'"is_latitude" at line 0, column "prop". Value "90.1.1.1.1" is not a float number.',
- (string)$rule->validate('90.1.1.1.1'),
+ \strip_tags((string)$rule->validate('90.1.1.1.1')),
);
$rule = new IsLatitude('prop', false);
@@ -271,21 +271,21 @@ public function testIsLongitude(): void
isSame(null, $rule->validate('180'));
isSame(null, $rule->validate('-180'));
isSame(
- '"is_longitude" at line 0, column "prop". Value "1230" is not a valid longitude (-180 <= x <= 180).',
- (string)$rule->validate('1230'),
+ '"is_longitude" at line 0, column "prop". Value "1230" is not a valid longitude (-180 -> 180).',
+ \strip_tags((string)$rule->validate('1230')),
);
isSame(
'"is_longitude" at line 0, column "prop". ' .
- 'Value "180.0001" is not a valid longitude (-180 <= x <= 180).',
- (string)$rule->validate('180.0001'),
+ 'Value "180.0001" is not a valid longitude (-180 -> 180).',
+ \strip_tags((string)$rule->validate('180.0001')),
);
isSame(
- '"is_longitude" at line 0, column "prop". Value "-180.1" is not a valid longitude (-180 <= x <= 180).',
- (string)$rule->validate('-180.1'),
+ '"is_longitude" at line 0, column "prop". Value "-180.1" is not a valid longitude (-180 -> 180).',
+ \strip_tags((string)$rule->validate('-180.1')),
);
isSame(
'"is_longitude" at line 0, column "prop". Value "1.0.0.0" is not a float number.',
- (string)$rule->validate('1.0.0.0'),
+ \strip_tags((string)$rule->validate('1.0.0.0')),
);
$rule = new IsLongitude('prop', false);
@@ -300,11 +300,11 @@ public function testIsUrl(): void
isSame(null, $rule->validate('ftp://user:pass@example.com/home-page?param=value&v=asd#anchor'));
isSame(
'"is_url" at line 0, column "prop". Value "123" is not a valid URL.',
- (string)$rule->validate('123'),
+ \strip_tags((string)$rule->validate('123')),
);
isSame(
'"is_url" at line 0, column "prop". Value "//example.com" is not a valid URL.',
- (string)$rule->validate('//example.com'),
+ \strip_tags((string)$rule->validate('//example.com')),
);
$rule = new IsUrl('prop', false);
@@ -318,11 +318,11 @@ public function testMin(): void
isSame(null, $rule->validate('11'));
isSame(
'"min" at line 0, column "prop". Value "9" is less than "10".',
- (string)$rule->validate('9'),
+ \strip_tags((string)$rule->validate('9')),
);
isSame(
'"min" at line 0, column "prop". Value "example.com" is not a float number.',
- (string)$rule->validate('example.com'),
+ \strip_tags((string)$rule->validate('example.com')),
);
$rule = new Min('prop', 10.1);
@@ -330,11 +330,11 @@ public function testMin(): void
isSame(null, $rule->validate('11'));
isSame(
'"min" at line 0, column "prop". Value "9" is less than "10.1".',
- (string)$rule->validate('9'),
+ \strip_tags((string)$rule->validate('9')),
);
isSame(
'"min" at line 0, column "prop". Value "example.com" is not a float number.',
- (string)$rule->validate('example.com'),
+ \strip_tags((string)$rule->validate('example.com')),
);
}
@@ -345,11 +345,11 @@ public function testMax(): void
isSame(null, $rule->validate('10'));
isSame(
'"max" at line 0, column "prop". Value "123" is greater than "10".',
- (string)$rule->validate('123'),
+ \strip_tags((string)$rule->validate('123')),
);
isSame(
'"max" at line 0, column "prop". Value "example.com" is not a float number.',
- (string)$rule->validate('example.com'),
+ \strip_tags((string)$rule->validate('example.com')),
);
$rule = new Max('prop', 10.1);
@@ -358,7 +358,7 @@ public function testMax(): void
isSame(null, $rule->validate('10.1'));
isSame(
'"max" at line 0, column "prop". Value "10.2" is greater than "10.1".',
- (string)$rule->validate('10.2'),
+ \strip_tags((string)$rule->validate('10.2')),
);
}
@@ -369,7 +369,7 @@ public function testMinDate(): void
isSame(
'"min_date" at line 0, column "prop". ' .
'Value "2000-01-09" is less than the minimum date "2000-01-10T00:00:00.000+00:00".',
- (string)$rule->validate('2000-01-09'),
+ \strip_tags((string)$rule->validate('2000-01-09')),
);
$rule = new MinDate('prop', '2000-01-10 00:00:00 +01:00');
@@ -377,7 +377,7 @@ public function testMinDate(): void
isSame(
'"min_date" at line 0, column "prop". ' .
'Value "2000-01-09 23:59:59 Europe/Berlin" is less than the minimum date "2000-01-10T00:00:00.000+01:00".',
- (string)$rule->validate('2000-01-09 23:59:59 Europe/Berlin'),
+ \strip_tags((string)$rule->validate('2000-01-09 23:59:59 Europe/Berlin')),
);
$rule = new MinDate('prop', '-1000 years');
@@ -391,7 +391,7 @@ public function testMaxDate(): void
isSame(
'"max_date" at line 0, column "prop". ' .
'Value "2000-01-11" is more than the maximum date "2000-01-10T00:00:00.000+00:00".',
- (string)$rule->validate('2000-01-11'),
+ \strip_tags((string)$rule->validate('2000-01-11')),
);
$rule = new MaxDate('prop', '2000-01-10 00:00:00');
@@ -399,7 +399,7 @@ public function testMaxDate(): void
isSame(
'"max_date" at line 0, column "prop". ' .
'Value "2000-01-10 00:00:01" is more than the maximum date "2000-01-10T00:00:00.000+00:00".',
- (string)$rule->validate('2000-01-10 00:00:01'),
+ \strip_tags((string)$rule->validate('2000-01-10 00:00:01')),
);
$rule = new MaxDate('prop', '+1 day');
@@ -413,16 +413,16 @@ public function testMinLength(): void
isSame(null, $rule->validate(' '));
isSame(null, $rule->validate(' 1 '));
isSame(
- '"min_length" at line 0, column "prop". Value "1234" (legth: 4) is too short. Min length is 5.',
- (string)$rule->validate('1234'),
+ '"min_length" at line 0, column "prop". Value "1234" (length: 4) is too short. Min length is 5.',
+ \strip_tags((string)$rule->validate('1234')),
);
isSame(
- '"min_length" at line 0, column "prop". Value "123 " (legth: 4) is too short. Min length is 5.',
- (string)$rule->validate('123 '),
+ '"min_length" at line 0, column "prop". Value "123 " (length: 4) is too short. Min length is 5.',
+ \strip_tags((string)$rule->validate('123 ')),
);
isSame(
- '"min_length" at line 0, column "prop". Value "" (legth: 0) is too short. Min length is 5.',
- (string)$rule->validate(''),
+ '"min_length" at line 0, column "prop". Value "" (length: 0) is too short. Min length is 5.',
+ \strip_tags((string)$rule->validate('')),
);
}
@@ -435,12 +435,12 @@ public function testMaxLength(): void
isSame(null, $rule->validate(' '));
isSame(null, $rule->validate(' 1 '));
isSame(
- '"max_length" at line 0, column "prop". Value "123456" (legth: 6) is too long. Max length is 5.',
- (string)$rule->validate('123456'),
+ '"max_length" at line 0, column "prop". Value "123456" (length: 6) is too long. Max length is 5.',
+ \strip_tags((string)$rule->validate('123456')),
);
isSame(
- '"max_length" at line 0, column "prop". Value "12345 " (legth: 6) is too long. Max length is 5.',
- (string)$rule->validate('12345 '),
+ '"max_length" at line 0, column "prop". Value "12345 " (length: 6) is too long. Max length is 5.',
+ \strip_tags((string)$rule->validate('12345 ')),
);
}
@@ -454,11 +454,11 @@ public function testNotEmpty(): void
isSame(null, $rule->validate(' '));
isSame(
'"not_empty" at line 0, column "prop". Value is empty.',
- (string)$rule->validate(''),
+ \strip_tags((string)$rule->validate('')),
);
isSame(
'"not_empty" at line 0, column "prop". Value is empty.',
- (string)$rule->validate(null),
+ \strip_tags((string)$rule->validate(null)),
);
$rule = new NotEmpty('prop', false);
@@ -475,11 +475,11 @@ public function testOnlyCapitalize(): void
isSame(null, $rule->validate(' '));
isSame(
'"only_capitalize" at line 0, column "prop". Value "qwerty" should be in capitalize.',
- (string)$rule->validate('qwerty'),
+ \strip_tags((string)$rule->validate('qwerty')),
);
isSame(
'"only_capitalize" at line 0, column "prop". Value "qwe Rty" should be in capitalize.',
- (string)$rule->validate('qwe Rty'),
+ \strip_tags((string)$rule->validate('qwe Rty')),
);
$rule = new OnlyCapitalize('prop', false);
@@ -496,11 +496,11 @@ public function testOnlyLowercase(): void
isSame(null, $rule->validate(' '));
isSame(
'"only_lowercase" at line 0, column "prop". Value "Qwerty" should be in lowercase.',
- (string)$rule->validate('Qwerty'),
+ \strip_tags((string)$rule->validate('Qwerty')),
);
isSame(
'"only_lowercase" at line 0, column "prop". Value "qwe Rty" should be in lowercase.',
- (string)$rule->validate('qwe Rty'),
+ \strip_tags((string)$rule->validate('qwe Rty')),
);
$rule = new OnlyLowercase('prop', false);
@@ -516,11 +516,11 @@ public function testOnlyUppercase(): void
isSame(null, $rule->validate(' '));
isSame(
'"only_uppercase" at line 0, column "prop". Value "Qwerty" is not uppercase.',
- (string)$rule->validate('Qwerty'),
+ \strip_tags((string)$rule->validate('Qwerty')),
);
isSame(
'"only_uppercase" at line 0, column "prop". Value "qwe Rty" is not uppercase.',
- (string)$rule->validate('qwe Rty'),
+ \strip_tags((string)$rule->validate('qwe Rty')),
);
$rule = new OnlyUppercase('prop', false);
@@ -536,12 +536,12 @@ public function testPrecision(): void
isSame(
'"precision" at line 0, column "prop". ' .
'Value "1.1" has a precision of 1 but should have a precision of 0.',
- (string)$rule->validate('1.1'),
+ \strip_tags((string)$rule->validate('1.1')),
);
isSame(
'"precision" at line 0, column "prop". ' .
'Value "1.0" has a precision of 1 but should have a precision of 0.',
- (string)$rule->validate('1.0'),
+ \strip_tags((string)$rule->validate('1.0')),
);
$rule = new Precision('prop', 1);
@@ -551,12 +551,12 @@ public function testPrecision(): void
isSame(
'"precision" at line 0, column "prop". ' .
'Value "1" has a precision of 0 but should have a precision of 1.',
- (string)$rule->validate('1'),
+ \strip_tags((string)$rule->validate('1')),
);
isSame(
'"precision" at line 0, column "prop". ' .
'Value "1.01" has a precision of 2 but should have a precision of 1.',
- (string)$rule->validate('1.01'),
+ \strip_tags((string)$rule->validate('1.01')),
);
$rule = new Precision('prop', 2);
@@ -566,12 +566,12 @@ public function testPrecision(): void
isSame(
'"precision" at line 0, column "prop". ' .
'Value "2.0" has a precision of 1 but should have a precision of 2.',
- (string)$rule->validate('2.0'),
+ \strip_tags((string)$rule->validate('2.0')),
);
isSame(
'"precision" at line 0, column "prop". ' .
'Value "1.000" has a precision of 3 but should have a precision of 2.',
- (string)$rule->validate('1.000'),
+ \strip_tags((string)$rule->validate('1.000')),
);
}
@@ -583,7 +583,7 @@ public function testRegex(): void
isSame(null, $rule->validate('a'));
isSame(
'"regex" at line 0, column "prop". Value "1bc" does not match the pattern "/^a/".',
- (string)$rule->validate('1bc'),
+ \strip_tags((string)$rule->validate('1bc')),
);
$rule = new Regex('prop', '^a');
@@ -592,7 +592,7 @@ public function testRegex(): void
isSame(null, $rule->validate('a'));
isSame(
'"regex" at line 0, column "prop". Value "1bc" does not match the pattern "/^a/u".',
- (string)$rule->validate('1bc'),
+ \strip_tags((string)$rule->validate('1bc')),
);
}
@@ -611,7 +611,7 @@ public function testUnitFacing(): void
isSame(
'"cardinal_direction" at line 0, column "prop". Value "qwe" is not allowed. ' .
'Allowed values: ["N", "S", "E", "W", "NE", "SE", "NW", "SW", "none", ""].',
- (string)$rule->validate('qwe'),
+ \strip_tags((string)$rule->validate('qwe')),
);
}
@@ -624,7 +624,7 @@ public function testUsaMarketName(): void
'"usa_market_name" at line 0, column "prop". ' .
'Invalid market name format for value ", ST". ' .
'Market name must have format "New York, NY".',
- (string)$rule->validate(', ST'),
+ \strip_tags((string)$rule->validate(', ST')),
);
$rule = new UsaMarketName('prop', false);
@@ -637,7 +637,7 @@ public function testIsUuid4(): void
isSame(null, $rule->validate(Str::uuid()));
isSame(
'"is_uuid4" at line 0, column "prop". Value is not a valid UUID v4.',
- (string)$rule->validate('123'),
+ \strip_tags((string)$rule->validate('123')),
);
$rule = new IsUuid4('prop', false);
diff --git a/tests/Blueprint/ValidatorTest.php b/tests/Blueprint/ValidatorTest.php
index a9cd4771..a74202cf 100644
--- a/tests/Blueprint/ValidatorTest.php
+++ b/tests/Blueprint/ValidatorTest.php
@@ -53,13 +53,13 @@ public function testUndefinedRule(): void
public function testValidWithHeader(): void
{
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, self::SCHEMA_SIMPLE_HEADER);
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
}
public function testValidWithoutHeader(): void
{
$csv = new CsvFile(self::CSV_SIMPLE_NO_HEADER, self::SCHEMA_SIMPLE_NO_HEADER);
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
}
public function testInvalidSchemaFile(): void
@@ -73,7 +73,7 @@ public function testSchemaAsPhpFile(): void
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, self::SCHEMA_SIMPLE_HEADER_PHP);
isSame(
'"min" at line 2, column "0:seq". Value "1" is less than "2".' . "\n",
- (string)$csv->validate(),
+ \strip_tags((string)$csv->validate()),
);
}
@@ -82,19 +82,19 @@ public function testSchemaAsJsonFile(): void
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, self::SCHEMA_SIMPLE_HEADER_JSON);
isSame(
'"min" at line 2, column "0:seq". Value "1" is less than "2".' . "\n",
- (string)$csv->validate(),
+ \strip_tags((string)$csv->validate()),
);
}
public function testNotEmptyMessage(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'not_empty', true));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('integer', 'not_empty', true));
isSame(
'"not_empty" at line 19, column "0:integer". Value is empty.' . "\n",
- (string)$csv->validate(),
+ \strip_tags((string)$csv->validate()),
);
}
@@ -104,203 +104,203 @@ public function testNoName(): void
isSame(
'"csv.header" at line 1, column "0:". ' .
'Property "name" is not defined in schema: "_custom_array_".' . "\n",
- (string)$csv->validate(),
+ \strip_tags((string)$csv->validate()),
);
}
public function testMin(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'min', -10));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'min', 10));
isSame(
'"min" at line 2, column "0:seq". Value "1" is less than "10".',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testMax(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'max', 10000));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'max', 10));
isSame(
'"max" at line 12, column "0:seq". Value "11" is greater than "10".',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testRegex(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'regex', '.*'));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'regex', '^[a-zA-Z0-9]+$'));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'regex', '[a-z]'));
isSame(
'"regex" at line 2, column "0:seq". Value "1" does not match the pattern "/[a-z]/u".',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'regex', '/[a-z]/'));
isSame(
'"regex" at line 2, column "0:seq". Value "1" does not match the pattern "/[a-z]/".',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'regex', '/[a-z]/i'));
isSame(
'"regex" at line 2, column "0:seq". Value "1" does not match the pattern "/[a-z]/i".',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testMinLength(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'min_length', 1));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'min_length', 1000));
isSame(
- '"min_length" at line 2, column "0:seq". Value "1" (legth: 1) is too short. Min length is 1000.',
- (string)$csv->validate()->get(0),
+ '"min_length" at line 2, column "0:seq". Value "1" (length: 1) is too short. Min length is 1000.',
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testMaxLength(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'max_length', 10));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'max_length', 1));
isSame(
- '"max_length" at line 11, column "0:seq". Value "10" (legth: 2) is too long. Max length is 1.',
- (string)$csv->validate()->get(0),
+ '"max_length" at line 11, column "0:seq". Value "10" (length: 2) is too long. Max length is 1.',
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testOnlyTrimed(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'only_trimed', true));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('sentence', 'only_trimed', true));
isSame(
'"only_trimed" at line 14, column "0:sentence". Value " Urecam" is not trimmed.',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testOnlyUppercase(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'only_uppercase', true));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('bool', 'only_uppercase', true));
isSame(
'"only_uppercase" at line 2, column "0:bool". Value "true" is not uppercase.',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testOnlyLowercase(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'only_lowercase', true));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('bool', 'only_lowercase', true));
isSame(
'"only_lowercase" at line 8, column "0:bool". Value "False" should be in lowercase.',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testOnlyCapitalize(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'only_capitalize', true));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('bool', 'only_capitalize', true));
isSame(
'"only_capitalize" at line 2, column "0:bool". Value "true" should be in capitalize.',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testPrecision(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'precision', 0));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'precision', 1));
isSame(
'"precision" at line 2, column "0:seq". ' .
'Value "1" has a precision of 0 but should have a precision of 1.',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('float', 'precision', 3));
isSame(
'"precision" at line 3, column "0:float". ' .
'Value "506847750940.2624" has a precision of 4 but should have a precision of 3.',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testMinDate(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('date', 'min_date', '2000-01-01'));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('date', 'min_date', '2120-01-01'));
isSame(
'"min_date" at line 2, column "0:date". ' .
'Value "2042/11/18" is less than the minimum date "2120-01-01T00:00:00.000+00:00".',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('date', 'min_date', '2042/11/17'));
isSame(
'"min_date" at line 5, column "0:date". ' .
'Value "2032/09/09" is less than the minimum date "2042-11-17T00:00:00.000+00:00".',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testMaxDate(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('date', 'max_date', '2200-01-01'));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('date', 'max_date', '2120-01-01'));
isSame(
'"max_date" at line 23, column "0:date". ' .
'Value "2120/02/01" is more than the maximum date "2120-01-01T00:00:00.000+00:00".',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('date', 'max_date', '2042/11/17'));
isSame(
'"max_date" at line 2, column "0:date". ' .
'Value "2042/11/18" is more than the maximum date "2042-11-17T00:00:00.000+00:00".',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testDateFormat(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('date', 'date_format', 'Y/m/d'));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('date', 'date_format', 'Y/m/d H:i:s'));
isSame(
'"date_format" at line 2, column "0:date". ' .
'Date format of value "2042/11/18" is not valid. Expected format: "Y/m/d H:i:s".',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
@@ -314,79 +314,79 @@ public function testAllowValues(): void
['true', 'false', 'False', 'True'],
),
);
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('bool', 'allow_values', ['true', 'false']));
isSame(
'"allow_values" at line 8, column "0:bool". ' .
'Value "False" is not allowed. Allowed values: ["true", "false"].',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testExactValue(): void
{
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, $this->getRule('exact', 'exact_value', '1'));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, $this->getRule('exact', 'exact_value', '2'));
isSame(
'"exact_value" at line 2, column "0:exact". Value "1" is not strict equal to "2".',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('bool', 'exact_value', 'true'));
isSame(
'"exact_value" at line 4, column "0:bool". Value "false" is not strict equal to "true".',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testIsInt(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'is_int', true));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('bool', 'is_int', true));
isSame(
'"is_int" at line 2, column "0:bool". Value "true" is not an integer.',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testIsFloat(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('seq', 'is_float', true));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('bool', 'is_float', true));
isSame(
'"is_float" at line 2, column "0:bool". Value "true" is not a float number.',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testIsBool(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('bool', 'is_bool', true));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('yn', 'is_bool', true));
isSame(
'"is_bool" at line 2, column "0:yn". Value "n" is not allowed. Allowed values: ["true", "false"].',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
public function testIsEmail(): void
{
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('email', 'is_email', true));
- isSame('', (string)$csv->validate());
+ isSame('', \strip_tags((string)$csv->validate()));
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('yn', 'is_email', true));
isSame(
'"is_email" at line 2, column "0:yn". Value "N" is not a valid email.',
- (string)$csv->validate()->get(0),
+ \strip_tags((string)$csv->validate()->get(0)),
);
}
@@ -407,7 +407,7 @@ public function testErrorToArray(): void
$csv = new CsvFile(self::CSV_COMPLEX, $this->getRule('yn', 'is_email', true));
isSame([
'ruleCode' => 'is_email',
- 'message' => 'Value "N" is not a valid email',
+ 'message' => 'Value "N" is not a valid email',
'columnName' => '0:yn',
'line' => 2,
], $csv->validate(true)->get(0)->toArray());
@@ -418,7 +418,7 @@ public function testRenderText(): void
$csv = new CsvFile(self::CSV_SIMPLE_HEADER, $this->getRule('seq', 'min', 3));
isSame(
'"min" at line 2, column "0:seq". Value "1" is less than "3".' . "\n",
- $csv->validate(true)->render(ErrorSuite::RENDER_TEXT),
+ \strip_tags($csv->validate(true)->render(ErrorSuite::RENDER_TEXT)),
);
isSame(
@@ -426,7 +426,7 @@ public function testRenderText(): void
'"min" at line 2, column "0:seq". Value "1" is less than "3".',
'"min" at line 3, column "0:seq". Value "2" is less than "3".' . "\n",
]),
- $csv->validate()->render(ErrorSuite::RENDER_TEXT),
+ \strip_tags($csv->validate()->render(ErrorSuite::RENDER_TEXT)),
);
}