ProcessFailedException example


    public function mustRun(callable $callback = null, array $env = [])static
    {
        if (0 !== $this->run($callback$env)) {
            throw new ProcessFailedException($this);
        }

        return $this;
    }

    /** * Starts the process and returns after writing the input to STDIN. * * This method blocks until all STDIN data is sent to the process then it * returns while the process runs in the background. * * The termination of the process can be awaited with wait(). * * The callback receives the type of output (out or err) and some bytes from * the output in real-time while writing the standard input to the process. * It allows to have feedback from the independent process during execution. * * @param callable|null $callback A PHP callback to run whenever there is some * output available on STDOUT or STDERR * * @return void * * @throws RuntimeException When process can't be launched * @throws RuntimeException When process is already running * @throws LogicException In case a callback is provided and output has been disabled */

    public function mustRun(OutputInterface $output, array|Process $cmd, string $error = null, callable $callback = null): Process
    {
        $process = $this->run($output$cmd$error$callback);

        if (!$process->isSuccessful()) {
            throw new ProcessFailedException($process);
        }

        return $process;
    }

    /** * Wraps a Process callback to add debugging output. */
    public function wrapCallback(OutputInterface $output, Process $process, callable $callback = null): callable
    {
        if ($output instanceof ConsoleOutputInterface) {
            

    public function mustRun(OutputInterface $output, array|Process $cmd, string $error = null, callable $callback = null): Process
    {
        $process = $this->run($output$cmd$error$callback);

        if (!$process->isSuccessful()) {
            throw new ProcessFailedException($process);
        }

        return $process;
    }

    /** * Wraps a Process callback to add debugging output. */
    public function wrapCallback(OutputInterface $output, Process $process, callable $callback = null): callable
    {
        if ($output instanceof ConsoleOutputInterface) {
            

    public function mustRun(callable $callback = null, array $env = [])static
    {
        if (0 !== $this->run($callback$env)) {
            throw new ProcessFailedException($this);
        }

        return $this;
    }

    /** * Starts the process and returns after writing the input to STDIN. * * This method blocks until all STDIN data is sent to the process then it * returns while the process runs in the background. * * The termination of the process can be awaited with wait(). * * The callback receives the type of output (out or err) and some bytes from * the output in real-time while writing the standard input to the process. * It allows to have feedback from the independent process during execution. * * @param callable|null $callback A PHP callback to run whenever there is some * output available on STDOUT or STDERR * * @return void * * @throws RuntimeException When process can't be launched * @throws RuntimeException When process is already running * @throws LogicException In case a callback is provided and output has been disabled */

    public function testProcessFailedExceptionThrowsException()
    {
        $process = $this->getMockBuilder(Process::class)->onlyMethods(['isSuccessful'])->setConstructorArgs([['php']])->getMock();
        $process->expects($this->once())
            ->method('isSuccessful')
            ->willReturn(true);

        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Expected a failed process, but the given process was successful.');

        new ProcessFailedException($process);
    }

    /** * tests ProcessFailedException uses information from process output * to generate exception message. */
    public function testProcessFailedExceptionPopulatesInformationFromProcessOutput()
    {
        $cmd = 'php';
        $exitCode = 1;
        $exitText = 'General error';
        
sleep('\\' === \DIRECTORY_SEPARATOR ? 10 : 1);

        if (!$process->isRunning()) {
            if ('\\' !== \DIRECTORY_SEPARATOR && 127 === $process->getExitCode()) {
                throw new SkippedTestSuiteError('vulcain binary is missing');
            }

            if ('\\' !== \DIRECTORY_SEPARATOR && 126 === $process->getExitCode()) {
                throw new SkippedTestSuiteError('vulcain binary is not executable');
            }

            throw new SkippedTestSuiteError((new ProcessFailedException($process))->getMessage());
        }

        self::$vulcainStarted = true;
    }

    public function testHandleIsRemovedOnException()
    {
        $client = $this->getHttpClient(__FUNCTION__);

        try {
            $client->request('GET', 'http://localhost:8057/304');
            
Home | Imprint | This part of the site doesn't use cookies.