How to test Symfony Process inside a queued job?

Posted 1 year ago by swalker

Hello there,

I am relatively new to testing and so... I have this inside a queued job:

    public function handle()
    {
        ...

        $output .= $this->runCommand("ls -la");
        ...
    }
    /**
     * Runs a command
     *
     * @param        $cmd
     * @param string $cwd
     *
     * @return string
     */
    private function runCommand($cmd, $cwd = '')
    {
        
        $process = new Process(trim($cmd), $cwd);
        $process->setTimeout(300);
        $process->run();
        $process->wait();
        
        if ( ! $process->isSuccessful()) {
            throw new ProcessFailedException($process);
        }
        
        return trim($process->getOutput());
    }

How can I test this without actually running the command?

Is it ok if I mock the Proccess class inside my code?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.