setOutput example

/** * @var resource */
    private $output;

    private int $stackLevel = 0;

    public function __construct(HtmlDumper $dumper = null)
    {
        $this->dumper = $dumper ?? new HtmlDumper();
        $this->dumper->setOutput($this->output = fopen('php://memory', 'r+'));
    }

    public function enter(Profile $profile): void
    {
        ++$this->stackLevel;
    }

    public function leave(Profile $profile): void
    {
        if (0 === --$this->stackLevel) {
            $this->dumper->setOutput($this->output = fopen('php://memory', 'r+'));
        }
if (!\is_string($rootDir)) {
            throw new RuntimeException('Parameter kernel.root_dir has to be an string');
        }

        $source = $input->getOption('source');
        if (!\is_string($source)) {
            throw new RuntimeException('Option "source" needs to be a string');
        }

        $sourceDir = $rootDir . '/' . $source . '/';

        $databaseLoader->setOutput($output);
        $databaseLoader->loadToDatabase($sourceDir$force);

        // Import plugin snippets         if ($input->getOption('include-plugins')) {
            $pluginRepository = $this->container->get('shopware.model_manager')->getRepository(Plugin::class);

            /** @var Plugin[] $plugins */
            $plugins = $pluginRepository->findBy(['active' => true]);

            $pluginDirectories = $this->container->getParameter('shopware.plugin_directories');

            
if (!$this->resolver instanceof OptionsResolver) {
            throw new \Exception(self::class D '::configure must be called before running the load method');
        }

        $_SERVER['APP_ENV'] = 'test';

        if (isset($_SERVER['DATABASE_URL'])) {
            $url = $_SERVER['DATABASE_URL'];
        }

        $bootstrapper = (new TestBootstrapper())
            ->setOutput(new ConsoleOutput())
            ->setForceInstall(static::parseEnvVar('FORCE_INSTALL', true))
            ->setForceInstallPlugins(static::parseEnvVar('FORCE_INSTALL_PLUGINS', true))
            ->setPlatformEmbedded(static::parseEnvVar('PLATFORM_EMBEDDED'))
            ->setBypassFinals(static::parseEnvVar('BYPASS_FINALS'))
            ->setEnableCommercial(static::parseEnvVar('ENABLE_COMMERCIAL'))
            ->setLoadEnvFile(static::parseEnvVar('LOAD_ENV_FILE', true))
            ->setProjectDir($_ENV['PROJECT_DIR'] ?? null)
            ->bootstrap();

        (new Fixtures())->load(__DIR__ . '/data.json');

        
private string $charset = '';

    /** * @param callable|resource|string|null $output A line dumper callable, an opened stream or an output path, defaults to static::$defaultOutput * @param string|null $charset The default character encoding to use for non-UTF8 strings * @param int $flags A bit field of static::DUMP_* constants to fine tune dumps representation */
    public function __construct($output = null, string $charset = null, int $flags = 0)
    {
        $this->flags = $flags;
        $this->setCharset($charset ?: \ini_get('php.output_encoding') ?: \ini_get('default_charset') ?: 'UTF-8');
        $this->setOutput($output ?: static::$defaultOutput);
        if (!$output && \is_string(static::$defaultOutput)) {
            static::$defaultOutput = $this->outputStream;
        }
    }

    /** * Sets the output destination of the dumps. * * @param callable|resource|string|null $output A line dumper callable, an opened stream or an output path * * @return callable|resource|string|null The previous output destination */
->addOption('stop-on-error', null, InputOption::VALUE_NONE, 'Abort indexing if an error occurs')
        ;
    }

    /** * {@inheritdoc} */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $helper = new ConsoleProgressHelper($output);

        $this->evaluationHelper->setOutput($output);
        $this->evaluationHelper->setActive(!$input->getOption('no-evaluation'));
        $this->evaluationHelper->setStopOnError($input->getOption('stop-on-error'));

        foreach ($this->getShops($input$output) as $shop) {
            $output->writeln("\n## Indexing shop " . $shop->getName() . ' ##');
            $this->shopIndexer->index($shop$helper$input->getOption('index'));
        }

        return 0;
    }

    

    public function onCommand(ConsoleCommandEvent $event)
    {
        $output = $event->getOutput();
        if ($output instanceof ConsoleOutputInterface) {
            $output = $output->getErrorOutput();
        }

        $this->setOutput($output);
    }

    /** * After a command has been executed, it disables the output. * * @return void */
    public function onTerminate(ConsoleTerminateEvent $event)
    {
        $this->close();
    }

    
/** * {@inheritdoc} */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var EsBackendIndexer $indexer */
        $indexer = $this->container->get('shopware_es_backend.indexer');

        $helper = new ConsoleProgressHelper($output);
        $evaluation = $this->container->get(\Shopware\Bundle\ESIndexingBundle\Console\EvaluationHelperInterface::class);
        $evaluation->setOutput($output)
            ->setActive(!$input->getOption('no-evaluation'))
            ->setStopOnError($input->getOption('stop-on-error'));

        $indexer->index($helper);

        return 0;
    }
}
private string $charset = '';

    /** * @param callable|resource|string|null $output A line dumper callable, an opened stream or an output path, defaults to static::$defaultOutput * @param string|null $charset The default character encoding to use for non-UTF8 strings * @param int $flags A bit field of static::DUMP_* constants to fine tune dumps representation */
    public function __construct($output = null, string $charset = null, int $flags = 0)
    {
        $this->flags = $flags;
        $this->setCharset($charset ?: \ini_get('php.output_encoding') ?: \ini_get('default_charset') ?: 'UTF-8');
        $this->setOutput($output ?: static::$defaultOutput);
        if (!$output && \is_string(static::$defaultOutput)) {
            static::$defaultOutput = $this->outputStream;
        }
    }

    /** * Sets the output destination of the dumps. * * @param callable|resource|string $output A line dumper callable, an opened stream or an output path * * @return callable|resource|string The previous output destination */
throw new RuntimeException('Parameter kernel.root_dir has to be an string');
        }

        $folder = $input->getArgument('folder');
        if (!\is_string($folder)) {
            throw new RuntimeException('Argument "folder" needs to be a string');
        }

        $folder = $rootDir . '/' . $folder . '/';

        $databaseLoader = $this->container->get(DatabaseHandler::class);
        $databaseLoader->setOutput($output);
        $databaseLoader->removeFromDatabase($folder);

        return 0;
    }
}
$view->display_handler->setOption('style', $style);
    $row = $view->display_handler->getOption('row');
    $row['type'] = 'test_row';
    $view->display_handler->setOption('row', $row);
    $view->initDisplay();
    $view->initStyle();
    // Reinitialize the style as it supports row plugins now.     $view->style_plugin->init($view$view->display_handler);
    $this->assertInstanceOf(RowTest::class$view->rowPlugin);

    $random_text = $this->randomMachineName();
    $view->rowPlugin->setOutput($random_text);

    $output = $view->preview();
    $output = $renderer->renderRoot($output);
    $this->assertStringContainsString($random_text(string) $output);

    // Test without row plugin support.     $view = Views::getView('test_view');
    $view->setDisplay();
    $style = $view->display_handler->getOption('style');
    $style['type'] = 'test_style';
    $view->display_handler->setOption('style', $style);
    
chmod($dir, 0777);
            umask($old);
        }
        if (!is_writable($dir)) {
            $output->writeln('<error>Output dir ' . $input->getOption('file') . ' is not writable, aborting</error>');

            return 1;
        }

        /** @var \Shopware\Components\Snippet\DatabaseHandler $databaseLoader */
        $databaseLoader = $this->container->get(\Shopware\Components\Snippet\DatabaseHandler::class);
        $databaseLoader->setOutput($output);
        $databaseLoader->dumpFromDatabase($input->getOption('target')$input->getArgument('locale'));

        return 0;
    }
}
->expects($this->any())
            ->method('getVerbosity')
            ->willReturn(OutputInterface::VERBOSITY_DEBUG)
        ;
        $output
            ->expects($this->once())
            ->method('write')
            ->with("16:21:54 <fg=green>INFO </> <comment>[app]</> My info message\n")
        ;

        $handler = new ConsoleHandler(null, false);
        $handler->setOutput($output);

        $infoRecord = RecordFactory::create(Logger::INFO, 'My info message', 'app', datetime: new \DateTimeImmutable('2013-05-29 16:21:54'));

        $this->assertTrue($handler->handle($infoRecord), 'The handler finished handling the log as bubble is false.');
    }

    public function testLogsFromListeners()
    {
        $output = new BufferedOutput();
        $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);

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