shouldBeCalledTimes example



  /** * Tests the getTranslationFromContext() method. * * @covers ::getTranslationFromContext */
  public function testGetTranslationFromContext() {
    $language = new Language(['id' => 'en']);
    $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
      ->willReturn($language)
      ->shouldBeCalledTimes(1);
    $this->languageManager->getFallbackCandidates(Argument::type('array'))
      ->will(function D$args) {
        $context = $args[0];
        $candidates = [];
        if (!empty($context['langcode'])) {
          $candidates[$context['langcode']] = $context['langcode'];
        }
        return $candidates;
      })
      ->shouldBeCalledTimes(1);

    
/** * Sets up a mock pager on the view executable object. * * @param int $items_per_page * The value to return from getItemsPerPage(). */
  protected function setupViewPager($items_per_page = 0) {
    $pager = $this->prophesize(PagerPluginBase::class);
    $pager->getItemsPerPage()
      ->willReturn($items_per_page)
      ->shouldBeCalledTimes(1);
    $pager->getCurrentPage()
      ->willReturn(0)
      ->shouldBeCalledTimes(1);

    $this->view->pager = $pager->reveal();
    $this->view->style_plugin = new \stdClass();
    $this->view->total_rows = 100;
    $this->view->result = [1, 2, 3, 4, 5];
  }

}
'status' => TRUE,
      ])
      ->shouldBeCalled();
    $config_object->save(FALSE)->shouldBeCalled();
    $config_object->get()->willReturn([]);

    $this->cacheTagsInvalidator->invalidateTags([$this->entityTypeId . '_list'])
      ->shouldBeCalled();

    $this->configFactory->loadMultiple(['the_provider.the_config_prefix.foo'])
      ->willReturn([])
      ->shouldBeCalledTimes(2);
    $this->configFactory
      ->get('the_provider.the_config_prefix.foo')
      ->willReturn($immutable_config_object->reveal())
      ->shouldBeCalledTimes(1);
    $this->configFactory
      ->getEditable('the_provider.the_config_prefix.foo')
      ->willReturn($config_object->reveal())
      ->shouldBeCalledTimes(1);

    $this->moduleHandler->invokeAll('test_entity_type_presave', [$entity])
      ->shouldBeCalled();
    
/** * @covers ::getInstance */
  public function testGetInstance() {
    $options = [
      'foo' => 'F00',
      'bar' => 'bAr',
    ];
    $instance = new \stdClass();
    $mapper = $this->prophesize(MapperInterface::class);
    $mapper->getInstance($options)
      ->shouldBeCalledTimes(1)
      ->willReturn($instance);
    $manager = new StubPluginManagerBaseWithMapper($mapper->reveal());
    $this->assertEquals($instance$manager->getInstance($options));
  }

  /** * @covers ::getInstance */
  public function testGetInstanceWithoutMapperShouldThrowException() {
    $options = [
      'foo' => 'F00',
      
$bundles = [];
    $destination = new EntityTestDestination([], '', [],
      $this->migration->reveal(),
      $this->storage->reveal(),
      $bundles,
      $this->entityFieldManager->reveal(),
      $this->prophesize(FieldTypePluginManagerInterface::class)->reveal(),
      $this->prophesize(AccountSwitcherInterface::class)->reveal()
    );
    $entity = $this->prophesize(ContentEntityInterface::class);
    $entity->isValidationRequired()
      ->shouldBeCalledTimes(1);
    // Assert that save is called.     $entity->save()
      ->shouldBeCalledTimes(1);
    // Set an id for the entity     $entity->id()
      ->willReturn(5);
    $destination->setEntity($entity->reveal());
    // Ensure the id is saved entity id is returned from import.     $this->assertEquals([5]$destination->import(new Row()));
    // Assert that import set the rollback action.     $this->assertEquals(MigrateIdMapInterface::ROLLBACK_DELETE, $destination->rollbackAction());
  }
/** * @covers ::onFieldDefinitionCreate */
  public function testOnFieldDefinitionCreateNewField() {
    $field_definition = $this->prophesize(FieldDefinitionInterface::class);
    $field_definition->getTargetEntityTypeId()->willReturn('test_entity_type');
    $field_definition->getTargetBundle()->willReturn('test_bundle');
    $field_definition->getName()->willReturn('test_field');
    $field_definition->getType()->willReturn('test_type');

    $storage = $this->prophesize(DynamicallyFieldableEntityStorageInterface::class);
    $storage->onFieldDefinitionCreate($field_definition->reveal())->shouldBeCalledTimes(1);
    $this->entityTypeManager->getStorage('test_entity_type')->willReturn($storage->reveal());

    $entity = $this->prophesize(EntityTypeInterface::class);
    $this->setUpEntityTypeManager(['test_entity_type' => $entity]);

    // Set up the stored bundle field map.     $key_value_store = $this->prophesize(KeyValueStoreInterface::class);
    $this->keyValueFactory->get('entity.definitions.bundle_field_map')->willReturn($key_value_store->reveal());
    $key_value_store->get('test_entity_type')->willReturn([]);
    $key_value_store->set('test_entity_type', [
      'test_field' => [
        
public function testSupportsNormalization() {
    $this->assertTrue($this->normalizer->supportsNormalization($this->list));
    $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
  }

  /** * Tests the normalize() method. */
  public function testNormalize() {
    $serializer = $this->prophesize(Serializer::class);
    $serializer->normalize($this->typedData, 'json', ['mu' => 'nu'])
      ->shouldBeCalledTimes(3)
      ->willReturn('test');

    $this->normalizer->setSerializer($serializer->reveal());

    $normalized = $this->normalizer->normalize($this->list, 'json', ['mu' => 'nu']);

    $this->assertEquals($this->expectedListValues, $normalized);
  }

}
$date_sql->setFieldTimezoneOffset($field, 42);
    $this->assertEquals("(foobar.field + INTERVAL '42 SECONDS')", $field);
  }

  /** * Tests setting the database offset. * * @covers ::setTimezoneOffset */
  public function testSetTimezoneOffset() {
    $database = $this->prophesize(Connection::class);
    $database->query("SET TIME ZONE INTERVAL '42' HOUR TO MINUTE")->shouldBeCalledTimes(1);
    $date_sql = new PostgresqlDateSql($database->reveal());
    $date_sql->setTimezoneOffset(42);
  }

}
/** * Tests logging a message. * * @covers ::__construct * @covers ::logMessage */
  public function testLogMessage() {
    $migration = $this->prophesize('\Drupal\migrate\Plugin\MigrationInterface');
    $message_service = $this->prophesize('\Drupal\migrate\MigrateMessageInterface');
    $event = new MigrateImportEvent($migration->reveal()$message_service->reveal());
    // Assert that the intended calls to the services happen.     $message_service->display('status message', 'status')->shouldBeCalledTimes(1);
    $event->logMessage('status message');
    $message_service->display('warning message', 'warning')->shouldBeCalledTimes(1);
    $event->logMessage('warning message', 'warning');
  }

}

  }

  /** * @covers ::minimumVersion * @covers ::name * @dataProvider providerNameAndMinimumVersion */
  public function testNameAndMinimumVersion(bool $is_mariadb, string $expected_name, string $expected_minimum_version): void {
    $this->connection
      ->isMariaDb()
      ->shouldBeCalledTimes(2)
      ->willReturn($is_mariadb);
    $tasks = $this->createTasks();

    $minimum_version = $tasks->minimumVersion();
    $name = $tasks->name();

    $this->assertSame($expected_minimum_version$minimum_version);
    $this->assertSame($expected_name$name);

  }

  
$date_sql->setFieldTimezoneOffset($field, 42);
    $this->assertEquals("(foobar.field + INTERVAL 42 SECOND)", $field);
  }

  /** * Tests setting the database offset. * * @covers ::setTimezoneOffset */
  public function testSetTimezoneOffset() {
    $database = $this->prophesize(Connection::class);
    $database->query("SET @@session.time_zone = '42'")->shouldBeCalledTimes(1);
    $date_sql = new MysqlDateSql($database->reveal());
    $date_sql->setTimezoneOffset(42);
  }

}
/** * Tests logging a message. * * @covers ::__construct * @covers ::logMessage */
  public function testLogMessage() {
    $migration = $this->prophesize('\Drupal\migrate\Plugin\MigrationInterface')->reveal();
    $message_service = $this->prophesize('\Drupal\migrate\MigrateMessageInterface');
    $event = new EventBase($migration$message_service->reveal());
    // Assert that the intended calls to the services happen.     $message_service->display('status message', 'status')->shouldBeCalledTimes(1);
    $event->logMessage('status message');
    $message_service->display('warning message', 'warning')->shouldBeCalledTimes(1);
    $event->logMessage('warning message', 'warning');
  }

}
$this->assertEquals(['theme_d_post_update_b', 'theme_d_post_update_c']array_values($update_registry->getUpdateFunctions('theme_d')));
  }

  /** * @covers ::registerInvokedUpdates */
  public function testRegisterInvokedUpdatesWithoutExistingUpdates() {
    $this->setupBasicExtensions();
    $key_value = $this->prophesize(KeyValueStoreInterface::class);
    $key_value->get('existing_updates', [])
      ->willReturn([])
      ->shouldBeCalledTimes(1);
    $key_value->set('existing_updates', ['module_a_post_update_a'])
      ->willReturn(NULL)
      ->shouldBeCalledTimes(1);
    $key_value = $key_value->reveal();

    $update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
      'module_a',
      'module_b',
      'theme_d',
    ]$key_value, FALSE);
    $update_registry->registerInvokedUpdates(['module_a_post_update_a']);
  }
/** * @covers ::getValue */
  public function testGetValue() {
    $entity = $this->prophesize(FileInterface::class);
    $entity->getFileUri()
      ->willReturn($this->testUrl);

    $parent = $this->prophesize(FieldItemInterface::class);
    $parent->getEntity()
      ->shouldBeCalledTimes(2)
      ->willReturn($entity->reveal());

    $definition = $this->prophesize(DataDefinitionInterface::class);

    $typed_data = new ComputedFileUrl($definition->reveal()$this->randomMachineName()$parent->reveal());

    $expected = base_path() . $this->siteDirectory . '/files/druplicon.txt';

    $this->assertSame($expected$typed_data->getValue());
    // Do this a second time to confirm the same value is returned but the value     // isn't retrieved from the parent entity again.

  public function testPathHooks() {
    $path_alias = PathAlias::create([
      'path' => '/' . $this->randomMachineName(),
      'alias' => '/' . $this->randomMachineName(),
    ]);

    // Check \Drupal\path_alias\Entity\PathAlias::postSave() for new path alias     // entities.     $alias_manager = $this->prophesize(AliasManagerInterface::class);
    $alias_manager->cacheClear(Argument::any())->shouldBeCalledTimes(1);
    $alias_manager->cacheClear($path_alias->getPath())->shouldBeCalledTimes(1);
    \Drupal::getContainer()->set('path_alias.manager', $alias_manager->reveal());
    $path_alias->save();

    $new_source = '/' . $this->randomMachineName();

    // Check \Drupal\path_alias\Entity\PathAlias::postSave() for existing path     // alias entities.     $alias_manager = $this->prophesize(AliasManagerInterface::class);
    $alias_manager->cacheClear(Argument::any())->shouldBeCalledTimes(2);
    $alias_manager->cacheClear($path_alias->getPath())->shouldBeCalledTimes(1);
    
Home | Imprint | This part of the site doesn't use cookies.