You are here

class CardSchemeValidatorTest in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/validator/Tests/Constraints/CardSchemeValidatorTest.php \Symfony\Component\Validator\Tests\Constraints\CardSchemeValidatorTest

Hierarchy

Expanded class hierarchy of CardSchemeValidatorTest

File

vendor/symfony/validator/Tests/Constraints/CardSchemeValidatorTest.php, line 18

Namespace

Symfony\Component\Validator\Tests\Constraints
View source
class CardSchemeValidatorTest extends AbstractConstraintValidatorTest {
  protected function getApiVersion() {
    return Validation::API_VERSION_2_5;
  }
  protected function createValidator() {
    return new CardSchemeValidator();
  }
  public function testNullIsValid() {
    $this->validator
      ->validate(null, new CardScheme(array(
      'schemes' => array(),
    )));
    $this
      ->assertNoViolation();
  }
  public function testEmptyStringIsValid() {
    $this->validator
      ->validate('', new CardScheme(array(
      'schemes' => array(),
    )));
    $this
      ->assertNoViolation();
  }

  /**
   * @dataProvider getValidNumbers
   */
  public function testValidNumbers($scheme, $number) {
    $this->validator
      ->validate($number, new CardScheme(array(
      'schemes' => $scheme,
    )));
    $this
      ->assertNoViolation();
  }

  /**
   * @dataProvider getInvalidNumbers
   */
  public function testInvalidNumbers($scheme, $number, $code) {
    $constraint = new CardScheme(array(
      'schemes' => $scheme,
      'message' => 'myMessage',
    ));
    $this->validator
      ->validate($number, $constraint);
    $this
      ->buildViolation('myMessage')
      ->setParameter('{{ value }}', is_string($number) ? '"' . $number . '"' : $number)
      ->setCode($code)
      ->assertRaised();
  }
  public function getValidNumbers() {
    return array(
      array(
        'AMEX',
        '378282246310005',
      ),
      array(
        'AMEX',
        '371449635398431',
      ),
      array(
        'AMEX',
        '378734493671000',
      ),
      array(
        'AMEX',
        '347298508610146',
      ),
      array(
        'CHINA_UNIONPAY',
        '6228888888888888',
      ),
      array(
        'CHINA_UNIONPAY',
        '62288888888888888',
      ),
      array(
        'CHINA_UNIONPAY',
        '622888888888888888',
      ),
      array(
        'CHINA_UNIONPAY',
        '6228888888888888888',
      ),
      array(
        'DINERS',
        '30569309025904',
      ),
      array(
        'DINERS',
        '36088894118515',
      ),
      array(
        'DINERS',
        '38520000023237',
      ),
      array(
        'DISCOVER',
        '6011111111111117',
      ),
      array(
        'DISCOVER',
        '6011000990139424',
      ),
      array(
        'INSTAPAYMENT',
        '6372476031350068',
      ),
      array(
        'INSTAPAYMENT',
        '6385537775789749',
      ),
      array(
        'INSTAPAYMENT',
        '6393440808445746',
      ),
      array(
        'JCB',
        '3530111333300000',
      ),
      array(
        'JCB',
        '3566002020360505',
      ),
      array(
        'JCB',
        '213112345678901',
      ),
      array(
        'JCB',
        '180012345678901',
      ),
      array(
        'LASER',
        '6304678107004080',
      ),
      array(
        'LASER',
        '6706440607428128629',
      ),
      array(
        'LASER',
        '6771656738314582216',
      ),
      array(
        'MAESTRO',
        '6759744069209',
      ),
      array(
        'MAESTRO',
        '5020507657408074712',
      ),
      array(
        'MAESTRO',
        '5612559223580173965',
      ),
      array(
        'MAESTRO',
        '6759744069209',
      ),
      array(
        'MAESTRO',
        '6759744069209',
      ),
      array(
        'MAESTRO',
        '6594371785970435599',
      ),
      array(
        'MASTERCARD',
        '5555555555554444',
      ),
      array(
        'MASTERCARD',
        '5105105105105100',
      ),
      array(
        'VISA',
        '4111111111111111',
      ),
      array(
        'VISA',
        '4012888888881881',
      ),
      array(
        'VISA',
        '4222222222222',
      ),
      array(
        array(
          'AMEX',
          'VISA',
        ),
        '4111111111111111',
      ),
      array(
        array(
          'AMEX',
          'VISA',
        ),
        '378282246310005',
      ),
      array(
        array(
          'JCB',
          'MASTERCARD',
        ),
        '5105105105105100',
      ),
      array(
        array(
          'VISA',
          'MASTERCARD',
        ),
        '5105105105105100',
      ),
    );
  }
  public function getInvalidNumbers() {
    return array(
      array(
        'VISA',
        '42424242424242424242',
        CardScheme::INVALID_FORMAT_ERROR,
      ),
      array(
        'AMEX',
        '357298508610146',
        CardScheme::INVALID_FORMAT_ERROR,
      ),
      array(
        'DINERS',
        '31569309025904',
        CardScheme::INVALID_FORMAT_ERROR,
      ),
      array(
        'DINERS',
        '37088894118515',
        CardScheme::INVALID_FORMAT_ERROR,
      ),
      array(
        'INSTAPAYMENT',
        '6313440808445746',
        CardScheme::INVALID_FORMAT_ERROR,
      ),
      array(
        'CHINA_UNIONPAY',
        '622888888888888',
        CardScheme::INVALID_FORMAT_ERROR,
      ),
      array(
        'CHINA_UNIONPAY',
        '62288888888888888888',
        CardScheme::INVALID_FORMAT_ERROR,
      ),
      array(
        'AMEX',
        '30569309025904',
        CardScheme::INVALID_FORMAT_ERROR,
      ),
      // DINERS number
      array(
        'AMEX',
        'invalid',
        CardScheme::NOT_NUMERIC_ERROR,
      ),
      // A string
      array(
        'AMEX',
        0,
        CardScheme::INVALID_FORMAT_ERROR,
      ),
      // a lone number
      array(
        'AMEX',
        '0',
        CardScheme::INVALID_FORMAT_ERROR,
      ),
      // a lone number
      array(
        'AMEX',
        '000000000000',
        CardScheme::INVALID_FORMAT_ERROR,
      ),
      // a lone number
      array(
        'DINERS',
        '3056930',
        CardScheme::INVALID_FORMAT_ERROR,
      ),
      // only first part of the number
      array(
        'DISCOVER',
        '1117',
        CardScheme::INVALID_FORMAT_ERROR,
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractConstraintValidatorTest::$constraint protected property
AbstractConstraintValidatorTest::$context protected property 1
AbstractConstraintValidatorTest::$defaultTimezone protected property
AbstractConstraintValidatorTest::$group protected property
AbstractConstraintValidatorTest::$metadata protected property
AbstractConstraintValidatorTest::$object protected property
AbstractConstraintValidatorTest::$propertyPath protected property
AbstractConstraintValidatorTest::$root protected property
AbstractConstraintValidatorTest::$validator protected property 1
AbstractConstraintValidatorTest::$value protected property
AbstractConstraintValidatorTest::assertNoViolation protected function
AbstractConstraintValidatorTest::assertViolation Deprecated protected function
AbstractConstraintValidatorTest::assertViolations Deprecated protected function
AbstractConstraintValidatorTest::buildViolation protected function
AbstractConstraintValidatorTest::createContext protected function
AbstractConstraintValidatorTest::createViolation Deprecated protected function
AbstractConstraintValidatorTest::expectNoValidate protected function
AbstractConstraintValidatorTest::expectValidateAt protected function
AbstractConstraintValidatorTest::expectValidateValueAt protected function
AbstractConstraintValidatorTest::restoreDefaultTimezone protected function
AbstractConstraintValidatorTest::setDefaultTimezone protected function
AbstractConstraintValidatorTest::setGroup protected function
AbstractConstraintValidatorTest::setObject protected function
AbstractConstraintValidatorTest::setProperty protected function
AbstractConstraintValidatorTest::setPropertyPath protected function
AbstractConstraintValidatorTest::setRoot protected function
AbstractConstraintValidatorTest::setUp protected function 2
AbstractConstraintValidatorTest::setValue protected function
AbstractConstraintValidatorTest::tearDown protected function 1
CardSchemeValidatorTest::createValidator protected function Overrides AbstractConstraintValidatorTest::createValidator
CardSchemeValidatorTest::getApiVersion protected function Overrides AbstractConstraintValidatorTest::getApiVersion
CardSchemeValidatorTest::getInvalidNumbers public function
CardSchemeValidatorTest::getValidNumbers public function
CardSchemeValidatorTest::testEmptyStringIsValid public function
CardSchemeValidatorTest::testInvalidNumbers public function @dataProvider getInvalidNumbers
CardSchemeValidatorTest::testNullIsValid public function
CardSchemeValidatorTest::testValidNumbers public function @dataProvider getValidNumbers