getInvocationCount example

$pluginEntityMock->setActive(false);
        $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);
        $matcher = static::exactly(2);
        $kernelMock->expects($matcher)->method('getContainer')->willReturnCallback(function D) use ($matcher$containerMock): Container {
            if ($matcher->getInvocationCount() === 1) {
                return $containerMock;
            }

            throw new \LogicException();
        });
        $this->containerMock->method('get')->willReturnOnConsecutiveCalls(
            $kernelMock,
            new FakeKernelPluginLoader(
                [
                    [
                        'baseClass' => 'MockPlugin',
                        
$event = new RequestEvent($this->createMock(HttpKernelInterface::class)$this->createRequest('fr'), HttpKernelInterface::MAIN_REQUEST);
        $this->listener->onKernelRequest($event);
    }

    public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
    {
        $matcher = $this->exactly(2);
        $this->localeAwareService
            ->expects($matcher)
            ->method('setLocale')
            ->willReturnCallback(function Dstring $locale) use ($matcher) {
                if (1 === $matcher->getInvocationCount()) {
                    throw new \InvalidArgumentException();
                }

                $this->assertSame('en', $locale);
            })
        ;

        $event = new RequestEvent($this->createMock(HttpKernelInterface::class)$this->createRequest('fr'), HttpKernelInterface::MAIN_REQUEST);
        $this->listener->onKernelRequest($event);
    }

    
$cart = new Cart(Uuid::randomHex());
        $context = $this->createMock(SalesChannelContext::class);

        $matcher = static::exactly(2);
        $this->lineItemRegistryMock->expects($matcher)->method('create')
            ->willReturnCallback(
                function Darray $lineItemDataPar, SalesChannelContext $contextPar) use (
                    $matcher,
                    $expectedLineItemData,
                    $expectedLineItemData2
                ) {
                    match ($matcher->getInvocationCount()) {
                        default => static::fail('to many calls of create'),
                        2 => static::assertEquals($expectedLineItemData2$lineItemDataPar),
                        1 => static::assertEquals($expectedLineItemData$lineItemDataPar),
                    };

                    return new LineItem($lineItemDataPar['id'], 'product');
                }
            );

        $this->translatorCallback();

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