-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new rule 'is_currency_code' has been added to the schema examples in full.json, full.php, and full.yml files. This rule validates ISO 4217 currency codes like 'GBP' or 'EUR'. Corresponding to this, a new PHP file 'IsCurrencyCode.php' has been created under the 'src/Rules/Cell' directory to implement the validation rule. Similarly, a new test file 'CurrencyCodeTest.php' has been added to check the proper functioning of the newly implemented rule. The README.md file has been updated to reflect these changes.
- Loading branch information
Showing
6 changed files
with
105 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\CsvBlueprint\Rules\Cell; | ||
|
||
use Respect\Validation\Validator; | ||
|
||
final class IsCurrencyCode extends AbstractCellRule | ||
{ | ||
protected const HELP_OPTIONS = [ | ||
self::DEFAULT => [ | ||
'true', | ||
'Validates an ISO 4217 currency code like GBP or EUR. Case-sensitive. ' . | ||
'See: https://en.wikipedia.org/wiki/ISO_4217', | ||
], | ||
]; | ||
|
||
public function validateRule(string $cellValue): ?string | ||
{ | ||
if ($cellValue === '') { | ||
return null; | ||
} | ||
|
||
if (!Validator::currencyCode()->validate($cellValue)) { | ||
return "Value \"<c>{$cellValue}</c>\" is not a valid currency code (ISO_4217)"; | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?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\IsCurrencyCode; | ||
use JBZoo\PHPUnit\Rules\AbstractCellRule; | ||
|
||
use function JBZoo\PHPUnit\isSame; | ||
|
||
final class CurrencyCodeTest extends AbstractCellRule | ||
{ | ||
protected string $ruleClass = IsCurrencyCode::class; | ||
|
||
public function testPositive(): void | ||
{ | ||
$rule = $this->create(true); | ||
isSame('', $rule->test('')); | ||
isSame('', $rule->test('USD')); | ||
isSame('', $rule->test('EUR')); | ||
|
||
$rule = $this->create(false); | ||
isSame(null, $rule->validate('qwerty')); | ||
} | ||
|
||
public function testNegative(): void | ||
{ | ||
$rule = $this->create(true); | ||
isSame( | ||
'Value "usd" is not a valid currency code (ISO_4217)', | ||
$rule->test('usd'), | ||
); | ||
isSame( | ||
'Value "qwerty" is not a valid currency code (ISO_4217)', | ||
$rule->test('qwerty'), | ||
); | ||
} | ||
} |