withConsecutive example

static::assertEquals(2, \Drupal::state()->get('cron_queue_test_lease_time'));
  }

  /** * Tests that non-queue exceptions thrown by workers are handled properly. * * @see \Drupal\cron_queue_test\Plugin\QueueWorker\CronQueueTestException */
  public function testUncaughtExceptions() {
    $this->logger->expects($this->atLeast(2))
      ->method('log')
      ->withConsecutive(
        [
          $this->equalTo(RfcLogLevel::ERROR),
          $this->equalTo('%type: @message in %function (line %line of %file).'),
          $this->callback(function D$args) {
            return $args['@message'] === 'That is not supposed to happen.' &&
              $args['exception'] instanceof \Exception;
          }),
        ],
        [
          $this->equalTo(RfcLogLevel::INFO),
          $this->equalTo('Cron run completed.'),
          
->getMockForAbstractClass();
    $content_entity->expects($this->once())
      ->method('getFields')
      ->willReturn($definitions);

    $serializer = $this->getMockBuilder('Symfony\Component\Serializer\Serializer')
      ->disableOriginalConstructor()
      ->onlyMethods(['normalize'])
      ->getMock();
    $serializer->expects($this->exactly(2))
      ->method('normalize')
      ->withConsecutive(
        [$list_item_1, 'test_format'],
        [$list_item_2, 'test_format'],
      );

    $this->entityNormalizer->setSerializer($serializer);

    $this->entityNormalizer->normalize($content_entity, 'test_format');
  }

  /** * Tests the denormalize() method with no entity type provided in context. * * @covers ::denormalize */
    $storage = $this->createMock('\Drupal\Core\Entity\EntityStorageInterface');
    // Our mocked entity->preSave() returns NULL, so assert that.     $this->assertNull($this->entity->preSave($storage));
  }

  /** * @covers ::postSave */
  public function testPostSave() {
    $this->cacheTagsInvalidator->expects($this->exactly(2))
      ->method('invalidateTags')
      ->withConsecutive([
        [
          // List cache tag.           $this->entityTypeId . '_list',
        ],
      ],
      [
        [
          // List cache tag.           $this->entityTypeId . '_list',
          // Own cache tag.           $this->entityTypeId . ':' . $this->values['id'],
        ],
$key = $this->randomMachineName();
    $value = $this->randomMachineName();

    $cache = (object) [
      'data' => [$key => $value],
      'created' => (int) $_SERVER['REQUEST_TIME'],
    ];
    // Set up mock expectation, on the second call the with the second argument     // set to TRUE because we triggered a cache invalidation.     $this->cacheBackend->expects($this->exactly(2))
      ->method('get')
      ->withConsecutive(
        [$this->cid],
        [$this->cid, TRUE],
      )
      ->willReturn($cache);

    $this->collector->delete($key);

    // Set up mock objects for the expected calls, first a lock acquire, then     // a cache set and finally the lock is released again.     $this->lock->expects($this->once())
      ->method('acquire')
      

  public function testCreateWithPredefinedUuid() {
    $this->entityType->expects($this->once())
      ->method('getClass')
      ->willReturn(get_class($this->getMockEntity()));
    $this->setUpKeyValueEntityStorage();

    $this->moduleHandler->expects($this->exactly(2))
      ->method('invokeAll')
      ->withConsecutive(['test_entity_type_create']['entity_create']);
    $this->uuidService->expects($this->never())
      ->method('generate');

    $entity = $this->entityStorage->create(['id' => 'foo', 'uuid' => 'baz']);
    $this->assertInstanceOf('Drupal\Core\Entity\EntityInterface', $entity);
    $this->assertSame('foo', $entity->id());
    $this->assertSame('baz', $entity->uuid());
  }

  /** * @covers ::create * @covers ::doCreate */
$schema = $this->getMockBuilder('Drupal\Core\Database\Schema')
      ->disableOriginalConstructor()
      ->getMock();
    $schema->expects($this->exactly(2))
      ->method('tableExists')
      ->willReturnMap([
        ['migrate_map_sql_idmap_test', FALSE],
        ['migrate_message_sql_idmap_test', FALSE],
      ]);
    $schema->expects($this->exactly(2))
      ->method('createTable')
      ->withConsecutive(
        ['migrate_map_sql_idmap_test', $map_table_schema],
        ['migrate_message_sql_idmap_test', $table_schema],
      );

    $this->runEnsureTablesTest($schema);
  }

  /** * Tests the ensureTables method when the tables exist. */
  public function testEnsureTablesExist() {
    
// Clone the object but change the owner.     $this->otherObject = clone $this->ownObject;
    $this->otherObject->owner = 2;
  }

  /** * @covers ::get */
  public function testGet() {
    $this->keyValue->expects($this->exactly(2))
      ->method('get')
      ->withConsecutive(
        ['test_2'],
        ['test'],
      )
      ->willReturnOnConsecutiveCalls(
        FALSE,
        $this->ownObject,
      );

    $this->assertNull($this->tempStore->get('test_2'));
    $this->assertSame($this->ownObject->data, $this->tempStore->get('test'));
  }

  
'queue_manager' => $queueManager,
      'time' => $time,
    ] = $this->cronConstructorArguments;

    $cron = $this->getMockBuilder(Cron::class)
      ->onlyMethods(['usleep'])
      ->setConstructorArgs($this->cronConstructorArguments)
      ->getMock();

    $cron->expects($this->exactly(2))
      ->method('usleep')
      ->withConsecutive(
        [$this->equalTo(2000000)],
        [$this->equalTo(3000000)],
      );

    $queueManager->expects($this->once())
      ->method('getDefinitions')
      ->willReturn([
        'test_worker_a' => [
          'id' => 'test_worker_a',
          'cron' => ['time' => 300],
        ],
        
'module_handler_test' => [
            'type' => 'module',
            'pathname' => 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml',
            'filename' => 'module_handler_test.module',
          ],
        ]$this->cacheBackend,
      ])
      ->onlyMethods(['load'])
      ->getMock();
    $module_handler->expects($this->exactly(3))
      ->method('load')
      ->withConsecutive(
        // First reload.         ['module_handler_test'],
        // Second reload.         ['module_handler_test'],
        ['module_handler_test_added'],
      );
    $module_handler->reload();
    $module_handler->addModule('module_handler_test_added', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_added');
    $module_handler->reload();
  }

  
->willReturn(['test_module' => $routes]);

    $route_collection = $routing_fixtures->sampleRouteCollection();
    foreach ($route_collection->all() as $route) {
      $route->setOption('compiler_class', RouteCompiler::class);
    }
    $route_build_event = new RouteBuildEvent($route_collection);

    // Ensure that the alter routes events are fired.     $this->dispatcher->expects($this->atLeast(2))
      ->method('dispatch')
      ->withConsecutive(
        [$route_build_event, RoutingEvents::DYNAMIC],
        [$route_build_event, RoutingEvents::ALTER],
      );

    // Ensure that access checks are set.     $this->checkProvider->expects($this->once())
      ->method('setChecks')
      ->with($route_collection);

    // Ensure that the routes are set to the dumper and dumped.     $this->dumper->expects($this->once())
      
->willReturnCallback(function D$hook$callback) {
        $callback(\Closure::fromCallable([$this, 'viewsData']), 'views_test_data');
      });
    $this->moduleHandler->expects($this->exactly(2))
      ->method('alter')
      ->with('views_data', $expected_views_data);

    // The cache should only be called once (before the clear() call) as get     // will get all table data in the first get().     $this->cacheBackend->expects($this->exactly(4))
      ->method('get')
      ->withConsecutive(
        ['views_data:en'],
        ["views_data:$random_table_name:en"],
        ['views_data:en'],
        ["views_data:$random_table_name:en"],
      )
      ->willReturn(FALSE);
    $this->cacheBackend->expects($this->exactly(4))
      ->method('set')
      ->withConsecutive(
        ['views_data:en', $expected_views_data],
        ["views_data:$random_table_name:en", []],
        [
$this->otherObject->owner = 2;
  }

  /** * Tests the get() method. * * @covers ::get */
  public function testGet() {
    $this->keyValue->expects($this->exactly(3))
      ->method('get')
      ->withConsecutive(
        ['1:test_2'],
        ['1:test'],
        ['1:test'],
      )
      ->willReturnOnConsecutiveCalls(
        FALSE,
        $this->ownObject,
        $this->otherObject,
      );

    $this->assertNull($this->tempStore->get('test_2'));
    
$config->expects($this->exactly(4))
      ->method('get')
      ->with('definitions')
      ->willReturnOnConsecutiveCalls(
        [],
        [],
        $definition_save_1['definitions'],
        $definition_save_1['definitions'],
      );
    $config->expects($this->exactly(2))
      ->method('set')
      ->withConsecutive(
        ['definitions', $definition_save_1['definitions']],
        ['definitions', $definitions_save_2['definitions']],
      )
      ->will($this->returnSelf());
    $config->expects($this->exactly(2))
      ->method('save');

    $config_factory = $this->createMock('Drupal\Core\Config\ConfigFactoryInterface');
    $config_factory->expects($this->once())
      ->method('getEditable')
      ->willReturn($config);

    
$this->container->set('path_alias.manager', $this->pathAliasManager);
    $this->container->set('path.validator', $this->pathValidator);
    \Drupal::setContainer($this->container);
  }

  /** * Tests creating a URL from a request. */
  public function testUrlFromRequest() {
    $this->router->expects($this->exactly(3))
      ->method('matchRequest')
      ->withConsecutive(
        [$this->getRequestConstraint('/node')],
        [$this->getRequestConstraint('/node/1')],
        [$this->getRequestConstraint('/node/2/edit')],
      )
      ->willReturnOnConsecutiveCalls([
        RouteObjectInterface::ROUTE_NAME => 'view.frontpage.page_1',
        '_raw_variables' => new InputBag(),
      ][
        RouteObjectInterface::ROUTE_NAME => 'node_view',
        '_raw_variables' => new InputBag(['node' => '1']),
      ][
        
->method('messenger')
      ->willReturn($this->messenger);
  }

  /** * @covers ::handleFormErrors * @covers ::displayErrorMessages */
  public function testDisplayErrorMessages() {
    $this->messenger->expects($this->exactly(6))
      ->method('addMessage')
      ->withConsecutive(
        ['invalid', 'error'],
        ['invalid', 'error'],
        ['invalid', 'error'],
        ['no title given', 'error'],
        ['element is invisible', 'error'],
        ['this missing element is invalid', 'error'],
      );

    $form = [
      '#parents' => [],
      '#array_parents' => [],
    ];
Home | Imprint | This part of the site doesn't use cookies.