abstract class KeyTestBase in Key 8
Provides a base class for key tests.
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait- class \Drupal\Tests\key\Unit\KeyTestBase
 
Expanded class hierarchy of KeyTestBase
1 file declares its use of KeyTestBase
- KeyEntityTest.php in tests/src/ Unit/ Entity/ KeyEntityTest.php 
File
- tests/src/ Unit/ KeyTestBase.php, line 12 
Namespace
Drupal\Tests\key\UnitView source
abstract class KeyTestBase extends UnitTestCase {
  /**
   * Config.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $config;
  /**
   * Configuration storage.
   *
   * @var \Drupal\Core\Config\Entity\ConfigEntityStorage
   */
  protected $configStorage;
  /**
   * Entity type manager instance.
   *
   * @var \Drupal\Core\Entity\EntityTypeManager
   */
  protected $entityTypeManager;
  /**
   * Container builder.
   *
   * This should be used sparingly by test cases to add to the container as
   * necessary for tests.
   *
   * @var \Drupal\Core\DependencyInjection\ContainerBuilder
   */
  protected $container;
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    // Mock the Config object, but methods will be mocked in the test class.
    $this->config = $this
      ->getMockBuilder('\\Drupal\\Core\\Config\\ImmutableConfig')
      ->disableOriginalConstructor()
      ->getMock();
    // Mock ConfigEntityStorage object, but methods will be mocked in the test
    // class.
    $this->configStorage = $this
      ->getMockBuilder('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')
      ->disableOriginalConstructor()
      ->getMock();
    // Mock EntityTypeManager service.
    $this->entityTypeManager = $this
      ->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')
      ->disableOriginalConstructor()
      ->getMock();
    $this->entityTypeManager
      ->expects($this
      ->any())
      ->method('getStorage')
      ->with('key')
      ->willReturn($this->configStorage);
    // Create a dummy container.
    $this->container = new ContainerBuilder();
    $this->container
      ->set('entity_type.manager', $this->entityTypeManager);
    // Each test class should call \Drupal::setContainer() in its own setUp
    // method so that test classes can add mocked services to the container
    // without affecting other test classes.
  }
  /**
   * Return a token that could be a key.
   *
   * @return string
   *   A hashed string that could be confused as some secret token.
   */
  protected function createToken() {
    return strtoupper(hash('ripemd128', Crypt::hashBase64($this
      ->getRandomGenerator()
      ->string(30))));
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| KeyTestBase:: | protected | property | Config. | |
| KeyTestBase:: | protected | property | Configuration storage. | |
| KeyTestBase:: | protected | property | Container builder. | |
| KeyTestBase:: | protected | property | Entity type manager instance. | |
| KeyTestBase:: | protected | function | Return a token that could be a key. | |
| KeyTestBase:: | protected | function | Overrides UnitTestCase:: | 1 | 
| 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. | 
