class CreditCardTypeTest in Commerce Core 8.2
@coversDefaultClass \Drupal\commerce_payment\CreditCardType @group commerce
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait- class \Drupal\Tests\commerce_payment\Unit\CreditCardTypeTest
 
Expanded class hierarchy of CreditCardTypeTest
File
- modules/payment/ tests/ src/ Unit/ CreditCardTypeTest.php, line 12 
Namespace
Drupal\Tests\commerce_payment\UnitView source
class CreditCardTypeTest extends UnitTestCase {
  /**
   * The credit card type definition array.
   *
   * @var array
   */
  protected $definition;
  /**
   * The credit card type.
   *
   * @var \Drupal\commerce_payment\CreditCardType
   */
  protected $type;
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->definition = [
      'id' => 'dummy',
      'label' => 'DummyCard',
      'number_prefixes' => [
        '51-55',
        '500',
        '222100-272099',
      ],
      'number_lengths' => [
        5,
        10,
      ],
      'security_code_length' => 6,
      'uses_luhn' => FALSE,
    ];
    $this->type = new CreditCardType($this->definition);
  }
  /**
   * @covers ::getId
   */
  public function testGetId() {
    $this
      ->assertEquals($this->definition['id'], $this->type
      ->getId());
  }
  /**
   * @covers ::getLabel
   */
  public function testGetLabel() {
    $this
      ->assertEquals($this->definition['label'], $this->type
      ->getLabel());
  }
  /**
   * @covers ::getNumberPrefixes
   */
  public function testGetNumberPrefixes() {
    $this
      ->assertEquals($this->definition['number_prefixes'], $this->type
      ->getNumberPrefixes());
  }
  /**
   * @covers ::getNumberLengths
   */
  public function testGetNumberLengths() {
    $this
      ->assertEquals($this->definition['number_lengths'], $this->type
      ->getNumberLengths(), 'Credit card type number length matches.');
  }
  /**
   * @covers ::getSecurityCodeLength
   */
  public function testGetSecurityCodeLength() {
    $this
      ->assertEquals($this->definition['security_code_length'], $this->type
      ->getSecurityCodeLength(), 'Credit card type security code length matches.');
  }
  /**
   * @covers ::usesLuhn
   */
  public function testUsesLuhn() {
    $this
      ->assertEquals($this->definition['uses_luhn'], $this->type
      ->usesLuhn());
  }
  /**
   * Tests the creation of a CreditCardType with an invalid definition.
   *
   * @dataProvider definitionProvider
   */
  public function testInvalidDefinition($definition, $message) {
    $this
      ->expectException(\InvalidArgumentException::class);
    $this
      ->expectExceptionMessage($message);
    $card = new CreditCardType($definition);
  }
  /**
   * Data provider for ::testInvalidDefinition.
   *
   * @return array
   *   A list of testInvalidDefinition function arguments.
   */
  public function definitionProvider() {
    return [
      [
        [],
        'Missing required property id.',
      ],
      [
        [
          'id' => 'llama',
        ],
        'Missing required property label.',
      ],
      [
        [
          'id' => 'llama',
          'label' => 'Llama',
        ],
        'Missing required property number_prefixes.',
      ],
    ];
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| CreditCardTypeTest:: | protected | property | The credit card type definition array. | |
| CreditCardTypeTest:: | protected | property | The credit card type. | |
| CreditCardTypeTest:: | public | function | Data provider for ::testInvalidDefinition. | |
| CreditCardTypeTest:: | protected | function | Overrides UnitTestCase:: | |
| CreditCardTypeTest:: | public | function | @covers ::getId | |
| CreditCardTypeTest:: | public | function | @covers ::getLabel | |
| CreditCardTypeTest:: | public | function | @covers ::getNumberLengths | |
| CreditCardTypeTest:: | public | function | @covers ::getNumberPrefixes | |
| CreditCardTypeTest:: | public | function | @covers ::getSecurityCodeLength | |
| CreditCardTypeTest:: | public | function | Tests the creation of a CreditCardType with an invalid definition. | |
| CreditCardTypeTest:: | public | function | @covers ::usesLuhn | |
| PhpunitCompatibilityTrait:: | public | function | Returns a mock object for the specified class using the available method. | |
| PhpunitCompatibilityTrait:: | public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
| UnitTestCase:: | protected | property | The random generator. | |
| UnitTestCase:: | protected | property | The app root. | 1 | 
| UnitTestCase:: | protected | function | Asserts if two arrays are equal by sorting them first. | |
| UnitTestCase:: | protected | function | Mocks a block with a block plugin. | 1 | 
| UnitTestCase:: | protected | function | Returns a stub class resolver. | |
| UnitTestCase:: | public | function | Returns a stub config factory that behaves according to the passed array. | |
| UnitTestCase:: | public | function | Returns a stub config storage that returns the supplied configuration. | |
| UnitTestCase:: | protected | function | Sets up a container with a cache tags invalidator. | |
| UnitTestCase:: | protected | function | Gets the random generator for the utility methods. | |
| UnitTestCase:: | public | function | Returns a stub translation manager that just returns the passed string. | |
| UnitTestCase:: | public | function | Generates a unique random string containing letters and numbers. | 
