You are here

class PaymentStorageSchemaTest in Payment 8.2

@coversDefaultClass \Drupal\payment\Entity\Payment\PaymentStorageSchema

@group Payment

Hierarchy

Expanded class hierarchy of PaymentStorageSchemaTest

File

tests/src/Unit/Entity/Payment/PaymentStorageSchemaTest.php, line 21

Namespace

Drupal\Tests\payment\Unit\Entity\Payment
View source
class PaymentStorageSchemaTest extends UnitTestCase {

  /**
   * The database connection.
   *
   * @var \Drupal\Core\Database\Connection|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $database;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $entityTypeManager;

  /**
   * The entity field manager.
   *
   * @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $entityFieldManager;

  /**
   * The entity type.
   *
   * @var \Drupal\Core\Entity\ContentEntityTypeInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $entityType;

  /**
   * The storage field definitions.
   *
   * @var \Drupal\Core\Field\FieldDefinitionInterface|\PHPUnit\Framework\MockObject\MockObject[]
   */
  protected $fieldStorageDefinitions;

  /**
   * The storage handler.
   *
   * @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $storage;

  /**
   * The class under test.
   *
   * @var \Drupal\payment\Entity\Payment\PaymentStorageSchema
   */
  protected $sut;

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    $entity_type_id_key = $this
      ->randomMachineName();
    $entity_type_id = $this
      ->randomMachineName();
    $this->database = $this
      ->getMockBuilder(Connection::class)
      ->disableOriginalConstructor()
      ->getMock();
    $this->fieldStorageDefinitions = array(
      $entity_type_id_key => $this
        ->createMock(FieldDefinitionInterface::class),
    );
    $this->entityTypeManager = $this
      ->getMockBuilder(EntityTypeManager::class)
      ->disableOriginalConstructor()
      ->getMock();
    $this->entityFieldManager = $this
      ->getMockBuilder(EntityFieldManager::class)
      ->disableOriginalConstructor()
      ->getMock();
    $this->entityFieldManager
      ->expects($this
      ->atLeastOnce())
      ->method('getActiveFieldStorageDefinitions')
      ->with($entity_type_id)
      ->willReturn($this->fieldStorageDefinitions);
    $this->entityType = $this
      ->createMock(ContentEntityTypeInterface::class);
    $this->entityType
      ->expects($this
      ->atLeastOnce())
      ->method('id')
      ->willReturn($entity_type_id);
    $this->entityTypeManager
      ->expects($this
      ->atLeastOnce())
      ->method('getActiveDefinition')
      ->with($entity_type_id)
      ->willReturn($this->entityType);
    $this->storage = $this
      ->getMockBuilder(SqlContentEntityStorage::class)
      ->disableOriginalConstructor()
      ->getMock();
    $this->sut = new PaymentStorageSchema($this->entityTypeManager, $this->entityType, $this->storage, $this->database, $this->entityFieldManager);
  }

  /**
   * @covers ::alterEntitySchemaWithNonFieldColumns
   */
  public function testAlterEntitySchemaWithNonFieldColumns() {
    $schema = array(
      'payment' => array(
        'fields' => [],
        'foreign keys' => [],
      ),
    );
    $method = new \ReflectionMethod($this->sut, 'alterEntitySchemaWithNonFieldColumns');
    $method
      ->setAccessible(TRUE);
    $method
      ->invokeArgs($this->sut, array(
      &$schema,
    ));
    $this
      ->assertIsArray($schema);
    $this
      ->assertArrayHasKey('payment', $schema);
    $this
      ->assertIsArray($schema['payment']);
    $this
      ->assertArrayHasKey('fields', $schema['payment']);
    foreach ($schema['payment']['fields'] as $field) {
      $this
        ->assertIsArray($field);
      $this
        ->assertArrayHasKey('type', $field);
    }
    $this
      ->assertArrayHasKey('foreign keys', $schema['payment']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PaymentStorageSchemaTest::$database protected property The database connection.
PaymentStorageSchemaTest::$entityFieldManager protected property The entity field manager.
PaymentStorageSchemaTest::$entityType protected property The entity type.
PaymentStorageSchemaTest::$entityTypeManager protected property The entity type manager.
PaymentStorageSchemaTest::$fieldStorageDefinitions protected property The storage field definitions.
PaymentStorageSchemaTest::$storage protected property The storage handler.
PaymentStorageSchemaTest::$sut protected property The class under test.
PaymentStorageSchemaTest::setUp public function Overrides UnitTestCase::setUp
PaymentStorageSchemaTest::testAlterEntitySchemaWithNonFieldColumns public function @covers ::alterEntitySchemaWithNonFieldColumns
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.