Skip to content

Commit

Permalink
Merge fa2b30d into 0e3110f
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Mar 19, 2024
2 parents 0e3110f + fa2b30d commit 31f3158
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 26 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ It's random ideas and plans. No orderings and deadlines. <u>But batch processing
* [More aggregate rules](https://github.com/markrogoyski/math-php#statistics---descriptive).
* [More cell rules](https://github.com/Respect/Validation).
* `required` flag for the column.
* Multi values in one cell.
* 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 All @@ -594,6 +595,7 @@ It's random ideas and plans. No orderings and deadlines. <u>But batch processing
* **Mock data generation**
* Create CSV files based on the schema (like "create 1000 rows with random data based on schema and rules").
* Use [Faker](https://github.com/FakerPHP/Faker) for random data generation.
* [ReverseRegex](https://github.com/enso-media/ReverseRegex) to generate text from regex.

* **Reporting**
* More report formats (like JSON, XML, etc). Any ideas?
Expand Down
9 changes: 9 additions & 0 deletions tests/Commands/ValidateCsvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,4 +485,13 @@ public function testInvalidSchemaAndNoFoundCSV(): void
isSame(1, $exitCode, $actual);
isSame($expected, $actual);
}

public function testSchemaNotFound(): void
{
$this->expectExceptionMessage('Schema file not found: invalid_schema_path.yml');
Tools::virtualExecution('validate:csv', [
'csv' => './tests/fixtures/no-found-file.csv',
'schema' => 'invalid_schema_path.yml',
]);
}
}
7 changes: 6 additions & 1 deletion tests/Rules/Cell/AllowValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ public function testPositive(): void
public function testNegative(): void
{
$rule = $this->create(['1', '2', '3']);

isSame(
'Value "invalid" is not allowed. Allowed values: ["1", "2", "3"]',
$rule->test('invalid'),
);

$rule = $this->create([]);
isSame(
'Allowed values are not defined',
$rule->test('invalid'),
);
}

public function testInvalidOption(): void
Expand Down
6 changes: 6 additions & 0 deletions tests/Rules/Cell/DateFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,11 @@ public function testNegative(): void
'Date format of value "2000-01-02 12:34:56" is not valid. Expected format: "Y-m-d"',
$rule->test('2000-01-02 12:34:56'),
);

$rule = $this->create('');
isSame(
'Date format is not defined',
$rule->test('12'),
);
}
}
43 changes: 43 additions & 0 deletions tests/Rules/Cell/IsTrimmedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* JBZoo Toolbox - Csv-Blueprint.
*
* This file is part of the JBZoo Toolbox project.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT
* @copyright Copyright (C) JBZoo.com, All rights reserved.
* @see https://github.com/JBZoo/Csv-Blueprint
*/

declare(strict_types=1);

namespace JBZoo\PHPUnit\Rules\Cell;

use JBZoo\CsvBlueprint\Rules\Cell\IsJson;
use JBZoo\CsvBlueprint\Rules\Cell\IsTrimmed;
use JBZoo\PHPUnit\Rules\AbstractCellRule;

use function JBZoo\PHPUnit\isSame;

final class IsTrimmedTest extends AbstractCellRule
{
protected string $ruleClass = IsTrimmed::class;

public function testPositive(): void
{
$rule = $this->create(true);
isSame('', $rule->test(''));
isSame('', $rule->test('Hello world!'));
}

public function testNegative(): void
{
$rule = $this->create(true);
isSame('Value "Hello world! " is not trimmed', $rule->test('Hello world! '));
isSame('Value " Hello world!" is not trimmed', $rule->test(' Hello world!'));
isSame('Value " Hello world! " is not trimmed', $rule->test(' Hello world! '));
}
}
13 changes: 4 additions & 9 deletions tests/Rules/Cell/NotAllowValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,11 @@ public function testPositive(): void
public function testNegative(): void
{
$rule = $this->create(['invalid', ' ']);
isSame('Value "invalid" is not allowed', $rule->test('invalid'));
isSame('Value " " is not allowed', $rule->test(' '));

isSame(
'Value "invalid" is not allowed',
$rule->test('invalid'),
);

isSame(
'Value " " is not allowed',
$rule->test(' '),
);
$rule = $this->create([]);
isSame('Not allowed values are not defined', $rule->test('invalid'));
}

public function testInvalidOption(): void
Expand Down
13 changes: 5 additions & 8 deletions tests/Rules/Cell/RegexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,12 @@ public function testPositive(): void
public function testNegative(): void
{
$rule = $this->create('/^a/');
isSame(
'Value "1bc" does not match the pattern "/^a/"',
$rule->test('1bc'),
);
isSame('Value "1bc" does not match the pattern "/^a/"', $rule->test('1bc'));

$rule = $this->create('^a');
isSame(
'Value "1bc" does not match the pattern "/^a/"',
$rule->test('1bc'),
);
isSame('Value "1bc" does not match the pattern "/^a/"', $rule->test('1bc'));

$rule = $this->create('');
isSame('Regex pattern is not defined', $rule->test('1bc'));
}
}
13 changes: 5 additions & 8 deletions tests/Rules/Cell/StratsWithTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,18 @@ public function testPositive(): void
isSame('', $rule->test('a'));
isSame('', $rule->test('abc'));
isSame(null, $rule->validate(''));

$rule = $this->create('a');
isSame('', $rule->test(''));
}

public function testNegative(): void
{
$rule = $this->create('a');

isSame(
'Value " a" must start with "a"',
$rule->test(' a'),
);
isSame('Value " a" must start with "a"',$rule->test(' a'));

$rule = $this->create('');
isSame(
'Rule must contain a prefix value in schema file.',
$rule->test('a '),
);
isSame('Rule must contain a prefix value in schema file.', $rule->test('a '));
}
}
1 change: 1 addition & 0 deletions tests/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function testFindFiles(): void
])));

isSame([], $this->getFileName(Utils::findFiles([])));
isSame([], $this->getFileName(Utils::findFiles([''])));

$this->getFileName(Utils::findFiles(['*.qwerty']));

Expand Down

0 comments on commit 31f3158

Please sign in to comment.