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

Deprecate other values than string for CreditCard #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions src/IsoCodes/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ class CreditCard implements IsoCodeInterface
*/
public static function validate($creditCard)
{
if (!is_string($creditCard) && !empty($creditCard)) {
@trigger_error(
'Passing other values than a string on '.__METHOD__.' is deprecated since version 2.2.'
.' It will be considered as invalid on version 3.0.',
E_USER_DEPRECATED
);
}

// Add !is_string($creditCard) to the condition on 3.0.
if (trim($creditCard) === '') {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/IsoCodes/Tests/AbstractIsoCodeInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ abstract class AbstractIsoCodeInterfaceTest extends AbstractIsoCodeTest
{
/**
* @dataProvider getValidValues
* @dataProvider getLegacyValidValues
*/
final public function testValidValues($value)
{
Expand All @@ -18,6 +19,7 @@ final public function testValidValues($value)

/**
* @dataProvider getInvalidValues
* @dataProvider getLegacyInvalidValidValues
*/
final public function testInvalidValues($value)
{
Expand Down
20 changes: 20 additions & 0 deletions tests/IsoCodes/Tests/AbstractIsoCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,31 @@ abstract class AbstractIsoCodeTest extends \PHPUnit_Framework_TestCase
*/
abstract public function getValidValues();

/**
* Optional. For legacy tests.
*
* @return array[]
*/
public function getLegacyValidValues()
{
return [];
}

/**
* @return array[]
*/
abstract public function getInvalidValues();

/**
* Optional. For legacy tests.
*
* @return array[]
*/
public function getLegacyInvalidValues()
{
return [];
}

final public function testEmptyValues()
{
$class = $this->getIsoCodesClass();
Expand Down
16 changes: 15 additions & 1 deletion tests/IsoCodes/Tests/CreditCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function getValidValues()
['4903010000000009'], //Switch
['4111111111111111'], //Visa
['6304100000000008'], //Laser
[6304100000000008], //Laser
['4917300800000000'], // VisaElectron
['6759649826438453'], // Maestro (long)
['6799990100000000019'], // maestro (short)
Expand All @@ -36,6 +35,21 @@ public function getValidValues()
];
}

/**
* {@inheritdoc}
*/
public function getLegacyValidValues()
{
$values = [];

// To be removed on 4.0.
if (8 === PHP_INT_SIZE) { // This test will success only on 64bits systems.
$values[] = [6304100000000008]; // Laser
}

return $values;
}

/**
* {@inheritdoc}
*/
Expand Down