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

Improve test coverage #2

Merged
merged 4 commits into from
Mar 10, 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
1 change: 1 addition & 0 deletions src/Commands/CreateCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

/**
* @psalm-suppress PropertyNotSetInConstructor
* @codeCoverageIgnore
*/
final class CreateCsv extends CliCommand
{
Expand Down
1 change: 1 addition & 0 deletions src/Commands/CreateSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

/**
* @psalm-suppress PropertyNotSetInConstructor
* @codeCoverageIgnore
*/
final class CreateSchema extends CliCommand
{
Expand Down
1 change: 1 addition & 0 deletions src/Commands/ValidateCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

/**
* @psalm-suppress PropertyNotSetInConstructor
* @codeCoverageIgnore
*/
final class ValidateCsv extends CliCommand
{
Expand Down
1 change: 1 addition & 0 deletions src/Commands/ValidateDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

/**
* @psalm-suppress PropertyNotSetInConstructor
* @codeCoverageIgnore
*/
final class ValidateDir extends CliCommand
{
Expand Down
2 changes: 2 additions & 0 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function __construct(null|array|string $csvSchemaFilenameOrArray = null)
} else {
throw new \InvalidArgumentException("Unsupported file extension: {$fileExtension}");
}
} elseif (\is_string($csvSchemaFilenameOrArray)) {
throw new \InvalidArgumentException("Invalid schema data: {$csvSchemaFilenameOrArray}");
} else {
$this->filename = null;
$this->data = new Data();
Expand Down
52 changes: 47 additions & 5 deletions tests/Blueprint/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public function testIsBool(): void
'"is_bool" at line 0, column "prop". Value "1" is not allowed. Allowed values: ["true", "false"].',
(string)$rule->validate('1'),
);

$rule = new IsBool('prop', false);
isSame(null, $rule->validate('1'));
}

public function testIsDomain(): void
Expand All @@ -139,12 +142,15 @@ 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)(string)$rule->validate('example'),
(string)$rule->validate('example'),
);
isSame(
'"is_domain" at line 0, column "prop". Value "" is not a valid domain.',
(string)$rule->validate(''),
);

$rule = new IsDomain('prop', false);
isSame(null, $rule->validate('example'));
}

public function testIsEmail(): void
Expand All @@ -154,8 +160,11 @@ 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)(string)$rule->validate('user:pass@example.com'),
(string)$rule->validate('user:pass@example.com'),
);

$rule = new IsEmail('prop', false);
isSame(null, $rule->validate('user:pass@example.com'));
}

public function testIsFloat(): void
Expand All @@ -179,6 +188,9 @@ public function testIsFloat(): void
'"is_float" at line 0, column "prop". Value " 1" is not a float number.',
(string)$rule->validate(' 1'),
);

$rule = new IsFloat('prop', false);
isSame(null, $rule->validate(' 1'));
}

public function testIsInt(): void
Expand All @@ -195,7 +207,7 @@ public function testIsInt(): void
);
isSame(
'"is_int" at line 0, column "prop". Value "1.1" is not an integer.',
(string)(string)$rule->validate('1.1'),
(string)$rule->validate('1.1'),
);
isSame(
'"is_int" at line 0, column "prop". Value "1.0" is not an integer.',
Expand All @@ -207,12 +219,15 @@ public function testIsInt(): void
);
isSame(
'"is_int" at line 0, column "prop". Value " 1" is not an integer.',
(string)(string)$rule->validate(' 1'),
(string)$rule->validate(' 1'),
);
isSame(
'"is_int" at line 0, column "prop". Value "1 " is not an integer.',
(string)(string)$rule->validate('1 '),
(string)$rule->validate('1 '),
);

$rule = new IsInt('prop', false);
isSame(null, $rule->validate(' 1'));
}

public function testIsIp(): void
Expand Down Expand Up @@ -244,6 +259,9 @@ public function testIsLatitude(): void
'"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'),
);

$rule = new IsLatitude('prop', false);
isSame(null, $rule->validate('90.1.1.1.1'));
}

public function testIsLongitude(): void
Expand All @@ -269,6 +287,9 @@ public function testIsLongitude(): void
'"is_longitude" at line 0, column "prop". Value "1.0.0.0" is not a float number.',
(string)$rule->validate('1.0.0.0'),
);

$rule = new IsLongitude('prop', false);
isSame(null, $rule->validate('1.0.0.0'));
}

public function testIsUrl(): void
Expand All @@ -285,6 +306,9 @@ public function testIsUrl(): void
'"is_url" at line 0, column "prop". Value "//example.com" is not a valid URL.',
(string)$rule->validate('//example.com'),
);

$rule = new IsUrl('prop', false);
isSame(null, $rule->validate('//example.com'));
}

public function testMin(): void
Expand Down Expand Up @@ -436,6 +460,9 @@ public function testNotEmpty(): void
'"not_empty" at line 0, column "prop". Value is empty.',
(string)$rule->validate(null),
);

$rule = new NotEmpty('prop', false);
isSame(null, $rule->validate(null));
}

public function testOnlyCapitalize(): void
Expand All @@ -454,6 +481,9 @@ public function testOnlyCapitalize(): void
'"only_capitalize" at line 0, column "prop". Value "qwe Rty" should be in capitalize.',
(string)$rule->validate('qwe Rty'),
);

$rule = new OnlyCapitalize('prop', false);
isSame(null, $rule->validate('qwerty'));
}

public function testOnlyLowercase(): void
Expand All @@ -472,6 +502,9 @@ public function testOnlyLowercase(): void
'"only_lowercase" at line 0, column "prop". Value "qwe Rty" should be in lowercase.',
(string)$rule->validate('qwe Rty'),
);

$rule = new OnlyLowercase('prop', false);
isSame(null, $rule->validate('Qwerty'));
}

public function testOnlyUppercase(): void
Expand All @@ -489,6 +522,9 @@ public function testOnlyUppercase(): void
'"only_uppercase" at line 0, column "prop". Value "qwe Rty" is not uppercase.',
(string)$rule->validate('qwe Rty'),
);

$rule = new OnlyUppercase('prop', false);
isSame(null, $rule->validate('Qwerty'));
}

public function testPrecision(): void
Expand Down Expand Up @@ -590,6 +626,9 @@ public function testUsaMarketName(): void
'Market name must have format "New York, NY".',
(string)$rule->validate(', ST'),
);

$rule = new UsaMarketName('prop', false);
isSame(null, $rule->validate(', ST'));
}

public function testIsUuid4(): void
Expand All @@ -600,5 +639,8 @@ public function testIsUuid4(): void
'"is_uuid4" at line 0, column "prop". Value is not a valid UUID v4.',
(string)$rule->validate('123'),
);

$rule = new IsUuid4('prop', false);
isSame(null, $rule->validate('123'));
}
}
Loading
Loading