Skip to content
Snippets Groups Projects

Issue #3504644 by tr: Fix StorageFactoryTest failures

@@ -9,7 +9,8 @@ use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\DependencyInjection\ClassResolverInterface;
use Drupal\radioactivity\DefaultIncidentStorage;
use Drupal\radioactivity\RestIncidentStorage;
use Drupal\radioactivity\IncidentStorageInterface;
use Drupal\radioactivity\RestIncidentStorageInterface;
use Drupal\radioactivity\StorageFactory;
/**
@@ -18,6 +19,13 @@ use Drupal\radioactivity\StorageFactory;
*/
class StorageFactoryTest extends UnitTestCase {
/**
* Instance of StorageFactory for testing.
*
* @var \Drupal\radioactivity\StorageFactory
*/
protected $storageFactory;
/**
* Mocked immutable configuration object.
*
@@ -54,7 +62,7 @@ class StorageFactoryTest extends UnitTestCase {
->willReturn($this->config);
// Mock the class resolver and the classes it provides.
$mockRestStorage = $this->createMock(RestIncidentStorage::class);
$mockRestStorage = $this->createMock(RestIncidentStorageInterface::class);
$mockDefaultStorage = $this->createMock(DefaultIncidentStorage::class);
$this->classResolver = $this->createMock(ClassResolverInterface::class);
@@ -65,6 +73,8 @@ class StorageFactoryTest extends UnitTestCase {
['radioactivity.default_incident_storage', $mockDefaultStorage],
]);
// Create concrete StorageFactory with mocked services.
$this->storageFactory = new StorageFactory($this->configFactory, $this->classResolver);
}
/**
@@ -72,14 +82,8 @@ class StorageFactoryTest extends UnitTestCase {
* @dataProvider providerGet
*/
public function testGet(string $storageType, string $storageClass): void {
$sut = $this->getMockBuilder(StorageFactory::class)
->setConstructorArgs([
$this->configFactory,
$this->classResolver,
])
->getMock();
$result = $sut->get($storageType);
$result = $this->storageFactory->get($storageType);
$this->assertInstanceOf(IncidentStorageInterface::class, $result);
$this->assertInstanceOf($storageClass, $result);
}
@@ -90,9 +94,12 @@ class StorageFactoryTest extends UnitTestCase {
* Storage type, storage class.
*/
public static function providerGet(): array {
// Format of each element is:
// - storageType: A string storage type.
// - storageClass: A string holding a fully qualified class name.
return [
['rest_local', RestIncidentStorage::class],
['rest_remote', RestIncidentStorage::class],
['rest_local', RestIncidentStorageInterface::class],
['rest_remote', RestIncidentStorageInterface::class],
['default', DefaultIncidentStorage::class],
['unknown_type', DefaultIncidentStorage::class],
];
@@ -120,12 +127,15 @@ class StorageFactoryTest extends UnitTestCase {
}
/**
* Data provider for testGet.
* Data provider for testGetConfiguredStorage.
*
* @return array
* Configured type, storage type.
*/
public static function providerGetConfiguredStorage(): array {
// Format of each element is:
// - configType: A string configuration type.
// - storageType: A string storage type.
return [
['rest_local', 'rest_local'],
['rest_remote', 'rest_remote'],
@@ -139,10 +149,10 @@ class StorageFactoryTest extends UnitTestCase {
*
* @param string $storageType
* The configured storage type.
* @param mixed $endpoint
* @param string $endpoint
* The configured endpoint.
*/
protected function setConfig(?string $storageType, $endpoint): void {
protected function setConfig(?string $storageType, ?string $endpoint): void {
$this->config->expects($this->any())
->method('get')
->willReturnMap([
Loading