2011-10-23 16:37:14 +02:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-06-08 17:09:25 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2011-10-23 16:37:14 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2016-10-30 20:07:28 +01:00
|
|
|
use Respect\Validation\Exceptions\ComponentException;
|
2018-01-07 14:12:55 +01:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
2016-10-30 20:07:28 +01:00
|
|
|
|
2015-08-16 20:00:05 +02:00
|
|
|
/**
|
2018-06-13 05:15:25 +02:00
|
|
|
* @group rule
|
|
|
|
*
|
2017-02-04 14:01:14 +01:00
|
|
|
* @covers \Respect\Validation\Rules\CreditCard
|
2018-06-13 05:15:25 +02:00
|
|
|
*
|
|
|
|
* @author Andy Snell <andysnell@gmail.com>
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
|
|
* @author Jean Pimentel <jeanfap@gmail.com>
|
|
|
|
* @author William Espindola <oi@williamespindola.com.br>
|
2022-10-22 10:17:00 +02:00
|
|
|
* @author Rakshit Arora <rakshit087@gmail.com>
|
2015-08-16 20:00:05 +02:00
|
|
|
*/
|
2018-06-13 05:15:25 +02:00
|
|
|
final class CreditCardTest extends RuleTestCase
|
2011-10-23 16:37:14 +02:00
|
|
|
{
|
2018-06-13 05:15:25 +02:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function itShouldThrowExceptionWhenCreditCardBrandIsNotValid(): void
|
2011-10-23 16:37:14 +02:00
|
|
|
{
|
2016-04-06 17:26:00 +02:00
|
|
|
$message = '"RespectCard" is not a valid credit card brand';
|
2023-02-13 22:58:16 +01:00
|
|
|
$message .= ' (Available: Any, American Express, Diners Club, Discover, JCB, MasterCard, Visa, RuPay)';
|
2016-04-06 17:26:00 +02:00
|
|
|
|
2018-08-22 18:30:48 +02:00
|
|
|
$this->expectException(ComponentException::class);
|
|
|
|
$this->expectExceptionMessage($message);
|
2016-04-06 17:26:00 +02:00
|
|
|
|
|
|
|
new CreditCard('RespectCard');
|
2011-10-23 16:37:14 +02:00
|
|
|
}
|
|
|
|
|
2018-06-13 05:15:25 +02:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-06-13 05:15:25 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForValidInput(): array
|
2011-10-23 16:37:14 +02:00
|
|
|
{
|
2016-04-06 17:26:00 +02:00
|
|
|
$general = new CreditCard();
|
|
|
|
$amex = new CreditCard(CreditCard::AMERICAN_EXPRESS);
|
|
|
|
$diners = new CreditCard(CreditCard::DINERS_CLUB);
|
|
|
|
$discover = new CreditCard(CreditCard::DISCOVER);
|
|
|
|
$jcb = new CreditCard(CreditCard::JCB);
|
|
|
|
$master = new CreditCard(CreditCard::MASTERCARD);
|
|
|
|
$visa = new CreditCard(CreditCard::VISA);
|
2022-10-22 10:17:00 +02:00
|
|
|
$rupay = new CreditCard(CreditCard::RUPAY);
|
2016-04-06 17:26:00 +02:00
|
|
|
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
2018-06-13 05:15:25 +02:00
|
|
|
[$general, 5555444433331111], // MasterCard 5 BIN Range
|
2016-12-05 05:56:43 +01:00
|
|
|
[$general, '5376 7473 9720 8720'], // MasterCard 5 BIN Range
|
2016-04-06 17:26:00 +02:00
|
|
|
[$master, '5376 7473 9720 8720'],
|
2016-12-05 05:56:43 +01:00
|
|
|
[$general, '2223000048400011'], // MasterCard 2 BIN Range
|
|
|
|
[$master, '2222 4000 4124 0011'],
|
2016-04-06 17:26:00 +02:00
|
|
|
[$general, '4024.0071.5336.1885'], // Visa 16
|
|
|
|
[$visa, '4024.0071.5336.1885'],
|
|
|
|
[$general, '4024 007 193 879'], // Visa 13
|
|
|
|
[$visa, '4024 007 193 879'],
|
|
|
|
[$general, '340-3161-9380-9364'], // American Express
|
|
|
|
[$amex, '340-3161-9380-9364'],
|
|
|
|
[$general, '30351042633884'], // Diners Club
|
|
|
|
[$diners, '30351042633884'],
|
|
|
|
[$general, '6011000990139424'], // Discover
|
|
|
|
[$discover, '6011000990139424'],
|
|
|
|
[$general, '3566002020360505'], // JBC
|
|
|
|
[$jcb, '3566002020360505'],
|
2022-10-22 10:17:00 +02:00
|
|
|
[$general, '6522447005971501'], // RuPay
|
|
|
|
[$rupay, '6062973831636410'],
|
2015-10-18 03:44:47 +02:00
|
|
|
];
|
2011-10-23 16:37:14 +02:00
|
|
|
}
|
|
|
|
|
2018-06-13 05:15:25 +02:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-06-13 05:15:25 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForInvalidInput(): array
|
2011-10-23 16:37:14 +02:00
|
|
|
{
|
2016-04-06 17:26:00 +02:00
|
|
|
$general = new CreditCard();
|
|
|
|
$amex = new CreditCard(CreditCard::AMERICAN_EXPRESS);
|
|
|
|
$diners = new CreditCard(CreditCard::DINERS_CLUB);
|
|
|
|
$discover = new CreditCard(CreditCard::DISCOVER);
|
|
|
|
$jcb = new CreditCard(CreditCard::JCB);
|
|
|
|
$master = new CreditCard(CreditCard::MASTERCARD);
|
|
|
|
$visa = new CreditCard(CreditCard::VISA);
|
|
|
|
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
2016-04-06 17:26:00 +02:00
|
|
|
[$general, ''],
|
|
|
|
[$general, null],
|
|
|
|
[$general, 'it isnt my credit card number'],
|
|
|
|
[$general, '&stR@ng3|) (|-|@r$'],
|
|
|
|
[$general, '1234 1234 1234 1234'],
|
|
|
|
[$general, '1234.1234.1234.1234'],
|
|
|
|
[$master, '6011111111111117'], // Discover
|
|
|
|
[$visa, '3530111333300000'], // JCB
|
|
|
|
[$amex, '5555555555554444'], // MasterCard
|
|
|
|
[$diners, '4012888888881881'], // Visa
|
|
|
|
[$discover, '371449635398431'], // American Express
|
|
|
|
[$jcb, '38520000023237'], // Diners Club
|
2015-10-18 03:44:47 +02:00
|
|
|
];
|
2011-10-23 16:37:14 +02:00
|
|
|
}
|
2023-02-13 22:58:16 +01:00
|
|
|
}
|