菜谱项目

LuhnTest.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Faker\Test\Calculator;
  3. use Faker\Calculator\Luhn;
  4. class LuhnTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function checkDigitProvider()
  7. {
  8. return array(
  9. array('7992739871', '3'),
  10. array('3852000002323', '7'),
  11. array('37144963539843', '1'),
  12. array('561059108101825', '0'),
  13. array('601100099013942', '4'),
  14. array('510510510510510', '0'),
  15. array(7992739871, '3'),
  16. array(3852000002323, '7'),
  17. array('37144963539843', '1'),
  18. array('561059108101825', '0'),
  19. array('601100099013942', '4'),
  20. array('510510510510510', '0')
  21. );
  22. }
  23. /**
  24. * @dataProvider checkDigitProvider
  25. */
  26. public function testComputeCheckDigit($partialNumber, $checkDigit)
  27. {
  28. $this->assertInternalType('string', $checkDigit);
  29. $this->assertEquals($checkDigit, Luhn::computeCheckDigit($partialNumber));
  30. }
  31. public function validatorProvider()
  32. {
  33. return array(
  34. array('79927398710', false),
  35. array('79927398711', false),
  36. array('79927398712', false),
  37. array('79927398713', true),
  38. array('79927398714', false),
  39. array('79927398715', false),
  40. array('79927398716', false),
  41. array('79927398717', false),
  42. array('79927398718', false),
  43. array('79927398719', false),
  44. array(79927398713, true),
  45. array(79927398714, false),
  46. );
  47. }
  48. /**
  49. * @dataProvider validatorProvider
  50. */
  51. public function testIsValid($number, $isValid)
  52. {
  53. $this->assertEquals($isValid, Luhn::isValid($number));
  54. }
  55. /**
  56. * @expectedException InvalidArgumentException
  57. * @expectedExceptionMessage Argument should be an integer.
  58. */
  59. public function testGenerateLuhnNumberWithInvalidPrefix()
  60. {
  61. Luhn::generateLuhnNumber('abc');
  62. }
  63. }