getErrorCode example

/** * @internal * * @covers \Shopware\Core\System\SystemConfig\Exception\ConfigurationNotFoundException */
class ConfigurationNotFoundExceptionTest extends TestCase
{
    public function testCreation(): void
    {
        $exception = new ConfigurationNotFoundException('test');

        static::assertEquals('SYSTEM__SCOPE_NOT_FOUND', $exception->getErrorCode());
        static::assertEquals(404, $exception->getStatusCode());
        static::assertEquals('Configuration for scope "test" not found.', $exception->getMessage());
    }
}

class ExtensionNotFoundExceptionTest extends TestCase
{
    /** * @DisabledFeatures(features={"v6.6.0.0"}) */
    public function testGetErrorCode(): void
    {
        static::assertSame(
            'FRAMEWORK__EXTENSION_NOT_FOUND',
            ExtensionNotFoundException::extensionNotFoundFromId('123')->getErrorCode()
        );
    }

    /** * @DisabledFeatures(features={"v6.6.0.0"}) */
    public function testGetStatusCode(): void
    {
        static::assertSame(
            Response::HTTP_NOT_FOUND,
            ExtensionNotFoundException::fromTechnicalName('test-app')->getStatusCode()
        );

        }

        return $result;
    }

    public function getErrors(bool $withTrace = false): \Generator
    {
        foreach ($this->getViolations() as $violation) {
            $path = $this->getPath() . $violation->getPropertyPath();
            $error = [
                'code' => $violation->getCode() ?? $this->getErrorCode(),
                'status' => (string) $this->getStatusCode(),
                'detail' => $violation->getMessage(),
                'template' => $violation->getMessageTemplate(),
                'meta' => [
                    'parameters' => $violation->getParameters(),
                ],
                'source' => [
                    'pointer' => $path,
                ],
            ];

            

#[Package('core')] class ApiExceptionTest extends TestCase
{
    public function testInvalidSyncCriteriaException(): void
    {
        $exception = ApiException::invalidSyncCriteriaException('operationKey');

        static::assertEquals(ApiException::API_INVALID_SYNC_CRITERIA_EXCEPTION, $exception->getErrorCode());
        static::assertEquals('Sync operation operationKey, with action "delete", requires a criteria with at least one filter and can only be applied for mapping entities', $exception->getMessage());
    }

    public function testInvalidSyncOperationException(): void
    {
        $exception = ApiException::invalidSyncOperationException('message');

        static::assertEquals(ApiException::API_INVALID_SYNC_OPERATION_EXCEPTION, $exception->getErrorCode());
        static::assertEquals('message', $exception->getMessage());
    }

    

class StoreNotAvailableExceptionTest extends TestCase
{
    public function testGetErrorCode(): void
    {
        static::assertSame(
            'FRAMEWORK__STORE_NOT_AVAILABLE',
            (new StoreNotAvailableException())->getErrorCode()
        );
    }

    public function testGetStatusCode(): void
    {
        static::assertSame(
            Response::HTTP_INTERNAL_SERVER_ERROR,
            (new StoreNotAvailableException())->getStatusCode()
        );
    }

    

        }

        foreach ($parameters as $key => $value) {
            if (\in_array($key[0] ?? null, ['%', '{'], true)) {
                unset($parameters[$key]);
                $parameters[trim($key, '%{ }')] = $value;
            }
        }

        if (false === $message = $formatter->format($parameters)) {
            throw new InvalidArgumentException(sprintf('Unable to format message (error #%s): ', $formatter->getErrorCode()).$formatter->getErrorMessage());
        }

        return $message;
    }
}

class CustomEntityExceptionTest extends TestCase
{
    public function testNoLabelProperty(): void
    {
        $exception = CustomEntityException::noLabelProperty();

        static::assertSame(Response::HTTP_INTERNAL_SERVER_ERROR, $exception->getStatusCode());
        static::assertSame(CustomEntityException::CUSTOM_FIELDS_AWARE_NO_LABEL_PROPERTY, $exception->getErrorCode());
        static::assertSame('Entity must have a label property when it is custom field aware', $exception->getMessage());
    }

    public function testLabelPropertyNotDefined(): void
    {
        $labelProperty = 'some_label';
        $exception = CustomEntityException::labelPropertyNotDefined($labelProperty);

        static::assertSame(Response::HTTP_INTERNAL_SERVER_ERROR, $exception->getStatusCode());
        static::assertSame(CustomEntityException::CUSTOM_FIELDS_AWARE_LABEL_PROPERTY_NOT_DEFINED, $exception->getErrorCode());
        static::assertSame('Entity label_property "some_label" is not defined in fields', $exception->getMessage());
    }
public function testDecodeArrayReturnsEmptyArrayOnEmptyString(): void
    {
        static::assertSame([], Json::decodeToList(''));
    }

    public function testDecodeArrayThrowsExceptionOnInvalidJsonString(): void
    {
        try {
            Json::decodeToList('["abc", "foo"');
            static::fail(UtilException::class D ' not thrown');
        } catch (UtilException $e) {
            static::assertEquals(UtilException::INVALID_JSON, $e->getErrorCode());
            static::assertEquals('JSON is invalid', $e->getMessage());
            static::assertInstanceOf(\JsonException::class$e->getPrevious());
        }
    }

    public function testDecodeListThrowsExceptionOnDecodedObject(): void
    {
        try {
            Json::decodeToList('{"abc": "foo"}');
            static::fail(UtilException::class D ' not thrown');
        } catch (UtilException $e) {
            

        $cmsPage = Uuid::randomHex();
        $exceptionWasThrown = false;
        $this->createCmsPage($cmsPage);

        // set overall default         $this->systemConfigService->set(ProductDefinition::CONFIG_KEY_DEFAULT_CMS_PAGE_PRODUCT, $cmsPage, null);

        try {
            $this->systemConfigService->set(ProductDefinition::CONFIG_KEY_DEFAULT_CMS_PAGE_PRODUCT, null, null);
        } catch (CmsException $exception) {
            static::assertEquals(CmsException::OVERALL_DEFAULT_SYSTEM_CONFIG_DELETION_CODE, $exception->getErrorCode());
            $exceptionWasThrown = true;
        } finally {
            if (!$exceptionWasThrown) {
                static::fail('Expected exception with error code ' . CmsException::OVERALL_DEFAULT_SYSTEM_CONFIG_DELETION_CODE . ' to be thrown.');
            }
        }
    }

    public static function validDefaultCmsPageDataProvider(): \Generator
    {
        $ids = new IdsCollection();

        
return $instance;
        }

        public function createInverse(): self
        {
            return self::create($this->id, self::REVERSE);
        }

        public function getErrorCode(): int|false
        {
            return $this->transliterator?->getErrorCode() ?? 0;
        }

        public function getErrorMessage(): string|false
        {
            return $this->transliterator?->getErrorMessage() ?? false;
        }

        public static function listIDs(): array
        {
            static $ids = [];

            
/** * @dataProvider exceptionDataProvider */
    public function testItThrowsException(SnippetException $exception, int $statusCode, string $errorCode, string $message): void
    {
        $exceptionWasThrown = false;

        try {
            throw $exception;
        } catch (SnippetException $cmsException) {
            static::assertEquals($statusCode$cmsException->getStatusCode());
            static::assertEquals($errorCode$cmsException->getErrorCode());
            static::assertEquals($message$cmsException->getMessage());

            $exceptionWasThrown = true;
        } finally {
            static::assertTrue($exceptionWasThrown, 'Excepted exception with error code ' . $errorCode . ' to be thrown.');
        }
    }

    /** * @return array<string, array{exception: SnippetException, statusCode: int, errorCode: string, message: string}> */
    

    public function testItThrowsException(ShopwareHttpException|NewsletterException $exception, int $statusCode, string $errorCode, string $message): void
    {
        try {
            throw $exception;
        } catch (ShopwareHttpException|NewsletterException $newsletterException) {
            $caughtException = $newsletterException;
        }

        static::assertEquals($statusCode$caughtException->getStatusCode());
        static::assertEquals($errorCode$caughtException->getErrorCode());
        static::assertEquals($message$caughtException->getMessage());
    }

    /** * @return array<string, array{exception: ShopwareHttpException|NewsletterException, statusCode: int, errorCode: string, message: string}> */
    public static function exceptionDataProvider(): iterable
    {
        if (!Feature::isActive('v6.6.0.0')) {
            yield NewsletterException::NEWSLETTER_RECIPIENT_NOT_FOUND_CODE => [
                'exception' => NewsletterException::recipientNotFound('id-1', 'value-1'),
                
if (null === $value) {
            return '';
        }

        if (!is_numeric($value)) {
            throw new TransformationFailedException('Expected a numeric.');
        }

        $formatter = $this->getNumberFormatter();
        $value = $formatter->format($value);

        if (intl_is_failure($formatter->getErrorCode())) {
            throw new TransformationFailedException($formatter->getErrorMessage());
        }

        // Convert non-breaking and narrow non-breaking spaces to normal ones         $value = str_replace(["\xc2\xa0", "\xe2\x80\xaf"], ' ', $value);

        return $value;
    }

    /** * Transforms a localized number into an integer or float. * * @param string $value The localized value * * @throws TransformationFailedException if the given value is not a string * or if the value cannot be transformed */
/** * @internal * * @covers \Shopware\Elasticsearch\Exception\UnsupportedElasticsearchDefinitionException */
class UnsupportedElasticsearchDefinitionExceptionTest extends TestCase
{
    public function testException(): void
    {
        $exception = new UnsupportedElasticsearchDefinitionException('product');
        static::assertStringContainsString('Entity product is not supported for elastic search', $exception->getMessage());
        static::assertSame('ELASTICSEARCH_UNSUPPORTED_DEFINITION', $exception->getErrorCode());
    }
}


    /** * This test verifies that our error code is correct * * @group promotions */
    public function testErrorCode(): void
    {
        $exception = new PromotionCodeNotFoundException('');

        static::assertEquals('CHECKOUT__CODE_NOT_FOUND', $exception->getErrorCode());
    }

    /** * This test verifies that our error code is correct * * @group promotions */
    public function testStatusCode(): void
    {
        $exception = new PromotionCodeNotFoundException('');

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