atLeastOnce example

$request = Request::create('/danger');
        $response = $kernel->handle($request);

        $this->assertSame('It\'s dangerous to go alone. Take this ⚔', $response->getContent());
    }

    public function testRoutingRouteLoaderTagIsAdded()
    {
        $frameworkExtension = $this->createMock(ExtensionInterface::class);
        $frameworkExtension
            ->expects($this->atLeastOnce())
            ->method('getAlias')
            ->willReturn('framework');
        $container = new ContainerBuilder();
        $container->registerExtension($frameworkExtension);
        $kernel = $this->kernel = new ConcreteMicroKernel('test', false);
        $kernel->registerContainerConfiguration(new ClosureLoader($container));
        $this->assertTrue($container->getDefinition('kernel')->hasTag('routing.route_loader'));
    }

    public function testFlexStyle()
    {
        
protected function setUpUnusedCache() {
    $this->cacheFactory->expects($this->never())
      ->method('get');
  }

  /** * Sets up a memory-based render cache back-end. */
  protected function setupMemoryCache() {
    $this->memoryCache = $this->memoryCache ?: new MemoryBackend();

    $this->cacheFactory->expects($this->atLeastOnce())
      ->method('get')
      ->with('render')
      ->willReturn($this->memoryCache);
  }

  /** * Sets up a request object on the request stack. * * @param string $method * The HTTP method to use for the request. Defaults to 'GET'. */
  


    public function testCalculateAdminShippingCostZero(): void
    {
        $context = $this->createMock(SalesChannelContext::class);
        $context->method('getItemRounding')->willReturn(new CashRoundingConfig(2, 0.01, true));

        $delivery = $this->getMockBuilder(Delivery::class)
            ->disableOriginalConstructor()
            ->getMock();
        $costs = new CalculatedPrice(0.0, 0.0, new CalculatedTaxCollection()new TaxRuleCollection());
        $delivery->expects(static::atLeastOnce())->method('getShippingCosts')->willReturn($costs);
        $newCosts = null;
        $delivery->expects(static::once())->method('setShippingCosts')->willReturnCallback(function D$costsParameter) use (&$newCosts): void {
            /** @var CalculatedPrice $newCosts */
            $newCosts = $costsParameter;
        });

        $lineItem = new LineItem(Uuid::randomHex(), 'product');
        $lineItem->setDeliveryInformation(
            new DeliveryInformation(
                10,
                12.0,
                
$condition_true->expects($this->any())
      ->method('execute')
      ->willReturn(TRUE);
    $condition_false = $this->createMock('Drupal\Core\Condition\ConditionInterface');
    $condition_false->expects($this->any())
      ->method('execute')
      ->willReturn(FALSE);
    $condition_exception = $this->createMock('Drupal\Core\Condition\ConditionInterface');
    $condition_exception->expects($this->any())
      ->method('execute')
      ->will($this->throwException(new ContextException()));
    $condition_exception->expects($this->atLeastOnce())
      ->method('isNegated')
      ->willReturn(FALSE);
    $condition_negated = $this->createMock('Drupal\Core\Condition\ConditionInterface');
    $condition_negated->expects($this->any())
      ->method('execute')
      ->will($this->throwException(new ContextException()));
    $condition_negated->expects($this->atLeastOnce())
      ->method('isNegated')
      ->willReturn(TRUE);

    $conditions = [];
    
'extension' => '.twig',
      'base_theme_extensions' => [],
    ]);

    $this->themeManager->expects($this->exactly(2))
      ->method('getActiveTheme')
      ->willReturnOnConsecutiveCalls($test_theme$test_stable);

    // Include the module and theme files so that hook_theme can be called.     include_once $this->root . '/core/modules/system/tests/modules/theme_test/theme_test.module';
    include_once $this->root . '/core/tests/fixtures/test_stable/test_stable.theme';
    $this->moduleHandler->expects($this->atLeastOnce())
      ->method('invokeAllWith')
      ->with('theme')
      ->willReturnCallback(function Dstring $hook, callable $callback) {
        $callback(function D) {}, 'theme_test');
      });
    $this->moduleHandler->expects($this->atLeastOnce())
      ->method('getModuleList')
      ->willReturn([]);
    $this->moduleList->expects($this->exactly(2))
      ->method('getPath')
      ->with('theme_test')
      
$node->expects($this->any())
      ->method('getCacheTags')
      ->willReturn([]);
    $node->expects($this->any())
      ->method('getCacheMaxAge')
      ->willReturn(-1);
    $node->expects($this->any())
      ->method('getEntityTypeId')
      ->willReturn('node');

    if (isset($isDefaultRevision)) {
      $node->expects($this->atLeastOnce())
        ->method('isDefaultRevision')
        ->willReturn($isDefaultRevision);
    }

    $nodeStorage = $this->createMock(NodeStorageInterface::class);
    $nodeStorage->expects($this->any())
      ->method('load')
      ->with($nid)
      ->willReturn($node);
    $entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
    $entityTypeManager->expects($this->any())
      
protected $contextHandler;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $active_theme = $this->getMockBuilder('Drupal\Core\Theme\ActiveTheme')
      ->disableOriginalConstructor()
      ->getMock();
    $this->theme = $this->randomMachineName();
    $active_theme->expects($this->atLeastOnce())
      ->method('getName')
      ->willReturn($this->theme);
    $active_theme->expects($this->atLeastOnce())
      ->method('getRegions')
      ->willReturn([
        'top',
        'center',
        'bottom',
      ]);

    $theme_manager = $this->createMock('Drupal\Core\Theme\ThemeManagerInterface');
    
$this->assertEquals($plugin_class$class);
  }

  /** * Tests getPluginClass() with a valid object plugin definition. * * @covers ::getPluginClass */
  public function testGetPluginClassWithValidObjectPluginDefinition() {
    $plugin_class = Corn::class;
    $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
    $plugin_definition->expects($this->atLeastOnce())
      ->method('getClass')
      ->willReturn($plugin_class);
    $class = DefaultFactory::getPluginClass('corn', $plugin_definition);

    $this->assertEquals($plugin_class$class);
  }

  /** * Tests getPluginClass() with a missing class definition. * * @covers ::getPluginClass */
public function testExtendedClass() {
    $this->assertEquals(' class="kitten"', $this->twig->render('{{ attribute.addClass("kitten") }}', ['attribute' => new TestAttribute()]));
  }

  /** * Tests that prefixed methods can be called from within Twig templates. * * Currently "get", "has", and "is" are the only allowed prefixes. */
  public function testEntitySafePrefixes() {
    $entity = $this->createMock('Drupal\Core\Entity\EntityInterface');
    $entity->expects($this->atLeastOnce())
      ->method('hasLinkTemplate')
      ->with('test')
      ->willReturn(TRUE);
    $result = $this->twig->render('{{ entity.hasLinkTemplate("test") }}', ['entity' => $entity]);
    $this->assertTrue((bool) $result, 'Sandbox policy allows has* functions to be called.');

    $entity = $this->createMock('Drupal\Core\Entity\EntityInterface');
    $entity->expects($this->atLeastOnce())
      ->method('isNew')
      ->willReturn(TRUE);
    $result = $this->twig->render('{{ entity.isNew }}', ['entity' => $entity]);
    
/** * Provides data for testCheckRequirements(). */
  public function providerTestCheckRequirements() {
    $requirement_optional = new ContextDefinition();
    $requirement_optional->setRequired(FALSE);

    $requirement_any = new ContextDefinition();
    $requirement_any->setRequired(TRUE);

    $context_any = $this->createMock('Drupal\Core\Plugin\Context\ContextInterface');
    $context_any->expects($this->atLeastOnce())
      ->method('getContextDefinition')
      ->willReturn(new ContextDefinition('any'));

    $requirement_specific = new ContextDefinition('string');
    $requirement_specific->setConstraints(['Blank' => []]);

    $context_constraint_mismatch = $this->createMock('Drupal\Core\Plugin\Context\ContextInterface');
    $context_constraint_mismatch->expects($this->atLeastOnce())
      ->method('getContextDefinition')
      ->willReturn(new ContextDefinition('foo'));
    $context_datatype_mismatch = $this->createMock('Drupal\Core\Plugin\Context\ContextInterface');
    

  }

  /** * @covers \Drupal\Core\Routing\UrlGenerator::generateFromRoute * * Note: We use absolute covers to let * \Drupal\Tests\Core\Render\MetadataBubblingUrlGeneratorTest work. */
  public function testGenerateWithPathProcessorChangingOptions() {
    $path_processor = $this->createMock(OutboundPathProcessorInterface::CLASS);
    $path_processor->expects($this->atLeastOnce())
      ->method('processOutbound')
      ->willReturnCallback(function D$path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
        $options['query'] = ['zoo' => 5];
        $options['fragment'] = 'foo';
        return $path;
      });
    $this->processorManager->addOutbound($path_processor);

    $options = [];
    $this->assertGenerateFromRoute('test_2', ['narf' => 5]$options, '/goodbye/cruel/world?zoo=5#foo', (new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT));
  }

  
return $event->getError()->getMessage();
    }

    private function getKernel(array $bundles$useDispatcher = false)
    {
        $container = $this->createMock(ContainerInterface::class);

        if ($useDispatcher) {
            $dispatcher = $this->createMock(EventDispatcherInterface::class);
            $dispatcher
                ->expects($this->atLeastOnce())
                ->method('dispatch')
            ;
            $container
                ->expects($this->atLeastOnce())
                ->method('get')
                ->with($this->equalTo('event_dispatcher'))
                ->willReturn($dispatcher);
        }

        $container
            ->expects($this->exactly(2))
            

  public function testGetTableMappingTranslatable(array $entity_keys) {
    // This allows to re-use the data provider.     $entity_keys['langcode'] = 'langcode';

    $this->entityType->expects($this->atLeastOnce())
      ->method('isTranslatable')
      ->willReturn(TRUE);
    $this->entityType->expects($this->atLeastOnce())
      ->method('getDataTable')
      ->willReturn('entity_test_field_data');
    $this->entityType->expects($this->any())
      ->method('getKey')
      ->willReturnMap([
        ['id', $entity_keys['id']],
        ['uuid', $entity_keys['uuid']],
        ['bundle', $entity_keys['bundle']],
        [
/** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit\Framework\MockObject\MockObject $display */
    [$view$display] = $this->setupBaseViewAndDisplay();

    $views_data = [];
    $views_data['test_field'] = [
      'field' => ['id' => 'standard'],
      'filter' => ['id' => 'standard'],
      'argument' => ['id' => 'standard'],
      'sort' => ['id' => 'standard'],
    ];

    $this->viewsData->expects($this->atLeastOnce())
      ->method('get')
      ->with('test_entity')
      ->willReturn($views_data);

    $display->expects($this->atLeastOnce())
      ->method('setOption')
      ->with($option[
        'test_field' => [
          'id' => 'test_field',
          'table' => 'test_entity',
          'field' => 'test_field',
          
->getMock();
    // Create a configurable plugin that would add a dependency.     $instance_id = $this->randomMachineName();
    $this->moduleHandler->moduleExists('test')->willReturn(TRUE);
    $instance = new TestConfigurablePlugin([]$instance_id['provider' => 'test']);

    // Create a plugin collection to contain the instance.     $plugin_collection = $this->getMockBuilder('\Drupal\Core\Plugin\DefaultLazyPluginCollection')
      ->disableOriginalConstructor()
      ->onlyMethods(['get'])
      ->getMock();
    $plugin_collection->expects($this->atLeastOnce())
      ->method('get')
      ->with($instance_id)
      ->willReturn($instance);
    $plugin_collection->addInstanceId($instance_id);

    // Return the mocked plugin collection.     $entity->expects($this->once())
      ->method('getPluginCollections')
      ->willReturn([$plugin_collection]);

    $dependencies = $entity->calculateDependencies()->getDependencies();
    
Home | Imprint | This part of the site doesn't use cookies.