Exception example

return $this->memcached->delete($key);
    }

    /** * {@inheritDoc} * * @return never */
    public function deleteMatching(string $pattern)
    {
        throw new Exception('The deleteMatching method is not implemented for Memcached. You must select File, Redis or Predis handlers to use it.');
    }

    /** * {@inheritDoc} */
    public function increment(string $key, int $offset = 1)
    {
        if ($this->config['raw']) {
            return false;
        }

        

    public function getPluginByName($pluginName)
    {
        /** @var Plugin|null $plugin */
        $plugin = $this->pluginRepository->findOneBy([
            'name' => $pluginName,
            'capabilityEnable' => 1,
        ]);

        if ($plugin === null) {
            throw new Exception(sprintf('Unknown plugin "%s".', $pluginName));
        }

        return $plugin;
    }

    /** * Returns a certain plugin by plugin id. * * @return Shopware_Components_Plugin_Bootstrap|null */
    public function getPluginBootstrap(Plugin $plugin)
    {
static::assertEmpty($testRecord->context['additionalData']);
    }

    public function testWriteMailSendLogEvents(): void
    {
        $handler = new TestHandler();
        $logger = new Logger('testlogger', [$handler]);

        $service = new LoggingService('test', $logger);

        $service->logFlowEvent(
            new FlowLogEvent(TestFlowBusinessEvent::EVENT_NAME, new MailErrorEvent($this->context, 400, new Exception()))
        );

        $records = $handler->getRecords();

        static::assertCount(1, $records);
        $testRecord = $records[0];

        static::assertEquals(MailErrorEvent::NAME, $testRecord->message);
        static::assertEquals('test', $testRecord->context['environment']);
        static::assertEquals(Level::Error, $testRecord->level);
    }

    
/** * Deletes items from the cache store matching a given pattern. * * @param string $pattern Cache items glob-style pattern * * @return int|never * * @throws Exception */
    public function deleteMatching(string $pattern)
    {
        throw new Exception('The deleteMatching method is not implemented.');
    }
}

function smarty_function_controllerAction($params, Enlight_Template_Default $template)
{
    /** @var Enlight_Controller_Front $front */
    $front = Shopware()->Front();
    $request = $front->Request();

    if (empty($request) || !$request instanceof Enlight_Controller_Request_Request) {
        $e = new Exception(
            'Controller view helper requires a valid request object in the front controller instance'
        );
        throw $e;
    }

    return preg_replace('/[^a-zA-Z0-9]/', '', $request->getActionName());
}

        /** @var Theme $theme */
        foreach ($themes as $theme) {
            if ($theme->getExtend() === null) {
                continue;
            }

            $template = $this->repository->findOneBy([
                'template' => $theme->getTemplate(),
            ]);
            if (!$template instanceof Template) {
                throw new Exception(sprintf('Template of theme %s not found', $theme->getTemplate()));
            }

            $parent = $this->repository->findOneBy([
                'template' => $theme->getExtend(),
            ]);
            if (!$parent instanceof Template) {
                throw new Exception(sprintf('Parent %s of theme %s not found', $theme->getExtend()$theme->getTemplate()));
            }

            $template->setParent($parent);

            

        if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1')strlen($this->data))) {
            return false; // end of input         }
        $yy_global_pattern = "/\G(#|;)|\G(\\[)|\G(\\])|\G(=)|\G([ \t\r]+)|\G(\n)|\G([0-9]*[a-zA-Z_]\\w*)|\G([\S\s])/iS";

        do {
            if ($this->mbstring_overload ? preg_match($yy_global_patternmb_substr($this->data, $this->counter,2000000000,'latin1')$yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, 0, $this->counter)) {
                $yysubmatches = $yymatches;
                $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns                 if (!count($yymatches)) {
                    throw new Exception('Error: lexing failed because a rule matched' .
                        ' an empty string. Input "' . substr($this->data,
                        $this->counter, 5) . '... state START');
                }
                next($yymatches); // skip global match                 $this->token = key($yymatches); // token number                 if ($tokenMap[$this->token]) {
                    // extract sub-patterns for passing to lex function                     $yysubmatches = array_slice($yysubmatches$this->token + 1,
                        $tokenMap[$this->token]);
                } else {
                    $yysubmatches = array();
                }

        $migrationClassName = sprintf('%s\\Migrations\\Migration%d', $this->plugin->getName()$result['1']);
        if (!class_exists($migrationClassName, false)) {
            $file = $migrationPath . '/' . $result['0'];
            require $file;
        }

        try {
            /** @var AbstractPluginMigration $migrationClass */
            $migrationClass = new $migrationClassName($this->getConnection());
        } catch (Exception $e) {
            throw new Exception('Could not instantiate Object');
        }

        $this->validateMigration($migrationClass$result);

        return $migrationClass;
    }

    protected function insertMigration(AbstractMigration $migration): void
    {
        $sql = 'REPLACE s_plugin_schema_version (plugin_name, version, start_date, name) VALUES (:plugin_name, :version, :date, :name)';
        $stmt = $this->connection->prepare($sql);
        
/** * @throws Exception * * @return void */
    public function addEncoder(PasswordEncoderInterface $encoder)
    {
        $name = strtolower(trim($encoder->getName()));

        if (isset($this->encoder[$name])) {
            throw new Exception(sprintf('Encoder by name %s already registered', $name));
        }

        $this->encoder[$name] = $encoder;
    }

    /** * @param string $name * * @throws Exception * * @return PasswordEncoderInterface */
public function getThemeByTemplate(Template $template)
    {
        $namespace = 'Shopware\\Themes\\' . $template->getTemplate();
        /** @var class-string<Theme> $class */
        $class = $namespace . '\\Theme';

        $directory = $this->pathResolver->getDirectory($template);

        $file = $directory . DIRECTORY_SEPARATOR . 'Theme.php';

        if (!file_exists($file)) {
            throw new Exception(sprintf('Theme directory %s contains no Theme.php', $directory));
        }

        require_once $file;

        return new $class();
    }

    /** * Resolves the passed directory to a theme class. * Returns a new instance of the \Shopware\Theme * * @throws Exception * * @return Theme */
public function testPriority(): void
    {
        $handler = new ShippingMethodPriceExceptionHandler();

        static::assertSame(0, $handler->getPriority());
    }

    public function testSqlExceptionHandled(): void
    {
        $message = 'An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry \'foo-bar\' for key \'shipping_method_price.uniq.shipping_method_quantity_start\'';

        $e = new \Exception($message);

        $handler = new ShippingMethodPriceExceptionHandler();
        $result = $handler->matchException($e);

        static::assertInstanceOf(ShippingException::class$result);
        static::assertSame('Shipping method price quantity already exists.', $result->getMessage());
    }

    public function testNonAlignedSqlExceptionNotHandled(): void
    {
        $message = 'An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry \'foo-bar\' for key \'product.uniq.product.product_number__version_id\'';
        

    private const SUBJECT_CUSTOMER = 'customer-0';
    private const PRODUCT_KEY = 'product-10';

    public function setupWithLogin(): void
    {
        $this->ids = clone Fixtures::getIds();
        $this->context = Fixtures::context([
            SalesChannelContextService::CUSTOMER_ID => $this->ids->get(self::SUBJECT_CUSTOMER),
        ]);
        if (!$this->context->getCustomerId()) {
            throw new \Exception('Customer not logged in for bench tests which require it!');
        }

        $this->getContainer()->get(Connection::class)->beginTransaction();
    }

    #[Bench\BeforeMethods(['setup'])]     #[Bench\Groups(['custom-pricing'])]     #[Bench\Assert('mean(variant.time.avg) < 30ms +/- 5ms')]     public function bench_load_product_detail_route_with_logged_out_user(): void
    {
        $this->getContainer()->get(ProductDetailRoute::class)
            
$activeAppsLoader->reset();

        static::assertEquals($expected$activeAppsLoader->getActiveApps());
    }

    public function testLoadAppsFromLocal(): void
    {
        $connection = $this->createMock(Connection::class);
        $connection
            ->expects(static::once())
            ->method('fetchAllAssociative')
            ->willThrowException(new \Exception('test'));

        $appLoader = $this->createMock(AbstractAppLoader::class);

        $xmlFile = __DIR__ . '/_fixtures/manifest.xml';

        $appLoader
            ->method('load')
            ->willReturn([
                Manifest::createFromXmlFile($xmlFile),
            ]);

        

    public function factory($backendName)
    {
        if (!isset($this->cdnConfig['adapters'][$backendName])) {
            throw new Exception(sprintf('Configuration "%s" not found', $backendName));
        }

        // Filesystem         $config = $this->cdnConfig['adapters'][$backendName];
        $adapter = $this->getAdapter($config);
        $filesystem = new Filesystem($adapter['visibility' => AdapterInterface::VISIBILITY_PUBLIC]);

        // Strategy         $strategyFactory = $this->container->get(\Shopware\Bundle\MediaBundle\Strategy\StrategyFactory::class);
        $strategyName = isset($config['strategy']) ? $config['strategy'] : $this->cdnConfig['strategy'];
        $strategy = $strategyFactory->factory($strategyName);

        


    /** * Validates the ConfigSet component. * If no name or values configured the component throws an exception. * * @throws Exception */
    public function validate()
    {
        if (!$this->name) {
            throw new Exception('Each config set requires a configured name!');
        }
        if (!$this->values || !\is_array($this->values)) {
            throw new Exception(sprintf('Config set %s defined without values array.', $this->name));
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.