willThrowException example

$factory
            ->expects(static::once())
            ->method('createNew')
            ->with('test')
            ->willReturn($newCart);

        $persister = $this->createMock(AbstractCartPersister::class);
        $persister
            ->expects(static::once())
            ->method('load')
            ->with('test')
            ->willThrowException(CartException::tokenNotFound('test'));

        $salesChannelContext = $this->createMock(SalesChannelContext::class);
        $salesChannelContext
            ->expects(static::once())
            ->method('getToken')
            ->willReturn('test');
        $salesChannelContext
            ->expects(static::exactly(2))
            ->method('getContext')
            ->willReturn(Context::createDefaultContext());

        
$response = $this->controller->finishPage(new Request()$contextnew RequestDataBag());

        static::assertEquals(new RedirectResponse('url')$response);
    }

    public function testFinishPageOrderNotFound(): void
    {
        $context = $this->createMock(SalesChannelContext::class);
        $context->method('getCustomer')->willReturn(new CustomerEntity());

        $this->finishPageLoaderMock->method('load')->willThrowException(OrderException::orderNotFound('not-found'));

        $response = $this->controller->finishPage(new Request()$contextnew RequestDataBag());

        static::assertEquals('danger error.CHECKOUT__ORDER_ORDER_NOT_FOUND', $this->controller->flash);
        static::assertEquals(new RedirectResponse('url')$response);
    }

    public function testFinishPagePaymentFailed(): void
    {
        $context = $this->createMock(SalesChannelContext::class);
        $context->method('getCustomer')->willReturn(new CustomerEntity());

        


    public function testSwitchVariantException(): void
    {
        $ids = new IdsCollection();

        $options = [
            $ids->get('group1') => $ids->get('option1'),
            $ids->get('group2') => $ids->get('option2'),
        ];

        $this->findVariantRouteMock->method('load')->willThrowException(new VariantNotFoundException($ids->get('product')$options));

        $response = $this->controller->switch($ids->get('product')new Request()$this->createMock(SalesChannelContext::class));

        static::assertEquals('{"url":"","productId":"' . $ids->get('product') . '"}', $response->getContent());
    }

    public function testQuickViewMinimal(): void
    {
        $ids = new IdsCollection();

        $request = new Request(['productId' => $ids->get('productId')]);
        
$this->assertEquals(new DummyMessage('Hi')$actualEnvelopes[0]->getMessage());
    }

    public function testItThrowsATransportExceptionIfItCannotAcknowledgeMessage()
    {
        $this->expectException(TransportException::class);
        $serializer = $this->createMock(SerializerInterface::class);
        $amqpEnvelope = $this->createAMQPEnvelope();
        $connection = $this->createMock(Connection::class);
        $connection->method('getQueueNames')->willReturn(['queueName']);
        $connection->method('get')->with('queueName')->willReturn($amqpEnvelope);
        $connection->method('ack')->with($amqpEnvelope, 'queueName')->willThrowException(new \AMQPException());

        $receiver = new AmqpReceiver($connection$serializer);
        $receiver->ack(new Envelope(new \stdClass()[new AmqpReceivedStamp($amqpEnvelope, 'queueName')]));
    }

    public function testItThrowsATransportExceptionIfItCannotRejectMessage()
    {
        $this->expectException(TransportException::class);
        $serializer = $this->createMock(SerializerInterface::class);
        $amqpEnvelope = $this->createAMQPEnvelope();
        $connection = $this->createMock(Connection::class);
        
$listener = $this->createListener();
        $listener->onCheckPassport($this->createEvent(''));
    }

    public function testBindFailureShouldThrowAnException()
    {
        $this->expectException(BadCredentialsException::class);
        $this->expectExceptionMessage('The presented password is invalid.');

        $this->ldap->method('escape')->willReturnArgument(0);
        $this->ldap->expects($this->any())->method('bind')->willThrowException(new InvalidCredentialsException());

        $listener = $this->createListener();
        $listener->onCheckPassport($this->createEvent());
    }

    /** * @group legacy * * @dataProvider queryForDnProvider */
    public function testLegacyQueryForDn(string $dnString, string $queryString)
    {
$notifier->doTrackEvent(Notifier::EVENT_INSTALL_FINISHED, ['language' => 'en']);
    }

    public function testTrackEventDoesNotThrowOnException(): void
    {
        $idGenerator = $this->createMock(UniqueIdGenerator::class);
        $idGenerator->expects(static::once())->method('getUniqueId')
            ->willReturn('1234567890');

        $guzzle = $this->createMock(Client::class);
        $guzzle->expects(static::once())->method('postAsync')
            ->willThrowException(new \Exception());

        $notifier = new Notifier('http://localhost', $idGenerator$guzzle, '6.4.12');
        $notifier->doTrackEvent(Notifier::EVENT_INSTALL_FINISHED, ['language' => 'en']);
    }
}
static::assertInstanceOf(JsonResponse::class$result);
    }

    public function testBatchSaveConfigurationFailure(): void
    {
        $configurationServiceMock = $this->createMock(ConfigurationService::class);

        $systemConfigServiceMock = $this->createMock(SystemConfigService::class);

        $systemConfigValidatorMock = $this->createMock(SystemConfigValidator::class);
        $systemConfigValidatorMock->method('validate')
            ->willThrowException($this->createMock(ConstraintViolationException::class));

        $systemConfigController = new SystemConfigController(
            $configurationServiceMock,
            $systemConfigServiceMock,
            $systemConfigValidatorMock
        );

        $request = new Request();
        $request->request->set('null', []);

        $context = Context::createDefaultContext();

        


    public function testUnsuccessfulAuthenticate()
    {
        $this->expectException(InvalidLoginLinkAuthenticationException::class);
        $this->setUpAuthenticator();

        $request = Request::create('/login/link/check?stuff=1&user=weaverryan');
        $this->loginLinkHandler->expects($this->once())
            ->method('consumeLoginLink')
            ->with($request)
            ->willThrowException(new ExpiredLoginLinkException());

        $passport = $this->authenticator->authenticate($request);
        // trigger the user loader to try to load the user         $passport->getBadge(UserBadge::class)->getUser();
    }

    public function testMissingUser()
    {
        $this->expectException(InvalidLoginLinkAuthenticationException::class);
        $this->setUpAuthenticator();

        
$this->assertEquals($expectedMessage$actualEnvelopes[0]->getMessage());
    }

    /** * @dataProvider rejectedRedisEnvelopeProvider */
    public function testItRejectTheMessageIfThereIsAMessageDecodingFailedException(array $redisEnvelope)
    {
        $this->expectException(MessageDecodingFailedException::class);

        $serializer = $this->createMock(PhpSerializer::class);
        $serializer->method('decode')->willThrowException(new MessageDecodingFailedException());

        $connection = $this->createMock(Connection::class);
        $connection->method('get')->willReturn($redisEnvelope);
        $connection->expects($this->once())->method('reject');

        $receiver = new RedisReceiver($connection$serializer);
        $receiver->get();
    }

    public static function redisEnvelopeProvider(): \Generator
    {
        
public function testItThrowsATransportExceptionIfItCannotSendTheMessage()
    {
        $this->expectException(TransportException::class);
        $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->method('publish')->with($encoded['body']$encoded['headers'])->willThrowException(new \AMQPException());

        $sender = new AmqpSender($connection$serializer);
        $sender->send($envelope);
    }
}
public function testNoCredentialLeakageWhenConnectionFails()
    {
        $this->expectException(\AMQPException::class);
        $this->expectExceptionMessage('Could not connect to the AMQP server. Please verify the provided DSN.');
        $factory = new TestAmqpFactory(
            $amqpConnection = $this->createMock(\AMQPConnection::class),
            $amqpChannel = $this->createMock(\AMQPChannel::class),
            $amqpQueue = $this->createMock(\AMQPQueue::class),
            $amqpExchange = $this->createMock(\AMQPExchange::class)
        );

        $amqpConnection->method('connect')->willThrowException(
            new \AMQPConnectionException('Oups.')
        );

        $connection = Connection::fromDsn('amqp://user:secretpassword@localhost', []$factory);
        $connection->channel();
    }

    public function testNoCaCertOnSslConnectionFromDsn()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('No CA certificate has been provided. Set "amqp.cacert" in your php.ini or pass the "cacert" parameter in the DSN to use SSL. Alternatively, you can use amqp:// to use without SSL.');

        


    public function testHandleWithException()
    {
        $this->expectException(\RuntimeException::class);
        $this->expectExceptionMessage('Thrown from next middleware.');
        $busId = 'command_bus';

        $middleware = $this->createMock(MiddlewareInterface::class);
        $middleware->expects($this->once())
            ->method('handle')
            ->willThrowException(new \RuntimeException('Thrown from next middleware.'))
        ;

        $stopwatch = $this->createMock(Stopwatch::class);
        $stopwatch->expects($this->once())->method('isStarted')->willReturn(true);
        // Start/stop are expected to be called once, as an exception is thrown by the next callable         $stopwatch->expects($this->once())
            ->method('start')
            ->with($this->matches('"%sMiddlewareInterface%s" on "command_bus"'), 'messenger.middleware')
        ;
        $stopwatch->expects($this->once())
            ->method('stop')
            

  public function testIsValidWithAccessDenied() {
    $this->account->expects($this->once())
      ->method('hasPermission')
      ->with('link to any page')
      ->willReturn(FALSE);
    $this->accessUnawareRouter->expects($this->never())
      ->method('match');
    $this->accessAwareRouter->expects($this->once())
      ->method('match')
      ->with('/test-path')
      ->willThrowException(new AccessDeniedHttpException());
    $this->pathProcessor->expects($this->once())
      ->method('processInbound')
      ->willReturnArgument(0);

    $this->assertFalse($this->pathValidator->isValid('test-path'));
  }

  /** * @covers ::isValid * @covers ::getPathAttributes */
  
->willReturn($stmt);

        $connection = new Connection([]$driverConnection);
        $doctrineEnvelope = $connection->get();
        $this->assertNull($doctrineEnvelope);
    }

    public function testItThrowsATransportExceptionIfItCannotAcknowledgeMessage()
    {
        $this->expectException(TransportException::class);
        $driverConnection = $this->getDBALConnectionMock();
        $driverConnection->method('delete')->willThrowException(new DBALException());

        $connection = new Connection([]$driverConnection);
        $connection->ack('dummy_id');
    }

    public function testItThrowsATransportExceptionIfItCannotRejectMessage()
    {
        $this->expectException(TransportException::class);
        $driverConnection = $this->getDBALConnectionMock();
        $driverConnection->method('delete')->willThrowException(new DBALException());

        
$schema->expects($this->any())
      ->method('tableExists')
      ->willReturnMap($table_map);

    $connection = $this->getMockBuilder('Drupal\Core\Database\Connection')
      ->disableOriginalConstructor()
      ->getMock();

    if ($exception) {
      $connection->expects($this->any())
        ->method('query')
        ->willThrowException($exception);
    }
    else {
      $connection->expects($this->any())
        ->method('query')
        ->willReturn($statement);
    }

    $connection->expects($this->any())
      ->method('schema')
      ->willReturn($schema);

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