You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.6KB

  1. <?php
  2. namespace Faker\Test\Provider;
  3. class PaymentTest extends \PHPUnit_Framework_TestCase
  4. {
  5. public function setUp()
  6. {
  7. $faker = new \Faker\Generator();
  8. $faker->addProvider(new \Faker\Provider\Base($faker));
  9. $faker->addProvider(new \Faker\Provider\DateTime($faker));
  10. $faker->addProvider(new \Faker\Provider\Person($faker));
  11. $faker->addProvider(new \Faker\Provider\Payment($faker));
  12. $this->faker = $faker;
  13. }
  14. public function testCreditCardTypeReturnsValidVendorName()
  15. {
  16. $this->assertTrue(in_array($this->faker->creditCardType, array('Visa', 'MasterCard', 'American Express', 'Discover Card')));
  17. }
  18. public function testCreditCardNumberReturnsValidCreditCardNumber()
  19. {
  20. $this->assertRegExp('/^6011\d{12}$/', $this->faker->creditCardNumber('Discover Card'));
  21. }
  22. public function testCreditCardNumberCanFormatOutput()
  23. {
  24. $this->assertRegExp('/^6011-\d{4}-\d{4}-\d{4}$/', $this->faker->creditCardNumber('Discover Card', true));
  25. }
  26. public function testCreditCardExpirationDateReturnsValidDateByDefault()
  27. {
  28. $expirationDate = $this->faker->creditCardExpirationDate;
  29. $this->assertTrue(intval($expirationDate->format('U')) > strtotime('now'));
  30. $this->assertTrue(intval($expirationDate->format('U')) < strtotime('+36 months'));
  31. }
  32. public function testRandomCard()
  33. {
  34. $cardDetails = $this->faker->creditCardDetails;
  35. $this->assertEquals(count($cardDetails), 4);
  36. $this->assertEquals(array('type', 'number', 'name', 'expirationDate'), array_keys($cardDetails));
  37. }
  38. }