willReturnOnConsecutiveCalls example

$field_definition = $this->createMock('Drupal\Core\Field\FieldDefinitionInterface');
    $field_definition->expects($this->any())
      ->method('getFieldStorageDefinition')
      ->willReturn($field_storage_definition);

    $field_list_a = new FieldItemList($field_definition);
    $field_list_b = new FieldItemList($field_definition);

    // Set up the mocking necessary for creating field items.     $field_type_manager->expects($this->any())
      ->method('createFieldItem')
      ->willReturnOnConsecutiveCalls($first_field_item$second_field_item);

    // Set the field item values.     if ($first_field_item instanceof FieldItemInterface) {
      $field_list_a->setValue($first_field_item);
    }
    if ($second_field_item instanceof FieldItemInterface) {
      $field_list_b->setValue($second_field_item);
    }

    $this->assertEquals($expected$field_list_a->equals($field_list_b));
  }

  
$this->assertSame(['source_value1', 'source_value2', 'source_value3', 'source_value4']$value);
  }

  /** * Tests the Get plugin when source has integer values. * * @dataProvider integerValuesDataProvider */
  public function testIntegerValues($source$expected_value) {
    $this->row->expects($this->atMost(2))
      ->method('get')
      ->willReturnOnConsecutiveCalls('val1', 'val2');

    $this->plugin = new Get(['source' => $source], '', []);
    $return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destination_property');
    $this->assertSame($expected_value$return);
  }

  /** * Provides data for the successful lookup test. * * @return array */
  
class AmazonSqsSenderTest extends TestCase
{
    public function testSend()
    {
        $envelope = new Envelope(new DummyMessage('Oy'));
        $encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]];

        $connection = $this->createMock(Connection::class);
        $connection->expects($this->once())->method('send')->with($encoded['body']$encoded['headers']);

        $serializer = $this->createMock(SerializerInterface::class);
        $serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded);

        $sender = new AmazonSqsSender($connection$serializer);
        $sender->send($envelope);
    }

    public function testSendWithAmazonSqsFifoStamp()
    {
        $envelope = (new Envelope(new DummyMessage('Oy')))
            ->with($stamp = new AmazonSqsFifoStamp('testGroup', 'testDeduplicationId'));

        $encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]];

        
$container->expects($this->any())
      ->method('get')
      ->with('language.default')
      ->willReturn($language_default);
    \Drupal::setContainer($container);

    $language = new Language(['id' => $this->randomMachineName(2)]);
    // Set up the LanguageDefault to return different default languages on     // consecutive calls.     $language_default->expects($this->any())
      ->method('get')
      ->willReturnOnConsecutiveCalls(
        $language,
        new Language(['id' => $this->randomMachineName(2)])
      );

    $this->assertTrue($language->isDefault());
    $this->assertFalse($language->isDefault());
  }

  /** * Tests sorting an array of language objects. * * @covers ::sort * * @dataProvider providerTestSortArrayOfLanguages * * @param \Drupal\Core\Language\LanguageInterface[] $languages * An array of language objects. * @param array $expected * The expected array of keys. */
final class BeanstalkdSenderTest extends TestCase
{
    public function testSend()
    {
        $envelope = new Envelope(new DummyMessage('Oy'));
        $encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]];

        $connection = $this->createMock(Connection::class);
        $connection->expects($this->once())->method('send')->with($encoded['body']$encoded['headers'], 0);

        $serializer = $this->createMock(SerializerInterface::class);
        $serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded);

        $sender = new BeanstalkdSender($connection$serializer);
        $sender->send($envelope);
    }

    public function testSendWithDelay()
    {
        $envelope = (new Envelope(new DummyMessage('Oy')))->with(new DelayStamp(500));
        $encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]];

        $connection = $this->createMock(Connection::class);
        
$context = Context::createDefaultContext(new SalesChannelApiSource(Uuid::randomHex()));

        $this->cacheItemPoolInterfaceMock->method('getItem')->willReturn(new CacheItem());

        $kernelMock = $this->createMock(Kernel::class);
        $containerMock = $this->createMock(Container::class);
        $containerMock->method('getParameter')->with('kernel.plugin_dir')->willReturn('tmp');
        $containerMock->method('get')->willReturn($this->eventDispatcher);
        $kernelMock->method('getContainer')->willReturn($containerMock);
        $this->containerMock
            ->expects(static::exactly(2))
            ->method('get')->willReturnOnConsecutiveCalls(
                $kernelMock,
                new FakeKernelPluginLoader(
                    [
                        [
                            'baseClass' => 'MockPlugin',
                            'active' => false,
                        ],
                    ]
                )
            );

        
$deliveryEntity = new OrderDeliveryEntity();
        $deliveryEntity->setId(Uuid::randomHex());
        $deliveryEntity->setStateId(Uuid::randomHex());

        $deliveries = new OrderDeliveryCollection([$deliveryEntity]);

        $orderEntity = $this->orderEntity();
        $orderEntity->setDeliveries($deliveries);
        $cart = $this->getCart();

        $entityRepository = $this->createMock(EntityRepository::class);
        $entityRepository->method('search')->willReturnOnConsecutiveCalls(
            new EntitySearchResult('order', 1, new OrderCollection([$orderEntity]), null, new Criteria()$this->salesChannelContext->getContext()),
        );

        $entityRepository
            ->expects(static::once())
            ->method('upsert')
            ->willReturnCallback(function Darray $data, Context $context) use ($orderEntity) {
                static::assertSame($data[0]['stateId']$orderEntity->getStateId());
                static::assertNotNull($data[0]['deliveries']);
                static::assertNotNull($data[0]['deliveries'][0]);
                static::assertSame($data[0]['deliveries'][0]['stateId']$orderEntity->getDeliveries()?->first()?->getStateId());

                
static::assertArrayHasKey('int', $documents[$uuid]['customFields'][Defaults::LANGUAGE_SYSTEM]);
        static::assertIsFloat($documents[$uuid]['customFields'][Defaults::LANGUAGE_SYSTEM]['int']);
        static::assertArrayNotHasKey('unknown', $documents[$uuid]['customFields'][Defaults::LANGUAGE_SYSTEM]);
    }

    public function getConnection(): Connection
    {
        $connection = $this->createMock(Connection::class);

        $connection
            ->method('fetchAllAssociativeIndexed')
            ->willReturnOnConsecutiveCalls(
                [
                    $this->ids->get('product-1') => [
                        'id' => $this->ids->get('product-1'),
                        'parentId' => null,
                        'productNumber' => 1,
                        'ean' => '',
                        'active' => true,
                        'available' => true,
                        'isCloseout' => true,
                        'shippingFree' => true,
                        'markAsTopseller' => true,
                        
$statement = $this->createMock('\Drupal\Core\Database\StatementInterface');
    $statement->expects($this->any())
      ->method('fetchField')
      ->willReturn($max_identifier_length);

    $this->connection->expects($this->exactly(2))
      ->method('query')
      ->withConsecutive(
        [$this->anything()],
        ["SELECT 1 FROM pg_constraint WHERE conname = '$expected'"],
      )
      ->willReturnOnConsecutiveCalls(
        $statement,
        $this->createMock('\Drupal\Core\Database\StatementInterface'),
      );

    $schema->constraintExists($table_name$name);
  }

  /** * Data provider for ::testComputedConstraintName(). */
  public function providerComputedConstraintName() {
    
->getMock();
    $route_provider = $this->createMock('Drupal\Core\Routing\RouteProviderInterface');
    $state = $this->createMock('\Drupal\Core\State\StateInterface');
    $menu_storage = $this->createMock('\Drupal\Core\Entity\EntityStorageInterface');
    $parent_form_selector = $this->createMock(MenuParentFormSelector::class);
    $page_display = $this->getMockBuilder('Drupal\views\Plugin\views\display\Page')
      ->onlyMethods(['initDisplay', 'getPath'])
      ->setConstructorArgs([[], 'default', $display_manager->getDefinition('page')$route_provider$state$menu_storage$parent_form_selector])
      ->getMock();
    $page_display->expects($this->any())
      ->method('getPath')
      ->willReturnOnConsecutiveCalls(
        'test_page',
        '<object>malformed_path</object>',
        '<script>alert("placeholder_page/%")</script>',
      );

    $embed_display = $this->getMockBuilder('Drupal\views\Plugin\views\display\Embed')
      ->onlyMethods(['initDisplay'])
      ->setConstructorArgs([[], 'default', $display_manager->getDefinition('embed')])
      ->getMock();

    $values = [];
    
$reader->expects(static::once())->method('read')->willReturn([
            ['id' => 'id1', 'name' => 'foo'],
            ['id' => 'id2', 'name' => 'baz'],
            ['id' => 'id3', 'name' => 'bar'],
        ]);

        $writer = $this->createMock(AbstractWriter::class);
        $writer->expects(static::never())->method('append');

        $pipe = $this->createMock(AbstractPipe::class);
        $pipe->expects(static::never())->method('in');
        $pipe->expects(static::exactly(3))->method('out')->willReturnOnConsecutiveCalls([
            'id1' => ['id' => 'id1', 'name' => 'foo'],
        ][
            'id2' => ['id' => 'id2', 'name' => 'baz'],
        ][
            'id3' => ['id' => 'id3', 'name' => 'bar'],
        ]);

        $logEntity = new ImportExportLogEntity();
        $logEntity->assign([
            'id' => Uuid::randomHex(),
            'activity' => ImportExportLogEntity::ACTIVITY_IMPORT,
            
/** * @requires extension amqp */
class AmqpSenderTest extends TestCase
{
    public function testItSendsTheEncodedMessage()
    {
        $envelope = new Envelope(new DummyMessage('Oy'));
        $encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]];

        $serializer = $this->createMock(SerializerInterface::class);
        $serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded);

        $connection = $this->createMock(Connection::class);
        $connection->expects($this->once())->method('publish')->with($encoded['body']$encoded['headers']);

        $sender = new AmqpSender($connection$serializer);
        $sender->send($envelope);
    }

    public function testItSendsTheEncodedMessageUsingARoutingKey()
    {
        $envelope = (new Envelope(new DummyMessage('Oy')))->with($stamp = new AmqpStamp('rk'));
        
$context->addState('skipTriggerFlow');
        $order = new OrderEntity();
        $event = new CheckoutOrderPlacedEvent(
            $context,
            $order,
            Defaults::SALES_CHANNEL_TYPE_STOREFRONT
        );

        $flowLogEvent = new FlowLogEvent(FlowLogEvent::NAME, $event);
        $this->dispatcher->expects(static::exactly(2))
            ->method('dispatch')
            ->willReturnOnConsecutiveCalls($event$flowLogEvent);

        $this->flowDispatcher->dispatch($event);
    }

    public function testDispatchWithoutFlowLoader(): void
    {
        $context = Context::createDefaultContext();
        $order = new OrderEntity();
        $event = new CheckoutOrderPlacedEvent(
            $context,
            $order,
            
return ['id' => $currentLocaleId, 'code' => 'en-GB'];
        });

        $viLocaleId = Uuid::randomHex();

        $this->connection->expects(static::atLeast(2))->method('fetchOne')->willReturn($viLocaleId);

        $methodReturns = array_values(array_filter([$expectedMissingTranslations$expectedStateTranslations]fn (array $item) => $item !== []));

        $methodCalls = \count($methodReturns);

        $this->connection->expects(static::atLeast($methodCalls))->method('fetchAllKeyValue')->willReturnOnConsecutiveCalls($expectedStateTranslations$expectedMissingTranslations);

        $this->connection->expects(static::exactly($expectedInsertCall))->method('insert')->willReturnCallback($insertCallback);
        $this->shopConfigurator->setDefaultLanguage('de_DE');
    }

    /** * @return iterable<string, array<string, mixed>> */
    public static function countryStateTranslationsProvider(): iterable
    {
        /** * @param array<string, string> $parameters */
elseif ($request->getPathInfo() == '/example') {
          return [
            RouteObjectInterface::ROUTE_NAME => 'example',
            RouteObjectInterface::ROUTE_OBJECT => $route_2,
            '_raw_variables' => new InputBag([]),
          ];
        }
      });

    $this->accessManager->expects($this->any())
      ->method('check')
      ->willReturnOnConsecutiveCalls(
        AccessResult::allowed()->cachePerPermissions(),
        AccessResult::allowed()->addCacheContexts(['bar'])->addCacheTags(['example'])
      );
    $breadcrumb = $this->builder->build($this->createMock('Drupal\Core\Routing\RouteMatchInterface'));
    $this->assertEquals([
      new Link('Home', new Url('<front>')),
      new Link('Example', new Url('example')),
      new Link('Bar', new Url('example_bar')),
    ]$breadcrumb->getLinks());
    $this->assertEqualsCanonicalizing([
      'bar',
      
Home | Imprint | This part of the site doesn't use cookies.