class ConfigSnapshotConfigEntityUnitTest in Config Snapshot 8
@coversDefaultClass \Drupal\config_snapshot\Entity\ConfigSnapshot @group config_snapshot
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\config_snapshot\Unit\ConfigSnapshotConfigEntityUnitTest
Expanded class hierarchy of ConfigSnapshotConfigEntityUnitTest
File
- tests/
src/ Unit/ ConfigSnapshotConfigEntityUnitTest.php, line 16
Namespace
Drupal\Tests\config_snapshot\UnitView source
class ConfigSnapshotConfigEntityUnitTest extends UnitTestCase {
/**
* The configuration snapshot entity.
*
* @var \Drupal\config_snapshot\Entity\ConfigSnapshot
*/
protected $entity;
/**
* The entity type used for testing.
*
* @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityType;
/**
* The entity manager used for testing.
*
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
/**
* The entity type manager used for testing.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityTypeManager;
/**
* The UUID generator used for testing.
*
* @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $uuid;
/**
* The extension name used for testing.
*
* @var string
*/
protected $extensionName;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->entityType = $this
->createMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$this->entityType
->expects($this
->any())
->method('getProvider')
->will($this
->returnValue('entity'));
$this->entityManager = new EntityManager();
$this->entityTypeManager = $this
->createMock(EntityTypeManagerInterface::class);
$this->uuid = $this
->createMock('\\Drupal\\Component\\Uuid\\UuidInterface');
$container = new ContainerBuilder();
$container
->set('entity.manager', $this->entityManager);
$container
->set('entity_type.manager', $this->entityTypeManager);
$container
->set('uuid', $this->uuid);
$this->entityManager
->setContainer($container);
\Drupal::setContainer($container);
$snapshot_set = $this
->randomMachineName(8);
$extension_type = 'module';
$this->extensionName = $this
->randomMachineName(8);
$values = [
'snapshotSet' => $snapshot_set,
'extensionType' => $extension_type,
'extensionName' => $this->extensionName,
];
$this->entity = new ConfigSnapshot($values, 'config_snapshot.snapshot');
}
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependencies() {
$this->entityTypeManager
->expects($this
->any())
->method('getDefinition')
->will($this
->returnValue($this->entityType));
$dependencies = $this->entity
->calculateDependencies()
->getDependencies();
$this
->assertArrayNotHasKey('config', $dependencies);
$this
->assertContains($this->extensionName, $dependencies['module']);
}
/**
* @covers ::clearItem
* @covers ::getItem
* @covers ::getItems
* @covers ::setItem
*/
public function testItems() {
$expected_item = [
'collection' => StorageInterface::DEFAULT_COLLECTION,
'name' => 'example',
'data' => [
'something' => 'some_value',
],
];
// Set a new item.
$this->entity
->setItem($expected_item['collection'], $expected_item['name'], $expected_item['data']);
$items = $this->entity
->getItems();
$this
->assertEquals(1, count($items));
$this
->assertEquals($expected_item, $items[0]);
$item = $this->entity
->getItem($expected_item['collection'], $expected_item['name']);
$this
->assertEquals($expected_item, $item);
// Reset an existing item.
$expected_new_data = [
'something_else' => 'some_new_value',
];
$this->entity
->setItem($expected_item['collection'], $expected_item['name'], $expected_new_data);
$item = $this->entity
->getItem($expected_item['collection'], $expected_item['name']);
$this
->assertEquals($expected_new_data, $item['data']);
// Clear an item.
$this->entity
->clearItem($expected_item['collection'], $expected_item['name']);
$item = $this->entity
->getItem($expected_item['collection'], $expected_item['name']);
$this
->assertNull($item);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigSnapshotConfigEntityUnitTest:: |
protected | property | The configuration snapshot entity. | |
ConfigSnapshotConfigEntityUnitTest:: |
protected | property | The entity manager used for testing. | |
ConfigSnapshotConfigEntityUnitTest:: |
protected | property | The entity type used for testing. | |
ConfigSnapshotConfigEntityUnitTest:: |
protected | property | The entity type manager used for testing. | |
ConfigSnapshotConfigEntityUnitTest:: |
protected | property | The extension name used for testing. | |
ConfigSnapshotConfigEntityUnitTest:: |
protected | property | The UUID generator used for testing. | |
ConfigSnapshotConfigEntityUnitTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ConfigSnapshotConfigEntityUnitTest:: |
public | function | @covers ::calculateDependencies | |
ConfigSnapshotConfigEntityUnitTest:: |
public | function | @covers ::clearItem @covers ::getItem @covers ::getItems @covers ::setItem | |
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. |