willThrow example

$this->fieldPlugin->$method($this->row->reveal())->willReturn($expected_value);
    }
    $plugin = new ProcessField(['method' => $method]$value[]$this->fieldManager->reveal()$this->migration->reveal());

    if ($migrate_exception) {
      $this->expectException(MigrateException::class);
      $this->expectExceptionMessage($migrate_exception);
    }

    if ($plugin_not_found) {
      $exception = new PluginNotFoundException('foo');
      $this->fieldManager->getPluginIdFromFieldType()->willThrow($exception);
    }

    $transformed_value = $plugin->transform($value$this->migrateExecutable->reveal()$this->row->reveal(), 'foo');
    $this->assertSame($transformed_value$expected_value);
  }

  /** * Provides data for the transform method test. * * @return array * - The method to call. * - The value to process. * - The expected transformed value. * - The MigrateException message to expect. * - Whether the field plugin is not found. */


    // Create a queue instance for this queue worker.     $this->queue = new Memory($queue_worker);
    $queue_factory->get($queue_worker)->willReturn($this->queue);

    // Create a mock queue worker plugin instance based on above definition.     $queue_worker_plugin = $this->prophesize('Drupal\Core\Queue\QueueWorkerInterface');
    $queue_worker_plugin->getPluginId()->willReturn($queue_worker);
    $queue_worker_plugin->getPluginDefinition()->willReturn($queue_worker_definition);
    $queue_worker_plugin->processItem('Complete')->willReturn();
    $queue_worker_plugin->processItem('Exception')->willThrow(\Exception::class);
    $queue_worker_plugin->processItem('DelayedRequeueException')->willThrow(DelayedRequeueException::class);
    $queue_worker_plugin->processItem('SuspendQueueException')->willThrow(SuspendQueueException::class);
    // 'RequeueException' would normally result in an infinite loop.     //     // This is avoided by throwing RequeueException for the first few calls to     // ::processItem() and then returning void. ::testRequeueException()     // establishes sanity assertions for this case.     $queue_worker_plugin->processItem('RequeueException')->will(function D$args$mock$method) {
      // Fetch the number of calls to this prophesied method. This value will       // start at zero during the first call.       $method_calls = count($mock->findProphecyMethodCalls($method->getMethodName()new ArgumentsWildcard($args)));

      
$this->assertSame($this->plugin->reveal()$result);
  }

  /** * @covers ::load */
  public function testLoadNull() {
    $contexts = [
      'the_context' => $this->prophesize(ContextInterface::class)->reveal(),
    ];

    $this->contextHandler->applyContextMapping($this->plugin, $contexts)->willThrow(new ContextException());

    $result = $this->manager->load('the_plugin_id', $contexts);
    $this->assertNull($result);
  }

  /** * @covers ::findDefinitions */
  public function testFindDefinitions() {
    $this->discovery->getDefinitions()->willReturn([
      'plugin1' => (new SectionStorageDefinition())->setClass(SectionStorageInterface::class),
      
$migration = $this->getMigration();
    $source = new StubSourcePlugin([], '', []$migration);
    $row = new Row();

    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    // Return a failure from a prepare row hook.     $module_handler->invokeAll('migrate_prepare_row', [$row$source$migration])
      ->willReturn([TRUE, TRUE])
      ->shouldBeCalled();
    $module_handler->invokeAll('migrate_' . $migration->id() . '_prepare_row', [$row$source$migration])
      ->willThrow(new MigrateSkipRowException())
      ->shouldBeCalled();
    $source->setModuleHandler($module_handler->reveal());

    // This will only be called on the first prepare because the second     // explicitly avoids it.     $this->idMap->expects($this->once())
      ->method('saveIdMapping')
      ->with($row[], MigrateIdMapInterface::STATUS_IGNORED);
    $this->assertFalse($source->prepareRow($row));

    // Throw an exception the second time that avoids mapping.


  /** * Tests for entity storage exception. * * @covers ::writeData */
  public function testEntityStorageException() {
    /** @var \Drupal\Core\Entity\EntityTypeManager $entityTypeManager */
    $entityTypeManager = $this->prophesize(EntityTypeManager::class);
    $entityTypeManager->getStorage('file')
      ->willThrow(EntityStorageException::class);

    $fileRepository = new FileRepository(
      $this->container->get('file_system'),
      $this->container->get('stream_wrapper_manager'),
      $entityTypeManager->reveal(),
      $this->container->get('module_handler'),
      $this->container->get('file.usage'),
      $this->container->get('current_user')
    );

    $this->expectException(EntityStorageException::class);
    
$this->migrateStub->createStub('destination_migration', [1][], FALSE)->willReturn([2]);

    $configuration = [
      'no_stub' => FALSE,
      'migration' => 'destination_migration',
    ];

    $migration = MigrationLookup::create($this->prepareContainer()$configuration, '', []$migration_plugin->reveal());
    $result = $migration->transform(1, $this->migrateExecutable, $this->row, '');
    $this->assertEquals(2, $result);

    $this->migrateStub->createStub('destination_migration', [1][], FALSE)->willThrow(new \Exception('Oh noes!'));
    $migration = MigrationLookup::create($this->prepareContainer()$configuration, '', []$migration_plugin->reveal());
    $this->expectException(MigrateException::class);
    $this->expectExceptionMessage('Exception was thrown while attempting to stub: Oh noes!');
    $migration->transform(1, $this->migrateExecutable, $this->row, '');
  }

  /** * Tests that processing is skipped when the input value is invalid. * * @param mixed $value * An invalid value. * * @dataProvider skipInvalidDataProvider */
return $data;
  }

  /** * Tests the convert() method with an invalid entity type ID. * * @covers ::convert */
  public function testConvertWithInvalidEntityType() {
    $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
    $entity_type_manager->getStorage('invalid_entity_type_id')->willThrow(new InvalidPluginDefinitionException('invalid_entity_type_id'));
    $entity_repository = $this->prophesize(EntityRepositoryInterface::class);
    $converter = new EntityRevisionParamConverter($entity_type_manager->reveal()$entity_repository->reveal());

    $this->expectException(InvalidPluginDefinitionException::class);
    $converter->convert('valid_id', ['type' => 'entity_revision:invalid_entity_type_id'], 'foo', ['foo' => 'valid_id']);
  }

  /** * Tests the convert() method with an invalid dynamic entity type ID. * * @covers ::convert */


  /** * Tests for entity storage exception. * * @covers ::move */
  public function testEntityStorageException() {
    /** @var \Drupal\Core\Entity\EntityTypeManager $entityTypeManager */
    $entityTypeManager = $this->prophesize(EntityTypeManager::class);
    $entityTypeManager->getStorage('file')
      ->willThrow(EntityStorageException::class);

    $fileRepository = new FileRepository(
      $this->container->get('file_system'),
      $this->container->get('stream_wrapper_manager'),
      $entityTypeManager->reveal(),
      $this->container->get('module_handler'),
      $this->container->get('file.usage'),
      $this->container->get('current_user')
    );

    $this->expectException(EntityStorageException::class);
    


  /** * Tests for entity storage exception. * * @covers ::copy */
  public function testEntityStorageException() {
    /** @var \Drupal\Core\Entity\EntityTypeManager $entityTypeManager */
    $entityTypeManager = $this->prophesize(EntityTypeManager::class);
    $entityTypeManager->getStorage('file')
      ->willThrow(EntityStorageException::class);

    $fileRepository = new FileRepository(
      $this->container->get('file_system'),
      $this->container->get('stream_wrapper_manager'),
      $entityTypeManager->reveal(),
      $this->container->get('module_handler'),
      $this->container->get('file.usage'),
      $this->container->get('current_user')
    );

    $this->expectException(EntityStorageException::class);
    
->shouldBeCalled();
    $this->assertSame($cache$this->formStateDecoratorBase->isCached());
  }

  /** * @covers ::setCached * * @dataProvider providerSingleBooleanArgument */
  public function testSetCachedWithLogicException($cache) {
    $this->decoratedFormState->setCached($cache)
      ->willThrow(\LogicException::class);
    $this->expectException(\LogicException::class);
    $this->formStateDecoratorBase->setCached($cache);
  }

  /** * @covers ::disableCache */
  public function testDisableCache() {
    $this->decoratedFormState->disableCache()
      ->shouldBeCalled();

    
'%field' => 'the_field_name', '%error' => 'The exception message']
    );
  }

  /** * Tests a field block that throws a form exception. * * @todo Remove in https://www.drupal.org/project/drupal/issues/2367555. */
  public function testBuildWithFormException() {
    $field = $this->prophesize(FieldItemListInterface::class);
    $field->view(Argument::type('array'))->willThrow(new EnforcedResponseException(new Response()));

    $entity = $this->prophesize(FieldableEntityInterface::class);
    $entity->get('the_field_name')->willReturn($field->reveal());

    $block = $this->getTestBlock($entity);
    $this->expectException(EnforcedResponseException::class);
    $block->build();
  }

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