expectExceptionObject example



  /** * @covers ::merge * @dataProvider linkMergeProvider */
  public function testLinkMerge(Link $a, Link $b$expected) {
    if ($expected instanceof Link) {
      $this->assertSame($expected->getCacheTags(), Link::merge($a$b)->getCacheTags());
    }
    else {
      $this->expectExceptionObject($expected);
      Link::merge($a$b);
    }
  }

  /** * Provides test data for link merging. */
  public function linkMergeProvider() {
    $this->mockUrlAssembler();
    return [
      'same everything' => [
        
$tube = 'baz';
        $timeout = 44;

        $exception = new DeadlineSoonException('foo error');

        $client = $this->createMock(PheanstalkInterface::class);
        $client->expects($this->once())->method('watchOnly')->with($tube)->willReturn($client);
        $client->expects($this->once())->method('reserveWithTimeout')->with($timeout)->willThrowException($exception);

        $connection = new Connection(['tube_name' => $tube, 'timeout' => $timeout]$client);

        $this->expectExceptionObject(new TransportException($exception->getMessage(), 0, $exception));
        $connection->get();
    }

    public function testAck()
    {
        $id = 123456;

        $tube = 'xyz';

        $client = $this->createMock(PheanstalkInterface::class);
        $client->expects($this->once())->method('useTube')->with($tube)->willReturn($client);
        
null,
                new Criteria(),
                Context::createDefaultContext(),
            ),
        ]);

        $this->triggerFlowController = new TriggerFlowController(new EventDispatcher()$this->appFlowEventRepository);
    }

    public function testTriggerWithWrongEventName(): void
    {
        $this->expectExceptionObject(new CustomTriggerByNameNotFoundException('custom.checkout.event'));

        $request = new Request();
        $request->setMethod('POST');
        $context = Context::createDefaultContext();
        $appFlowEventRepository = new StaticEntityRepository([
            new EntitySearchResult(
                'app_flow_event',
                1,
                new EntityCollection([]),
                null,
                new Criteria(),
                
static::assertStringContainsString('Cancellation 1000 for Invoice ' . $invoiceNumber$stornoStruct->getHtml());
        // Customer no does not change because it refers to the older version of order         static::assertStringContainsString('Customer no. ' . $customerNo$stornoStruct->getHtml());
    }

    /** * @dataProvider uploadDataProvider */
    public function testUpload(bool $preGenerateDoc, Request $uploadFileRequest, bool $static = true, ?\Exception $expectedException = null): void
    {
        if ($expectedException instanceof \Exception) {
            static::expectExceptionObject($expectedException);
        }

        if ($preGenerateDoc) {
            $operation = new DocumentGenerateOperation($this->orderId);

            $documents = $this->documentGenerator->generate(InvoiceRenderer::TYPE, [$this->orderId => $operation]$this->context)->getSuccess();
            $document = $documents->first();

            static::assertNotNull($document);

            $documentId = $document->getId();
        }
$fooTransport = $this->createMock(TransportInterface::class);
        $fooTransport->method('send')
            ->willThrowException($exception);

        $transport = new Transports([
            'foo' => $fooTransport,
        ]);

        $headers = (new Headers())->addTextHeader('X-Transport', 'foo');
        $email = new Message($headersnew TextPart('...'));

        $this->expectExceptionObject($exception);

        try {
            $transport->send($email);
        } finally {
            $this->assertSame('foo', $email->getHeaders()->getHeaderBody('X-Transport'));
        }
    }
}

#[Package('buyers-experience')] class LandingPageLoaderTest extends TestCase
{
    use IntegrationTestBehaviour;
    use StorefrontPageTestBehaviour;

    private TestDataCollection $ids;

    public function testLoadWithoutId(): void
    {
        $this->expectExceptionObject(RoutingException::missingRequestParameter('landingPageId', '/landingPageId'));

        $context = $this->createSalesChannelContextWithNavigation();
        $this->getPageLoader()->load(new Request()$context);
    }

    public function testLoad(): void
    {
        $this->ids = new TestDataCollection();

        $request = new Request([][][
            'landingPageId' => $this->ids->get('landing-page'),
        ]);
$client = new MockHttpClient($response);

        $transport = new MailjetApiTransport(self::USER, self::PASSWORD, $client);

        $email = new Email();
        $email
            ->from('foo@example.com')
            ->to('bar@example.com')
            ->text('foobar');

        $this->expectExceptionObject(
            new HttpTransportException('Unable to send an email: "cannot-be-decoded" (code 200).', $response)
        );

        $transport->send($email);
    }

    public function testSendWithTransportException()
    {
        $response = new MockResponse('', ['error' => 'foo']);

        $client = new MockHttpClient($response);

        
$this->createMock(SystemConfigService::class),
            $this->eventDispatcher,
            $this->createMock(UrlGeneratorInterface::class),
            $this->logger,
        );
    }

    public function testThrowSalesChannelNotFound(): void
    {
        $salesChannelId = Uuid::randomHex();
        $exception = new SalesChannelNotFoundException($salesChannelId);
        static::expectExceptionObject($exception);

        $data = [
            'recipients' => [],
            'salesChannelId' => $salesChannelId,
        ];

        $this->mailService->send($data, Context::createDefaultContext());
    }

    public function testSendMailSuccess(): void
    {
        
$cart = new Cart(Uuid::randomHex());
        $context = $this->createMock(SalesChannelContext::class);

        $exception = CartException::invalidPriceDefinition();
        $this->lineItemRegistryMock->expects(static::once())
            ->method('create')
            ->with($lineItemData$this->createMock(SalesChannelContext::class))
            ->willThrowException($exception);

        $this->cartService->expects(static::never())->method('add');

        $this->expectExceptionObject($exception);
        $this->controller->addLineItems($cartnew RequestDataBag($request->request->all())$request$context);
    }

    public function testAddLineItemsCartExceptionWillBeThrownQuantity(): void
    {
        $productId = Uuid::randomHex();
        $lineItemData = [
            'id' => $productId,
            'referencedId' => $productId,
            'type' => 'nonexistenttype',
            'stackable' => 1,
            

    }

    public function testSignWithUnsupportedAlgorithm()
    {
        $message = $this->createMock(Message::class);

        $signer = new DkimSigner(self::$pk, 'testdkim.symfony.net', 'sf', [
            'algorithm' => 'unsupported-value',
        ]);

        $this->expectExceptionObject(
            new \LogicException('Invalid DKIM signing algorithm "unsupported-value".')
        );

        $signer->sign($message[]);
    }

    /** * @dataProvider getCanonicalizeHeaderData */
    public function testCanonicalizeHeader(string $bodyCanon, string $canonBody, string $body, int $maxLength)
    {
        
yield [[self::createDummySupportsAuthenticator(null), self::createDummySupportsAuthenticator(true)], true];
        yield [[self::createDummySupportsAuthenticator(true), self::createDummySupportsAuthenticator(false)], true];

        yield [[self::createDummySupportsAuthenticator(false), self::createDummySupportsAuthenticator(false)], false];
        yield [[], false];
    }

    public function testSupportsInvalidAuthenticator()
    {
        $manager = $this->createManager([new \stdClass()]);

        $this->expectExceptionObject(
            new \InvalidArgumentException('Authenticator "stdClass" must implement "Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface".')
        );

        $manager->supports($this->request);
    }

    public function testSupportCheckedUponRequestAuthentication()
    {
        // the attribute stores the supported authenticators, returning false now         // means support changed between calling supports() and authenticateRequest()         // (which is the case with lazy firewalls)
$message = new DummyMessage('Hello');
        $exception = new \RuntimeException();

        $bus = $this->createMock(MessageBusInterface::class);
        $bus->expects($this->once())
            ->method('dispatch')
            ->with($message)
            ->willThrowException($exception);

        $traceableBus = new TraceableMessageBus($bus);

        $this->expectExceptionObject($exception);

        array_map($traceableBus->dispatch(...)[$message]);
    }
}
$listener = new AccessListener($tokenStorage$this->createMock(AccessDecisionManagerInterface::class)$accessMap, false);
        $listener(new LazyResponseEvent(new RequestEvent($this->createMock(HttpKernelInterface::class)$request, HttpKernelInterface::MAIN_REQUEST)));
    }

    public function testConstructWithTrueExceptionOnNoToken()
    {
        $tokenStorage = $this->createMock(TokenStorageInterface::class);
        $tokenStorage->expects($this->never())->method(self::anything());

        $accessMap = $this->createMock(AccessMapInterface::class);

        $this->expectExceptionObject(
            new \LogicException('Argument $exceptionOnNoToken of "Symfony\Component\Security\Http\Firewall\AccessListener::__construct()" must be set to "false".')
        );

        new AccessListener($tokenStorage$this->createMock(AccessDecisionManagerInterface::class)$accessMap, true);
    }
}
$landingPageRouteMock->expects(static::never())->method('load');

        $landingPageLoader = new LandingPageLoader(
            $this->createMock(GenericPageLoader::class),
            $landingPageRouteMock,
            $this->createMock(EventDispatcherInterface::class)
        );

        $request = new Request([][][]);
        $salesChannelContext = $this->getSalesChannelContext();

        static::expectExceptionObject(RoutingException::missingRequestParameter('landingPageId', '/landingPageId'));
        $landingPageLoader->load($request$salesChannelContext);
    }

    public function testNoLandingPageException(): void
    {
        $landingPageRouteMock = $this->createMock(LandingPageRoute::class);
        $landingPageRouteMock->expects(static::once())->method('load');

        $landingPageLoader = new LandingPageLoader(
            $this->createMock(GenericPageLoader::class),
            $landingPageRouteMock,
            
$serializer = new EntitySerializer();
        $serializerRegistry = $this->getContainer()->get(SerializerRegistry::class);
        $serializer->setRegistry($serializerRegistry);
        $return = $serializer->deserialize(new Config([][][])$productDefinition$importData);
        $return = \is_array($return) ? $return : iterator_to_array($return);

        static::assertSame($expectedData$return);
    }

    public function testEnsureIdFieldsWithInvalidCharacter(): void
    {
        static::expectExceptionObject(new InvalidIdentifierException('invalid|string_with_pipe'));

        /** @var EntityDefinition $productDefinition */
        $productDefinition = $this->getContainer()->get(ProductDefinition::class);

        [$expectedData$importData] = require __DIR__ . '/../../../fixtures/ensure_ids_for_products.php';
        $importData['id'] = 'invalid|string_with_pipe';

        $serializer = new EntitySerializer();
        $serializerRegistry = $this->getContainer()->get(SerializerRegistry::class);
        $serializer->setRegistry($serializerRegistry);
        $return = $serializer->deserialize(new Config([][][])$productDefinition$importData);
        
Home | Imprint | This part of the site doesn't use cookies.