TaxProviderExceptions example


        if ($context->getTaxState() === CartPrice::TAX_STATE_FREE) {
            return;
        }

        $taxProviders = $this->getTaxProviders($context);

        if ($taxProviders->count() === 0) {
            return;
        }

        $exceptions = new TaxProviderExceptions();

        $result = $this->buildTaxes(
            $taxProviders,
            $cart,
            $context,
            $exceptions
        );

        if (!$result) {
            $this->logger->error($exceptions->getMessage()['error' => $exceptions]);

            
/** * @package checkout * * @internal * * @covers \Shopware\Core\Checkout\Cart\Exception\TaxProviderExceptions */
class TaxProviderExceptionsTest extends TestCase
{
    public function testException(): void
    {
        $e = new TaxProviderExceptions();

        static::assertSame('CHECKOUT__TAX_PROVIDER_EXCEPTION', $e->getErrorCode());
        static::assertSame('There was an error while calculating taxes', $e->getMessage());
        static::assertFalse($e->hasExceptions());
        static::assertEmpty($e->getErrorsForTaxProvider('foo'));
    }

    public function testAddException(): void
    {
        $e = new TaxProviderExceptions();

        
TaxProviderDefinition::ENTITY_NAME,
            1,
            $collection,
            null,
            new Criteria(),
            Context::createDefaultContext()
        );

        $repo = static::createMock(EntityRepository::class);
        $repo->method('search')->willReturn($result);

        $e = new TaxProviderExceptions();
        $e->add(TestGenericExceptionTaxProvider::classnew \Exception('Test exception'));

        $logger = static::createMock(LoggerInterface::class);
        $logger
            ->expects(static::once())
            ->method('error')
            ->with('There were 1 errors while fetching taxes from providers: ' . \PHP_EOL . 'Tax provider \'Shopware\\Tests\\Unit\\Core\\Checkout\\Cart\\TaxProvider\\_fixtures\\TestGenericExceptionTaxProvider\' threw an exception: Test exception' . \PHP_EOL);

        $processor = new TaxProviderProcessor(
            $repo,
            $logger,
            
Home | Imprint | This part of the site doesn't use cookies.