KeyValueMemoryFactory example


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

    $config_factory = $this->getConfigFactoryStub([
      'media.settings' => [
        'oembed_providers_url' => 'https://oembed.com/providers.json',
      ],
    ]);

    $key_value_factory = new KeyValueMemoryFactory();
    $this->keyValue = $key_value_factory->get('media');

    $this->currentTime = time();
    $time = $this->prophesize('\Drupal\Component\Datetime\TimeInterface');
    $time->getCurrentTime()->willReturn($this->currentTime);

    $this->logger = $this->prophesize('\Psr\Log\LoggerInterface');
    $logger_factory = new LoggerChannelFactory();
    $logger_factory->addLogger($this->logger->reveal());

    $this->responses = new MockHandler();
    

  protected TestLogger $logger;

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

    $this->fixtures = new RoutingFixtures();
    $this->state = new State(new KeyValueMemoryFactory());
    $this->logger = new TestLogger();
  }

  /** * Confirms that the dumper can be instantiated successfully. */
  public function testCreate() {
    $connection = Database::getConnection();
    $dumper = new MatcherDumper($connection$this->state, $this->logger);

    $class_name = 'Drupal\Core\Routing\MatcherDumper';
    

  protected TestLogger $logger;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->fixtures = new RoutingFixtures();
    $this->state = new State(new KeyValueMemoryFactory());
    $this->currentPath = new CurrentPathStack(new RequestStack());
    $this->cache = new MemoryBackend();
    $this->pathProcessor = \Drupal::service('path_processor_manager');
    $this->cacheTagsInvalidator = \Drupal::service('cache_tags.invalidator');
    $this->installEntitySchema('path_alias');

    $this->logger = new TestLogger();
  }

  /** * {@inheritdoc} */

  protected $state;

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

    // Construct a state object used for testing logger assertions.     $this->state = new State(new KeyValueMemoryFactory());

    // Create a mock logger to set a flag in the resulting state.     $logger = $this->prophesize('Drupal\Core\Logger\LoggerChannelInterface');
    // Safely ignore the cron success message.     $logger->info('Cron run completed.')->shouldBeCalled();
    // Set a flag to track when a message is logged by adding a callback     // function for each logging method.     foreach (get_class_methods(LoggerInterface::class) as $logger_method) {
      $logger->{$logger_method}(Argument::cetera())->will(function D) {
        \Drupal::state()->set('cron_test.message_logged', TRUE);
      });
    }
return $info_parser->parse($root . '/' . $file[0]);
      });

    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    $module_handler
      ->buildModuleDependencies(Argument::type('array'))
      ->willReturnArgument(0);
    $module_handler
      ->alter('system_info', Argument::type('array'), Argument::type(Extension::class), Argument::any())
      ->shouldBeCalled();

    $state = new State(new KeyValueMemoryFactory());

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

    
->register('flood', 'Drupal\Core\Flood\MemoryBackend')
      ->addArgument(new Reference('request_stack'));
    $container
      ->register('lock', 'Drupal\Core\Lock\NullLockBackend');
    $container
      ->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory');

    // Use memory for key value storages to avoid database queries. Store the     // key value factory on the test object so that key value storages persist     // container rebuilds, otherwise all state data would vanish.     if (!isset($this->keyValue)) {
      $this->keyValue = new KeyValueMemoryFactory();
    }
    $container->set('keyvalue', $this->keyValue);

    // Set the default language on the minimal container.     $container->setParameter('language.default_values', Language::$defaultValues);

    if ($this->strictConfigSchema) {
      $container
        ->register('testing.config_schema_checker', ConfigSchemaChecker::class)
        ->addArgument(new Reference('config.typed'))
        ->addArgument($this->getConfigSchemaExclusions())
        
/** * Tests bubbling of bubbleable metadata added by #pre_render callbacks. * * @dataProvider providerTestBubblingWithPrerender */
  public function testBubblingWithPrerender($test_element) {
    $this->setUpRequest();
    $this->setupMemoryCache();

    // Mock the State service.     $memory_state = new State(new KeyValueMemoryFactory());
    \Drupal::getContainer()->set('state', $memory_state);
    $this->controllerResolver->expects($this->any())
      ->method('getControllerFromDefinition')
      ->willReturnArgument(0);

    // Simulate the theme system/Twig: a recursive call to Renderer::render(),     // just like the theme system or a Twig template would have done.     $this->themeManager->expects($this->any())
      ->method('render')
      ->willReturnCallback(function D$hook$vars) {
        return $this->renderer->render($vars['foo']);
      });
Home | Imprint | This part of the site doesn't use cookies.