NullBackend example

$config_factory = $this->getConfigFactoryStub([
      'core.extension' => [
        'module' => [],
        'theme' => [],
        'disabled' => [
          'theme' => [],
        ],
        'theme_engine' => '',
      ],
    ]);

    $theme_engine_list = new TestThemeEngineExtensionList($this->root, 'theme_engine', new NullBackend('test')$info_parser->reveal()$module_handler->reveal()$state$config_factory);
    $theme_engine_list->setExtensionDiscovery($extension_discovery->reveal());

    $theme_list = new TestThemeExtensionList($this->root, 'theme', new NullBackend('test')$info_parser->reveal()$module_handler->reveal()$state$config_factory$theme_engine_list, 'testing');
    $theme_list->setExtensionDiscovery($extension_discovery->reveal());

    $theme_data = $theme_list->reset()->getList();
    $this->assertCount(2, $theme_data);

    $info_basetheme = $theme_data['test_basetheme'];
    $info_subtheme = $theme_data['test_subtheme'];

    

  protected function setUp(): void {
    parent::setUp();

    $this->contextHandler = new ContextHandler();

    $namespaces = new \ArrayObject([
      'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData',
      'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation',
    ]);
    $cache_backend = new NullBackend('cache');
    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    $class_resolver = $this->prophesize(ClassResolverInterface::class);
    $class_resolver->getInstanceFromDefinition(Argument::type('string'))->will(function D$arguments) {
      $class_name = $arguments[0];
      return new $class_name();
    });
    $type_data_manager = new TypedDataManager($namespaces$cache_backend$module_handler->reveal()$class_resolver->reveal());
    $type_data_manager->setValidationConstraintManager(
      new ConstraintManager($namespaces$cache_backend$module_handler->reveal())
    );

    
/** * Tests the cache NullBackend. * * @group Cache */
class NullBackendTest extends UnitTestCase {

  /** * Tests that the NullBackend does not actually store variables. */
  public function testNullBackend() {
    $null_cache = new NullBackend('test');

    $key = $this->randomMachineName();
    $value = $this->randomMachineName();

    $null_cache->set($key$value);
    $this->assertFalse($null_cache->get($key));
  }

}

  public function testListAllStaticCache() {
    $prefix = __FUNCTION__;
    $storage = $this->createMock('Drupal\Core\Config\StorageInterface');

    $response = ["$prefix." . $this->randomMachineName(), "$prefix." . $this->randomMachineName()];
    $storage->expects($this->once())
      ->method('listAll')
      ->with($prefix)
      ->willReturn($response);

    $cache = new NullBackend(__FUNCTION__);

    $cachedStorage = new CachedStorage($storage$cache);
    $this->assertEquals($response$cachedStorage->listAll($prefix));
    $this->assertEquals($response$cachedStorage->listAll($prefix));
  }

}

    $response = new Response(200, $headers$body);

    $client = $this->prophesize(Client::class);
    $client->request('GET', $url[RequestOptions::TIMEOUT => 5])
      ->shouldBeCalled()
      ->willReturn($response);

    $fetcher = new ResourceFetcher(
      $client->reveal(),
      $this->createMock('\Drupal\media\OEmbed\ProviderRepositoryInterface'),
      new NullBackend('default')
    );
    $fetcher->fetchResource($url);
  }

  /** * Tests how the resource fetcher handles unknown Content-Type headers. * * @covers ::fetchResource */
  public function testUnknownContentTypeHeader(): void {
    $headers = [
      
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $namespaces = new \ArrayObject([
      'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData',
      'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation',
      'Drupal\\Tests\\Core\\Plugin\\Fixtures' => $this->root . '/core/tests/Drupal/Tests/Core/Plugin/Fixtures',
    ]);
    $cache_backend = new NullBackend('cache');
    $module_handler = $this->prophesize(ModuleHandlerInterface::class);

    $class_resolver = $this->prophesize(ClassResolverInterface::class);
    $class_resolver->getInstanceFromDefinition(Argument::type('string'))->will(function D$arguments) {
      $class_name = $arguments[0];
      return new $class_name();
    });

    $type_data_manager = new TypedDataManager($namespaces$cache_backend$module_handler->reveal()$class_resolver->reveal());
    $type_data_manager->setValidationConstraintManager(new ConstraintManager($namespaces$cache_backend$module_handler->reveal()));

    
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $namespaces = new \ArrayObject([
      'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData',
      'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation',
      'Drupal\\Core\\Entity' => $this->root . '/core/lib/Drupal/Core/Entity',
    ]);
    $cache_backend = new NullBackend('cache');
    $module_handler = $this->prophesize(ModuleHandlerInterface::class);

    $class_resolver = $this->prophesize(ClassResolverInterface::class);
    $class_resolver->getInstanceFromDefinition(Argument::type('string'))->will(function D$arguments) {
      $class_name = $arguments[0];
      return new $class_name();
    });

    $type_data_manager = new TypedDataManager($namespaces$cache_backend$module_handler->reveal()$class_resolver->reveal());
    $type_data_manager->setValidationConstraintManager(new ConstraintManager($namespaces$cache_backend$module_handler->reveal()));

    
<?php
namespace Drupal\Core\Cache;

class NullBackendFactory implements CacheFactoryInterface {

  /** * {@inheritdoc} */
  public function get($bin) {
    return new NullBackend($bin);
  }

}

  protected $contextFactory;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $cache_backend = new NullBackend('cache');
    $namespaces = new \ArrayObject([
      'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData',
      'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation',
    ]);
    $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandlerInterface')
      ->disableOriginalConstructor()
      ->getMock();
    $class_resolver = $this->getMockBuilder('Drupal\Core\DependencyInjection\ClassResolverInterface')
      ->disableOriginalConstructor()
      ->getMock();

    
Home | Imprint | This part of the site doesn't use cookies.