Skip to content

Commit a21110e

Browse files
committed
Fixed alpha numeric length validation with multibyte characters.
1 parent 67eabcf commit a21110e

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

Diff for: composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
"guzzlehttp/guzzle": "^6.3"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "~5.2"
24+
"phpunit/phpunit": "~7.5"
2525
},
2626
"autoload": {
2727
"psr-4": {
28-
"Ekyna\\Component\\Dpd\\": "src/"
28+
"Ekyna\\Component\\Dpd\\": "src/",
29+
"Ekyna\\Component\\Dpd\\": "tests/"
2930
}
3031
},
3132
"extra": {

Diff for: src/Definition/AlphaNumeric.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function validate($value, string $prefix = null): void
4747
$this->throwValidationException("Expected string value", $prefix);
4848
}
4949

50-
if (strlen($value) > $this->length) {
50+
if (mb_strlen($value) > $this->length) {
5151
$this->throwValidationException("Expected string with max length $this->length", $prefix);
5252
}
5353
}

Diff for: tests/EPrint/Model/AddressTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function test_validation_with_valid_data()
2828
$address->countryPrefix = 'FR';
2929
$address->zipCode = '12345';
3030
$address->city = 'City';
31-
$address->street = 'Street';
31+
$address->street = 'Chaîne avec ’ caractères spéciaux';
3232
$address->phoneNumber = '12345678';
3333

3434
$address->validate();

Diff for: tests/TestCase.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace Ekyna\Component\Dpd;
44

5+
use PHPUnit\Framework\TestCase as BaseCase;
56
use Ekyna\Component\Dpd\Exception;
6-
use Ekyna\Component\Dpd\AbstractInput;
77

88
/**
99
* Class TestCase
1010
* @author Etienne Dauvergne <contact@ekyna.com>
1111
* @package Ekyna\Component\Dpd
1212
*/
13-
class TestCase extends \PHPUnit_Framework_TestCase
13+
class TestCase extends BaseCase
1414
{
1515
protected function expectValidationException()
1616
{
@@ -46,4 +46,4 @@ protected function buildDefinition(Definition\Definition $definition): void
4646
{
4747
$definition->addField(new Definition\Boolean('test', true));
4848
}
49-
}
49+
}

0 commit comments

Comments
 (0)