Skip to content

Commit 0619820

Browse files
author
Jon Waldstein
committed
refactor: revert back to an updated list of curerncies
1 parent c5d3969 commit 0619820

2 files changed

Lines changed: 10 additions & 42 deletions

File tree

src/Rules/Currency.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@
1010

1111
class Currency implements ValidationRule, ValidatesOnFrontEnd
1212
{
13-
/**
14-
* @var string[]
15-
*/
16-
protected $currencyCodes;
17-
18-
/**
19-
* @unreleased
20-
*/
21-
public function __construct(?array $currencyCodes = null)
22-
{
23-
$this->currencyCodes = $currencyCodes ?? self::currencyCodes();
24-
}
2513

2614
/**
2715
* @inheritDoc
@@ -60,7 +48,7 @@ public function serializeOption()
6048
*/
6149
public function __invoke($value, Closure $fail, string $key, array $values)
6250
{
63-
if (!is_string($value) || !in_array(strtoupper($value), $this->currencyCodes, true)) {
51+
if (!is_string($value) || !in_array(strtoupper($value), self::currencyCodes(), true)) {
6452
$fail(sprintf(__('%s must be a valid currency', '%TEXTDOMAIN%'), '{field}'));
6553
}
6654
}

tests/unit/Rules/CurrencyTest.php

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
git <?php
1+
<?php
22

33
declare(strict_types=1);
44

@@ -10,7 +10,7 @@
1010
class CurrencyTest extends TestCase
1111
{
1212
/**
13-
* @since 1.1.0
13+
* @unreleased
1414
* @dataProvider currencyProvider
1515
*/
1616
public function testCurrencyValidations($currency, $shouldPass)
@@ -24,31 +24,12 @@ public function testCurrencyValidations($currency, $shouldPass)
2424
}
2525
}
2626

27-
/**
28-
* Test custom currency codes override functionality.
29-
*
30-
* @since 1.1.0
31-
*/
32-
public function testCustomCurrencyCodesOverride()
33-
{
34-
// Test with custom currency codes
35-
$customCodes = ['XYZ', 'ABC', 'DEF'];
36-
$rule = new Currency($customCodes);
37-
38-
// Custom codes should pass
39-
self::assertValidationRulePassed($rule, 'XYZ');
40-
self::assertValidationRulePassed($rule, 'ABC');
41-
self::assertValidationRulePassed($rule, 'def'); // case insensitive
4227

43-
// Standard codes should fail when using custom list
44-
self::assertValidationRuleFailed($rule, 'USD');
45-
self::assertValidationRuleFailed($rule, 'EUR');
46-
}
4728

4829
/**
4930
* Test that obsolete currency codes no longer pass validation.
5031
*
51-
* @since 1.1.0
32+
* @unreleased
5233
* @dataProvider obsoleteCurrencyProvider
5334
*/
5435
public function testObsoleteCurrencyCodesFail($currency)
@@ -60,7 +41,7 @@ public function testObsoleteCurrencyCodesFail($currency)
6041
/**
6142
* Test newly added currency codes pass validation.
6243
*
63-
* @since 1.1.0
44+
* @unreleased
6445
* @dataProvider newCurrencyProvider
6546
*/
6647
public function testNewCurrencyCodesPass($currency)
@@ -72,7 +53,7 @@ public function testNewCurrencyCodesPass($currency)
7253
/**
7354
* Test case insensitivity with various currency codes.
7455
*
75-
* @since 1.1.0
56+
* @unreleased
7657
* @dataProvider caseInsensitiveProvider
7758
*/
7859
public function testCaseInsensitivity($currency, $shouldPass)
@@ -87,7 +68,7 @@ public function testCaseInsensitivity($currency, $shouldPass)
8768
}
8869

8970
/**
90-
* @since 1.1.0
71+
* @unreleased
9172
*/
9273
public function currencyProvider(): array
9374
{
@@ -149,7 +130,7 @@ public function currencyProvider(): array
149130
/**
150131
* Currency codes that were removed in the 2024 update.
151132
*
152-
* @since 1.1.0
133+
* @unreleased
153134
*/
154135
public function obsoleteCurrencyProvider(): array
155136
{
@@ -168,7 +149,7 @@ public function obsoleteCurrencyProvider(): array
168149
/**
169150
* New currency codes added in the 2024 update.
170151
*
171-
* @since 1.1.0
152+
* @unreleased
172153
*/
173154
public function newCurrencyProvider(): array
174155
{
@@ -211,7 +192,6 @@ public function newCurrencyProvider(): array
211192
['RWF'], // Rwandan Franc
212193
['SDG'], // Sudanese Pound
213194
['SLE'], // Sierra Leonean Leone (new)
214-
['SLL'], // Sierra Leonean Leone (old)
215195
['SSP'], // South Sudanese Pound
216196
['STN'], // São Tomé and Príncipe Dobra
217197
['SZL'], // Swazi Lilangeni
@@ -237,7 +217,7 @@ public function newCurrencyProvider(): array
237217
/**
238218
* Test various case combinations.
239219
*
240-
* @since 1.1.0
220+
* @unreleased
241221
*/
242222
public function caseInsensitiveProvider(): array
243223
{

0 commit comments

Comments
 (0)