Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/203' into develop
Browse files Browse the repository at this point in the history
Forward port #203
  • Loading branch information
weierophinney committed Feb 1, 2018
2 parents d17f740 + 8d3f119 commit 811d503
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ All notable changes to this project will be documented in this file, in reverse
`Zend\Validator\CreditCard`, fixing an issue where users were unable to add
new brands as they are created.

- [#203](https://github.com/zendframework/zend-validator/pull/203) adds support
for the new Russian bank card "Mir".

### Changed

- Nothing.
Expand Down
1 change: 1 addition & 0 deletions doc/book/validators/credit-card.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The following issuing institutes are accepted:
- Solo
- Visa
- Visa Electron
- Russia Mir

> ### Invalid institutes
>
Expand Down
4 changes: 4 additions & 0 deletions src/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CreditCard extends AbstractValidator
const MASTERCARD = 'Mastercard';
const SOLO = 'Solo';
const VISA = 'Visa';
const MIR = 'Mir';

const CHECKSUM = 'creditcardChecksum';
const CONTENT = 'creditcardContent';
Expand Down Expand Up @@ -72,6 +73,7 @@ class CreditCard extends AbstractValidator
8 => self::SOLO,
9 => self::UNIONPAY,
10 => self::VISA,
11 => self::MIR,
];

/**
Expand All @@ -91,6 +93,7 @@ class CreditCard extends AbstractValidator
self::SOLO => [16, 18, 19],
self::UNIONPAY => [16, 17, 18, 19],
self::VISA => [13, 16, 19],
self::MIR => [13, 16],
];

/**
Expand Down Expand Up @@ -122,6 +125,7 @@ class CreditCard extends AbstractValidator
'6224', '6225', '6226', '6227', '6228', '62290', '62291',
'622920', '622921', '622922', '622923', '622924', '622925'],
self::VISA => ['4'],
self::MIR => ['2200', '2201', '2202', '2203', '2204'],
];

/**
Expand Down
41 changes: 40 additions & 1 deletion test/CreditCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testGetMessages()
public function testGetSetType()
{
$validator = new CreditCard();
$this->assertEquals(11, count($validator->getType()));
$this->assertEquals(12, count($validator->getType()));

$validator->setType(CreditCard::MAESTRO);
$this->assertEquals([CreditCard::MAESTRO], $validator->getType());
Expand Down Expand Up @@ -253,6 +253,45 @@ public function testMastercardCard($input, $expected)
$this->assertEquals($expected, $validator->isValid($input));
}

/**
* Data provider
*
* @return string[][]|bool[][]
*/
public function mirValues()
{
return [
['3011111111111000', false],
['2031343323344731', false],
['2200312032822721', true],
['2209993834549400', false],
['2204001882200999', true],
['2202000312124573', true],
['2203921957923012', true],
['2204150479254495', true],
['2201123406612104', true],
['2900008996056', false],
['2201969950494', true],
['2201342387927', true],
['2205969950494', false],
];
}

/**
* Test mir card number validity
*
* @dataProvider mirValues
*
* @param string $input
* @param bool $expected
*/
public function testMirCard($input, $expected)
{
$validator = new CreditCard(['type' => CreditCard::MIR]);

$this->assertEquals($expected, $validator->isValid($input));
}

/**
* Test an invalid service class
*
Expand Down

0 comments on commit 811d503

Please sign in to comment.