prophesize example


  public function testBuild() {
    // Build all our dependencies, backwards.     $translation_manager = $this->getMockBuilder('Drupal\Core\StringTranslation\TranslationInterface')
      ->disableOriginalConstructor()
      ->getMock();

    $prophecy = $this->prophesize('Drupal\taxonomy\Entity\Term');
    $prophecy->label()->willReturn('Something');
    $prophecy->id()->willReturn(1);
    $prophecy->getCacheTags()->willReturn(['taxonomy_term:1']);
    $prophecy->getCacheContexts()->willReturn([]);
    $prophecy->getCacheMaxAge()->willReturn(Cache::PERMANENT);
    $term1 = $prophecy->reveal();

    $prophecy = $this->prophesize('Drupal\taxonomy\Entity\Term');
    $prophecy->label()->willReturn('Something else');
    $prophecy->id()->willReturn(2);
    $prophecy->getCacheTags()->willReturn(['taxonomy_term:2']);
    
$plugin_definition = [
      'title' => 'Hey jude',
      'enabled' => 1,
      'expanded' => 1,
      'menu_name' => 'admin',
      'parent' => '',
      'weight' => 10,
    ];
    $expected_plugin_definition = $plugin_definition;
    $expected_plugin_definition['weight'] = -10;

    $static_override = $this->prophesize(StaticMenuLinkOverridesInterface::class);
    $static_override->saveOverride('example_menu_link', $expected_plugin_definition);
    $static_override = $static_override->reveal();

    $menu_link = new MenuLinkDefault([], 'example_menu_link', $plugin_definition$static_override);

    $this->assertEquals($expected_plugin_definition$menu_link->updateLink(['weight' => -10], TRUE));
  }

  /** * @covers ::updateLink */
  

  public function testGetUpgradeStates($modules_to_enable$files$field_plugins$migrations$source_system_data$expected_7$expected_6) {
    $fieldPluginManager = $this->prophesize(MigrateFieldPluginManagerInterface::class);
    $fieldPluginManager->getDefinitions()->willReturn($field_plugins);
    $moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
    $moduleHandler->getModuleList()->willReturn($modules_to_enable);
    vfsStreamWrapper::register();
    $root = new vfsStreamDirectory('modules');
    vfsStreamWrapper::setRoot($root);
    $url = vfsStream::url('modules');

    foreach ($files as $module => $contents) {
      $path = $url . '/' . $module . '/migrations/state';
      mkdir($path, '0755', TRUE);
      

class EntityRevisionTest extends EntityTestBase {

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

    $this->migration = $this->prophesize(MigrationInterface::class);
    $this->storage = $this->prophesize(EntityStorageInterface::class);

    $this->entityType = $this->prophesize(EntityTypeInterface::class);
    $this->entityType->getSingularLabel()->willReturn('foo');
    $this->entityType->getPluralLabel()->willReturn('bar');
    $this->storage->getEntityType()->willReturn($this->entityType->reveal());
    $this->storage->getEntityTypeId()->willReturn('foo');
  }

  /** * Tests that revision destination fails for unrevisionable entities. */

  public function testGetContextValue() {
    $data_definition = DataDefinition::create('string');
    $typed_data = new StringData($data_definition);
    $typed_data->setValue('example string');

    // Prepare a container that holds the typed data manager mock.     $typed_data_manager = $this->prophesize(TypedDataManagerInterface::class);
    $typed_data_manager->getCanonicalRepresentation($typed_data)->will(function D$arguments) {
      return $arguments[0]->getValue();
    });
    $this->container->set('typed_data_manager', $typed_data_manager->reveal());

    $definition = new ContextDefinition('any');
    $context = new Context($definition$typed_data);
    $value = $context->getContextValue();
    $this->assertSame($value$typed_data->getValue());
  }

  
$second_section_storage = clone $this->sectionList;
    $this->assertTrue($this->sectionList->equals($second_section_storage));

    $second_section_storage->getSection(0)->setLayoutSettings(['foo' => '1']);
    $this->assertFalse($this->sectionList->equals($second_section_storage));
  }

  /** * @covers ::equals */
  public function testEqualsNonSection() {
    $list = $this->prophesize(FieldItemListInterface::class);
    $this->assertFalse($this->sectionList->equals($list->reveal()));
  }

}
/** * @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\MigrationLookup * @group migrate */
class MigrationLookupTest extends MigrationLookupTestCase {

  /** * @covers ::transform */
  public function testTransformWithStubSkipping() {
    $migration_plugin = $this->prophesize(MigrationInterface::class);
    $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);

    $destination_id_map = $this->prophesize(MigrateIdMapInterface::class);
    $destination_migration = $this->prophesize(MigrationInterface::class);
    $destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
    $destination_id_map->lookupDestinationIds([1])->willReturn(NULL);

    // Ensure the migration plugin manager returns our migration.     $migration_plugin_manager->createInstances(Argument::exact(['destination_migration']))
      ->willReturn(['destination_migration' => $destination_migration->reveal()]);

    

class StateTest extends UnitTestCase {

  /** * @covers ::__construct * @covers ::id * @covers ::label * @covers ::weight */
  public function testGetters() {
    $state = new State(
      $this->prophesize(WorkflowTypeInterface::class)->reveal(),
      'draft',
      'Draft',
      3
    );
    $this->assertEquals('draft', $state->id());
    $this->assertEquals('Draft', $state->label());
    $this->assertEquals(3, $state->weight());
  }

  /** * @covers ::canTransitionTo */
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    // Check that the validation class is available.     if (!class_exists("\\JsonSchema\\Validator")) {
      $this->fail('The JSON Schema validator is missing. You can install it with `composer require justinrainbow/json-schema`.');
    }

    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    $module = $this->prophesize(Extension::class);
    $module_path = dirname(__DIR__, 4);
    $module->getPath()->willReturn($module_path);
    $module_handler->getModule('jsonapi')->willReturn($module->reveal());
    $subscriber = new ResourceResponseValidator(
      $this->prophesize(LoggerInterface::class)->reveal(),
      $module_handler->reveal(),
      ''
    );
    $subscriber->setValidator();
    $this->subscriber = $subscriber;
  }

class OffsetPageTest extends UnitTestCase {

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

    $container = new Container();
    $cache_context_manager = $this->prophesize(CacheContextsManager::class);
    $cache_context_manager->assertValidTokens(Argument::any())
      ->willReturn(TRUE);
    $container->set('cache_contexts_manager', $cache_context_manager->reveal());
    \Drupal::setContainer($container);
  }

  /** * @covers ::createFromQueryParameter * @dataProvider parameterProvider */
  public function testCreateFromQueryParameter($original$expected) {
    

  protected $entityTypeManager;

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

    $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);

    $this->entityTypeRepository = new EntityTypeRepository($this->entityTypeManager->reveal());
  }

  /** * Sets up the entity type manager to be tested. * * @param \Drupal\Core\Entity\EntityTypeInterface[]|\Prophecy\Prophecy\ProphecyInterface[] $definitions * (optional) An array of entity type definitions. */
  protected function setUpEntityTypeDefinitions($definitions = []) {
    
->method('getProvider')
      ->willReturn('block');

    $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
    $this->entityTypeManager->expects($this->any())
      ->method('getDefinition')
      ->with($this->entityTypeId)
      ->willReturn($this->entityType);

    $this->uuid = $this->createMock('\Drupal\Component\Uuid\UuidInterface');

    $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
    $this->themeHandler = $this->prophesize(ThemeHandlerInterface::class);

    $container = new ContainerBuilder();
    $container->set('entity_type.manager', $this->entityTypeManager);
    $container->set('module_handler', $this->moduleHandler->reveal());
    $container->set('theme_handler', $this->themeHandler->reveal());
    $container->set('uuid', $this->uuid);
    \Drupal::setContainer($container);
  }

  /** * @covers ::calculateDependencies */
protected $defaultTheme = 'stark';

  /** * Tests that provider discovery fails if the provider database is empty. * * @param string $content * The expected JSON content of the provider database. * * @dataProvider providerEmptyProviderList */
  public function testEmptyProviderList($content) {
    $response = $this->prophesize('\GuzzleHttp\Psr7\Response');
    $response->getBody()->willReturn(Utils::streamFor($content));

    $client = $this->createMock('\GuzzleHttp\Client');
    $client->method('request')->withAnyParameters()->willReturn($response->reveal());
    $this->container->set('http_client', $client);

    $this->expectException(ProviderException::class);
    $this->expectExceptionMessage('Remote oEmbed providers database returned invalid or empty list.');
    $this->container->get('media.oembed.provider_repository')->getAll();
  }

  

  protected $formStateDecoratorBase;

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

    $this->decoratedFormState = $this->prophesize(FormStateInterface::class);

    $this->formStateDecoratorBase = new NonAbstractFormStateDecoratorBase($this->decoratedFormState->reveal());
  }

  /** * Provides data to test methods that take a single boolean argument. */
  public function providerSingleBooleanArgument() {
    return [
      [TRUE],
      [FALSE],
    ];
/** * @covers ::getDynamicPluginConfig * * @dataProvider providerGetDynamicPluginConfig */
  public function testGetDynamicPluginConfig(array $configuration, array $expected_dynamic_config): void {
    // Read the CKEditor 5 plugin's static configuration from YAML.     $ckeditor5_plugin_definitions = Yaml::parseFile(__DIR__ . '/../../../ckeditor5.ckeditor5.yml');
    $static_plugin_config = $ckeditor5_plugin_definitions['ckeditor5_list']['ckeditor5']['config'];
    $plugin = new ListPlugin($configuration, 'ckeditor5_list', NULL);
    $dynamic_plugin_config = $plugin->getDynamicPluginConfig($static_plugin_config$this->prophesize(Editor::class)
      ->reveal());
    $this->assertSame($expected_dynamic_config$dynamic_plugin_config);
  }

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