shouldBeCalledOnce example


  protected function setUp(): void {
    parent::setUp();
    $state = $this->prophesize(StateInterface::class);
    $file_url_generator = $this->createMock(FileUrlGeneratorInterface::class);
    $file_url_generator->expects($this->any())
      ->method('generateString')
      ->with($this->isType('string'))
      ->willReturnCallback(function D$uri) {
         return 'generated-relative-url:' . $uri;
      });
    $state->get('system.css_js_query_string', '0')->shouldBeCalledOnce()->willReturn(NULL);
    $this->renderer = new CssCollectionRenderer($state->reveal()$file_url_generator);
    $this->fileCssGroup = [
      'group' => -100,
      'type' => 'file',
      'media' => 'all',
      'preprocess' => TRUE,
      'items' => [
        0 => [
          'group' => -100,
          'type' => 'file',
          'weight' => 0.012,
          
->method('getClass')
      ->willReturn(get_class($entity));
    $this->entityType->expects($this->atLeastOnce())
      ->method('getKeys')
      ->willReturn(['id' => 'id']);

    // ContentEntityStorageBase iterates over the entity which calls this method     // internally in ContentEntityBase::getProperties().     $this->entityFieldManager
      ->getFieldDefinitions(Argument::type('string'), Argument::type('string'))
      ->willReturn([])
      ->shouldBeCalledOnce();

    $this->entityType->expects($this->atLeastOnce())
      ->method('isRevisionable')
      ->willReturn(FALSE);
    $this->entityTypeManager
      ->getDefinition($this->entityType->id())
      ->willReturn($this->entityType)
      ->shouldBeCalled();

    $this->setUpEntityStorage();

    
$this->assertNull($redirect);
  }

  /** * @covers ::executeSubmitHandlers */
  public function testExecuteSubmitHandlers() {
    $form_submitter = $this->getFormSubmitter();
    $mock = $this->prophesize(MockFormBase::class);
    $mock
      ->hash_submit(Argument::type('array'), Argument::type(FormStateInterface::class))
      ->shouldBeCalledOnce();
    $mock
      ->submit_handler(Argument::type('array'), Argument::type(FormStateInterface::class))
      ->shouldBeCalledOnce();
    $mock
      ->simple_string_submit(Argument::type('array'), Argument::type(FormStateInterface::class))
      ->shouldBeCalledOnce();

    $form = [];
    $form_state = new FormState();
    $form_submitter->executeSubmitHandlers($form$form_state);

    


    $constraint = new OEmbedResourceConstraint();

    $context = $this->prophesize(ExecutionContextInterface::class);

    $provider = $this->prophesize(Provider::class);
    $provider->getName()->willReturn('YouTube');

    $url_resolver = $this->prophesize(UrlResolverInterface::class);
    $url_resolver->getProviderByUrl(Argument::any())->willReturn($provider->reveal());
    $url_resolver->getResourceUrl(Argument::any())->shouldBeCalledOnce();

    $validator = new OEmbedResourceConstraintValidator(
      $url_resolver->reveal(),
      $this->prophesize(ResourceFetcher::class)->reveal(),
      $this->container->get('logger.factory')
    );
    $validator->initialize($context->reveal());
    $validator->validate($this->getValue($media)$constraint);
  }

  /** * Wraps a media entity in an anonymous class to mock a field value. * * @param \Drupal\media\Entity\Media $media * The media object. * * @return object * The mock field value to validate. */
Home | Imprint | This part of the site doesn't use cookies.