hasExceptions example


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();

        $e->add('tax_provider', new \Exception('bar'));

        static::assertTrue($e->hasExceptions());
        static::assertSame('There were 1 errors while fetching taxes from providers: ' . \PHP_EOL . 'Tax provider \'tax_provider\' threw an exception: bar' . \PHP_EOL, $e->getMessage());
        


    public function getErrorCode(): string
    {
        return self::ERROR_CODE;
    }

    private function updateMessage(): void
    {
        $message = '';

        if (!$this->hasExceptions()) {
            return;
        }

        foreach ($this->exceptions as $provider => $exceptions) {
            foreach ($exceptions as $exception) {
                $message .= \sprintf(
                    'Tax provider \'%s\' threw an exception: %s' . \PHP_EOL,
                    $provider,
                    $exception->getMessage()
                );
            }
        }
Home | Imprint | This part of the site doesn't use cookies.