Readouble

Laravel 10.x プロセス

イントロダクションIntroduction

LaravelはSymfonyプロセスコンポーネントを核にした、表現力豊かで最小限のAPIを提供し、Laravelアプリケーションから便利に外部プロセスを呼び出せるようにしています。Laravelのプロセス機能は、最も一般的なユースケースと、素晴らしい開発者体験に重点を置いています。Laravel provides an expressive, minimal API around the Symfony Process component[https://symfony.com/doc/current/components/process.html], allowing you to conveniently invoke external processes from your Laravel application. Laravel's process features are focused on the most common use cases and a wonderful developer experience.

プロセスの起動Invoking Processes

プロセスを起動するには、Processファサードが提供しているrunメソッドとstartメソッドを利用します。run メソッドはプロセスを呼び出して、プロセスの実行が終了するのを待ちます。一方のstartメソッドは非同期プロセスの実行に使用します。このドキュメントでは、両方のアプローチを検討します。まず、基本的な同期プロセスを起動し、その結果を確認する方法を調べましょう。To invoke a process, you may use the run and start methods offered by the Process facade. The run method will invoke a process and wait for the process to finish executing, while the start method is used for asynchronous process execution. We'll examine both approaches within this documentation. First, let's examine how to invoke a basic, synchronous process and inspect its result:

use Illuminate\Support\Facades\Process;

$result = Process::run('ls -la');

return $result->output();

もちろん、runメソッドが返す、Illuminate\Contracts\Process\ProcessResultインスタンスは、プロセスの結果を調べるために使用できる多くの有用なメソッドを用意しています。Of course, the Illuminate\Contracts\Process\ProcessResult instance returned by the run method offers a variety of helpful methods that may be used to inspect the process result:

$result = Process::run('ls -la');

$result->successful();
$result->failed();
$result->exitCode();
$result->output();
$result->errorOutput();

例外を投げるThrowing Exceptions

プロセス結果が出て、終了コードが0より大きい(つまり失敗を表している)場合に、Illuminate\Process\Exceptions\ProcessFailedExceptionのインスタンスを投げたい場合は、throwthrowIfメソッドを使用してください。プロセスが失敗しなかった場合、プロセス結果のインスタンスを返します。If you have a process result and would like to throw an instance of Illuminate\Process\Exceptions\ProcessFailedException if the exit code is greater than zero (thus indicating failure), you may use the throw and throwIf methods. If the process did not fail, the process result instance will be returned:

$result = Process::run('ls -la')->throw();

$result = Process::run('ls -la')->throwIf($condition);

プロセスのオプションProcess Options

もちろん、プロセス起動の前に、そのプロセスの動作をカスタマイズする必要がある場合もあるでしょう。幸福なことに、Laravelでは、作業ディレクトリ、タイムアウト、環境変数など、様々なプロセス機能を調整できます。Of course, you may need to customize the behavior of a process before invoking it. Thankfully, Laravel allows you to tweak a variety of process features, such as the working directory, timeout, and environment variables.

作業ディレクトリパスWorking Directory Path

プロセスの作業ディレクトリを指定するには、pathメソッドを使用します。このメソッドを呼び出さない場合、プロセスは現在実行中のPHPスクリプトの作業ディレクトリを引き継ぎます。You may use the path method to specify the working directory of the process. If this method is not invoked, the process will inherit the working directory of the currently executing PHP script:

$result = Process::path(__DIR__)->run('ls -la');

入力Input

入力は、inputメソッドを使い、プロセスの「標準入力」から行えます。You may provide input via the "standard input" of the process using the input method:

$result = Process::input('Hello World')->run('cat');

タイムアウトTimeouts

デフォルトでプロセスは60秒以上実行されると、Illuminate\Process\Exceptions\ProcessTimedOutExceptionのインスタンスを投げます。しかし、timeoutメソッドでこの動作をカスタマイズできます。By default, processes will throw an instance of Illuminate\Process\Exceptions\ProcessTimedOutException after executing for more than 60 seconds. However, you can customize this behavior via the timeout method:

$result = Process::timeout(120)->run('bash import.sh');

もしくは、プロセスのタイムアウトを完全に無効にしたい場合は、foreverメソッドを呼びだしてください。Or, if you would like to disable the process timeout entirely, you may invoke the forever method:

$result = Process::forever()->run('bash import.sh');

idleTimeoutメソッドを使用すると、出力をまったく返さずにプロセスを実行できる最大秒数を指定できます。The idleTimeout method may be used to specify the maximum number of seconds the process may run without returning any output:

$result = Process::timeout(60)->idleTimeout(30)->run('bash import.sh');

環境変数Environment Variables

環境変数は、envメソッドでプロセスへ指定できます。起動したプロセスはシステムで定義したすべての環境変数を継承します。Environment variables may be provided to the process via the env method. The invoked process will also inherit all of the environment variables defined by your system:

$result = Process::forever()
            ->env(['IMPORT_PATH' => __DIR__])
            ->run('bash import.sh');

呼び出したプロセスから継承した環境変数を削除したい場合は、その環境変数にfalse値を指定してください。If you wish to remove an inherited environment variable from the invoked process, you may provide that environment variable with a value of false:

$result = Process::forever()
            ->env(['LOAD_PATH' => false])
            ->run('bash import.sh');

TTYモードTTY Mode

ttyメソッドを使用すると、プロセスのTTYモードを有効にできます。TTYモードはプロセスの入出力をプログラムの入出力と接続し、プロセスがVimやNanoのようなエディタをプロセスとして開くことができるようにします。The tty method may be used to enable TTY mode for your process. TTY mode connects the input and output of the process to the input and output of your program, allowing your process to open an editor like Vim or Nano as a process:

Process::forever()->tty()->run('vim');

プロセス出力Process Output

前の説明の通り、プロセスの出力には、プロセス結果のoutput(stdout)とerrorOutput(stderr)メソッドを使用してアクセスできます。As previously discussed, process output may be accessed using the output (stdout) and errorOutput (stderr) methods on a process result:

use Illuminate\Support\Facades\Process;

$result = Process::run('ls -la');

echo $result->output();
echo $result->errorOutput();

しかし、runメソッドの第2引数へクロージャを渡すと、リアルタイムに出力を収集することもできます。クロージャは2つの引数を取ります。出力の「タイプ」(stdoutまたはstderr)と出力文字列そのものです。However, output may also be gathered in real-time by passing a closure as the second argument to the run method. The closure will receive two arguments: the "type" of output (stdout or stderr) and the output string itself:

$result = Process::run('ls -la', function (string $type, string $output) {
    echo $output;
});

Laravelには、seeInOutputseeInErrorOutputメソッドもあり、指定文字列がプロセスの出力に含まれているかを判断できる、便利な方法を提供しています。Laravel also offers the seeInOutput and seeInErrorOutput methods, which provide a convenient way to determine if a given string was contained in the process' output:

if (Process::run('ls -la')->seeInOutput('laravel')) {
    // ...
}

プロセス出力の無効化Disabling Process Output

もし、あなたのプロセスが興味のない出力を大量に書き出すものであるなら、出力の取得を完全に無効化し、メモリを節約できます。これを行うには、プロセスをビルドするときに、quietlyメソッドを呼び出してください。If your process is writing a significant amount of output that you are not interested in, you can conserve memory by disabling output retrieval entirely. To accomplish this, invoke the quietly method while building the process:

use Illuminate\Support\Facades\Process;

$result = Process::quietly()->run('bash import.sh');

パイプラインPipelines

あるプロセスの出力を別のプロセスの入力にしたい場合があると思います。これはよく、あるプロセスの出力を別のプロセスへ"パイプ"すると呼んでいます。Processファサードが提供する、pipeメソッドで、これを簡単に実現できます。pipeメソッドは、パイプラインで接続したプロセスを同時に実行し、パイプラインの最後のプロセスの結果を返します。Sometimes you may want to make the output of one process the input of another process. This is often referred to as "piping" the output of a process into another. The pipe method provided by the Process facades makes this easy to accomplish. The pipe method will execute the piped processes synchronously and return the process result for the last process in the pipeline:

use Illuminate\Process\Pipe;
use Illuminate\Support\Facades\Process;

$result = Process::pipe(function (Pipe $pipe) {
    $pipe->command('cat example.txt');
    $pipe->command('grep -i "laravel"');
});

if ($result->successful()) {
    // ...
}

パイプラインを構成する個々のプロセスをカスタマイズする必要がない場合は、pipeメソッドにコマンド文字列の配列を渡すだけです。If you do not need to customize the individual processes that make up the pipeline, you may simply pass an array of command strings to the pipe method:

$result = Process::pipe([
    'cat example.txt',
    'grep -i "laravel"',
]);

pipeメソッドの第2引数へクロージャを渡すと、プロセスの出力をリアルタイムに収集できます。クロージャは2引数を取ります。出力の「タイプ」(stdoutstderr)と、出力文字列そのものです:The process output may be gathered in real-time by passing a closure as the second argument to the pipe method. The closure will receive two arguments: the "type" of output (stdout or stderr) and the output string itself:

$result = Process::pipe(function (Pipe $pipe) {
    $pipe->command('cat example.txt');
    $pipe->command('grep -i "laravel"');
}, function (string $type, string $output) {
    echo $output;
});

Laravelでは、パイプライン内の各プロセスに、asメソッドで文字列キーを割り当てることもできます。このキーは、pipeメソッドへ指定する出力クロージャにも渡され、出力がどのプロセスに属しているかを判定できます:Laravel also allows you to assign string keys to each process within a pipeline via the as method. This key will also be passed to the output closure provided to the pipe method, allowing you to determine which process the output belongs to:

$result = Process::pipe(function (Pipe $pipe) {
    $pipe->as('first')->command('cat example.txt');
    $pipe->as('second')->command('grep -i "laravel"');
})->start(function (string $type, string $output, string $key) {
    // …
});

非同期プロセスAsynchronous Processes

runメソッドは同期的にプロセスを起動する一方で、startメソッドは非同期的にプロセスを起動するため使用します。これにより、プロセスをバックグラウンドで実行している間、アプリケーションは他のタスクを実行し続けられます。プロセスを起動したら、runningメソッドを使用して、プロセスがまだ実行されているかを判定できます。While the run method invokes processes synchronously, the start method may be used to invoke a process asynchronously. This allows your application to continue performing other tasks while the process runs in the background. Once the process has been invoked, you may utilize the running method to determine if the process is still running:

$process = Process::timeout(120)->start('bash import.sh');

while ($process->running()) {
    // ...
}

$result = $process->wait();

お気づきでしょうが、waitメソッドを呼び出し、プロセスの実行終了を待ち、プロセスの実行結果インスタンスを取得できます。As you may have noticed, you may invoke the wait method to wait until the process is finished executing and retrieve the process result instance:

$process = Process::timeout(120)->start('bash import.sh');

// ...

$result = $process->wait();

プロセスIDとシグナルProcess IDs and Signals

idメソッドを使えば、オペレーティングシステムが割り当てた、実行中のプロセスのプロセスIDを取得できます。The id method may be used to retrieve the operating system assigned process ID of the running process:

$process = Process::start('bash import.sh');

return $process->id();

実行中のプロセスへ、「シグナル」を送るには、signalメソッドを使用します。定義済みのシグナル定数の一覧は、PHPドキュメントに記載されています。You may use the signal method to send a "signal" to the running process. A list of predefined signal constants can be found within the PHP documentation[https://www.php.net/manual/en/pcntl.constants.php]:

$process->signal(SIGUSR2);

非同期プロセス出力Asynchronous Process Output

非同期プロセスの実行中は、outputメソッドとerrorOutputメソッドを使用して、現在の出力全部へアクセスできます。しかし、 latestOutputlatestErrorOutputを使用すれば、最後に出力を取得した後に発生したプロセス出力にアクセスできます。While an asynchronous process is running, you may access its entire current output using the output and errorOutput methods; however, you may utilize the latestOutput and latestErrorOutput to access the output from the process that has occurred since the output was last retrieved:

$process = Process::timeout(120)->start('bash import.sh');

while ($process->running()) {
    echo $process->latestOutput();
    echo $process->latestErrorOutput();

    sleep(1);
}

runメソッドと同様、startメソッドの第2引数にクロージャを渡せば、非同期プロセスからリアルタイムに出力を収集できます。クロージャは2つの引数を受け取ります。出力の「タイプ」(stdoutまたはstderr)と出力文字列そのものです。Like the run method, output may also be gathered in real-time from asynchronous processes by passing a closure as the second argument to the start method. The closure will receive two arguments: the "type" of output (stdout or stderr) and the output string itself:

$process = Process::start('bash import.sh', function (string $type, string $output) {
    echo $output;
});

$result = $process->wait();

同時実行プロセスConcurrent Processes

またLaravelでは、同時実行の非同期プロセスのプールを簡単に管理でき、多くのタスクを簡単に同時実行できます。使用するには、poolメソッドを呼び出してください。これは、Illuminate\Process\Poolのインスタンスを受け取るクロージャを引数に取ります。Laravel also makes it a breeze to manage a pool of concurrent, asynchronous processes, allowing you to easily execute many tasks simultaneously. To get started, invoke the pool method, which accepts a closure that receives an instance of Illuminate\Process\Pool.

このクロージャの中で、プールに所属するプロセスを定義してください。プロセスプールをstartメソッドで開始すれば、runningメソッドにより実行中のプロセスのコレクションにアクセスできるようになります。Within this closure, you may define the processes that belong to the pool. Once a process pool is started via the start method, you may access the collection[/docs/{{version}}/collections] of running processes via the running method:

use Illuminate\Process\Pool;
use Illuminate\Support\Facades\Process;

$pool = Process::pool(function (Pool $pool) {
    $pool->path(__DIR__)->command('bash import-1.sh');
    $pool->path(__DIR__)->command('bash import-2.sh');
    $pool->path(__DIR__)->command('bash import-3.sh');
})->start(function (string $type, string $output, int $key) {
    // ...
});

while ($pool->running()->isNotEmpty()) {
    // ...
}

$results = $pool->wait();

ご覧のように、プール内のすべてのプロセスの実行が終了するのを待ち、その結果をwaitメソッドで取得できます。waitメソッドは、プール内の各プロセスのプロセス結果のインスタンスへキーでアクセスできる、配列アクセス可能なオブジェクトを返します。As you can see, you may wait for all of the pool processes to finish executing and resolve their results via the wait method. The wait method returns an array accessible object that allows you to access the process result instance of each process in the pool by its key:

$results = $pool->wait();

echo $results[0]->output();

もしくは便利な方法として、concurrentlyメソッドを使用し、非同期プロセスプールを起動し、その結果をすぐに待つこともできます。これは、PHPの配列分解機能と組み合わせると、特に表現力豊かな構文を利用できます。Or, for convenience, the concurrently method may be used to start an asynchronous process pool and immediately wait on its results. This can provide particularly expressive syntax when combined with PHP's array destructuring capabilities:

[$first, $second, $third] = Process::concurrently(function (Pool $pool) {
    $pool->path(__DIR__)->command('ls -la');
    $pool->path(app_path())->command('ls -la');
    $pool->path(storage_path())->command('ls -la');
});

echo $first->output();

名前付きプールアクセスNaming Pool Processes

プロセスプールの結果に数値キーによりアクセスするのは表現力が乏しいので、Laravelではasメソッドを使用し、プール内の各プロセスに文字列キーを割り当てできます。このキーは、startメソッドへ指定するクロージャにも渡され、出力がどのプロセスに属しているかを判断できます。Accessing process pool results via a numeric key is not very expressive; therefore, Laravel allows you to assign string keys to each process within a pool via the as method. This key will also be passed to the closure provided to the start method, allowing you to determine which process the output belongs to:

$pool = Process::pool(function (Pool $pool) {
    $pool->as('first')->command('bash import-1.sh');
    $pool->as('second')->command('bash import-2.sh');
    $pool->as('third')->command('bash import-3.sh');
})->start(function (string $type, string $output, string $key) {
    // ...
});

$results = $pool->wait();

return $results['first']->output();

プールプロセスIDとシグナルPool Process IDs and Signals

プロセスプールのrunningメソッドは、プール内で呼び出したすべてのプロセスのコレクションを提供するため、プール内のプロセスIDで簡単にアクセスできます。Since the process pool's running method provides a collection of all invoked processes within the pool, you may easily access the underlying pool process IDs:

$processIds = $pool->running()->each->id();

また、便利なように、プロセスプール上でsignalメソッドを呼び出すと、そのプール内のすべてのプロセスへシグナルを送ることができます。And, for convenience, you may invoke the signal method on a process pool to send a signal to every process within the pool:

$pool->signal(SIGUSR2);

テストTesting

Laravelの多くのサービスでは、テストを簡単かつ表現豊かに書くための機能を提供していますが、Laravelプロセスサービスも例外ではありません。Processファサードのfakeメソッドを使用すると、プロセスが呼び出されたときに、Laravelへスタブ/ダミーの結果を返すように指示できます。Many Laravel services provide functionality to help you easily and expressively write tests, and Laravel's process service is no exception. The Process facade's fake method allows you to instruct Laravel to return stubbed / dummy results when processes are invoked.

プロセスのFakeFaking Processes

LaravelのプロセスFake機能を調べるため、プロセスを起動するあるルートを想像してみましょう。To explore Laravel's ability to fake processes, let's imagine a route that invokes a process:

use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Route;

Route::get('/import', function () {
    Process::run('bash import.sh');

    return 'Import complete!';
});

このルートをテストする場合、引数なしでProcessファサードのfakeメソッドを呼び出すことで、起動したすべてのプロセスに対し、プロセス実行成功のFakeな結果を返すように、Laravelへ指示できます。さらに、与えられたプロセスが「実行済み(run)」であることをアサートすることもできます。When testing this route, we can instruct Laravel to return a fake, successful process result for every invoked process by calling the fake method on the Process facade with no arguments. In addition, we can even assert[#available-assertions] that a given process was "run":

<?php

namespace Tests\Feature;

use Illuminate\Process\PendingProcess;
use Illuminate\Contracts\Process\ProcessResult;
use Illuminate\Support\Facades\Process;
use Tests\TestCase;

class ExampleTest extends TestCase
{
    public function test_process_is_invoked(): void
    {
        Process::fake();

        $response = $this->get('/import');

        // シンプルなプロセスのアサート
        Process::assertRan('bash import.sh');

        // もしくは、プロセス設定を調べる
        Process::assertRan(function (PendingProcess $process, ProcessResult $result) {
            return $process->command === 'bash import.sh' &&
                   $process->timeout === 60;
        });
    }
}

説明してきたように、Processファサードのfakeメソッドを呼び出すと、Laravelは常にプロセス実行成功の結果を返すように指示し、出力は返しません。しかし、Processファサードのresultメソッドを使用すると、Fakeしたプロセスの出力と終了コードを簡単に指定できます。As discussed, invoking the fake method on the Process facade will instruct Laravel to always return a successful process result with no output. However, you may easily specify the output and exit code for faked processes using the Process facade's result method:

Process::fake([
    '*' => Process::result(
        output: 'Test output',
        errorOutput: 'Test error output',
        exitCode: 1,
    ),
]);

特定プロセスのFakeFaking Specific Processes

前の例でお気づきかもしれませんが、Processファサードのfakeメソッドへ配列を渡すことで、プロセスごとに異なるFakeの結果を指定できます。As you may have noticed in a previous example, the Process facade allows you to specify different fake results per process by passing an array to the fake method.

配列のキーは、フェイクしたいコマンドのパターンと、それに関連する結果を表してください。 *文字は、ワイルドカード文字として使用できます。Fakeしないプロセスコマンドは、実際に呼び出されます。Processファサードのresultメソッドを使用して、これらのコマンドのスタブ/フェイク結果を作成できます。The array's keys should represent command patterns that you wish to fake and their associated results. The * character may be used as a wildcard character. Any process commands that have not been faked will actually be invoked. You may use the Process facade's result method to construct stub / fake results for these commands:

Process::fake([
    'cat *' => Process::result(
        output: 'Test "cat" output',
    ),
    'ls *' => Process::result(
        output: 'Test "ls" output',
    ),
]);

Fakeしたプロセスの終了コードや、エラー出力をカスタマイズする必要がない場合は、Fakeプロセスの結果を単純な文字列として指定する方法が便利です。If you do not need to customize the exit code or error output of a faked process, you may find it more convenient to specify the fake process results as simple strings:

Process::fake([
    'cat *' => 'Test "cat" output',
    'ls *' => 'Test "ls" output',
]);

プロセス順序のFakeFaking Process Sequences

テスト対象のコードが同じコマンドにより複数のプロセスを呼び出す場合、各プロセスの呼び出しに対し異なるFakeプロセス結果を割り当てたい場合もあるでしょう。Processファサードのsequenceメソッドで、これを実現できます。If the code you are testing invokes multiple processes with the same command, you may wish to assign a different fake process result to each process invocation. You may accomplish this via the Process facade's sequence method:

Process::fake([
    'ls *' => Process::sequence()
                ->push(Process::result('First invocation'))
                ->push(Process::result('Second invocation')),
]);

非同期プロセスライフサイクルのFakeFaking Asynchronous Process Lifecycles

ここまでは主に、runメソッドを使用して、同期的に起動するプロセスのフェイクについて説明してきました。しかし、もしstartを使って呼び出す非同期処理とやりとりするコードをテストしようとするなら、Fakeの処理を記述するためにもっと洗練されたアプローチが必要になるでしょう。Thus far, we have primarily discussed faking processes which are invoked synchronously using the run method. However, if you are attempting to test code that interacts with asynchronous processes invoked via start, you may need a more sophisticated approach to describing your fake processes.

例として、非同期処理を操作する、以下のようなルートを想像してください。For example, let's imagine the following route which interacts with an asynchronous process:

use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Route;

Route::get('/import', function () {
    $process = Process::start('bash import.sh');

    while ($process->running()) {
        Log::info($process->latestOutput());
        Log::info($process->latestErrorOutput());
    }

    return 'Done';
});

この処理を適切にフェイクするためには、runningメソッドが、何回trueを返すか記述できるようにする必要があります。さらに、複数行の出力を順番に返すように指定したい場合もあります。これを実現するには、Processファサードのdescribeメソッドを使用します。To properly fake this process, we need to be able to describe how many times the running method should return true. In addition, we may want to specify multiple lines of output that should be returned in sequence. To accomplish this, we can use the Process facade's describe method:

Process::fake([
    'bash import.sh' => Process::describe()
            ->output('First line of standard output')
            ->errorOutput('First line of error output')
            ->output('Second line of standard output')
            ->exitCode(0)
            ->iterations(3),
]);

上の例を掘り下げてみましょう。outputメソッドとerrorOutputメソッドを使用して、順番に出力される行を複数指定しています。exitCodeメソッドを使い、Fakeプロセスの最終的な終了コードを指定しています。最後に、iterationsメソッドを使用して、runningメソッドがtrueを何回返すか、指定しています。Let's dig into the example above. Using the output and errorOutput methods, we may specify multiple lines of output that will be returned in sequence. The exitCode method may be used to specify the final exit code of the fake process. Finally, the iterations method may be used to specify how many times the running method should return true.

利用可能なアサートAvailable Assertions

以前に説明したように、Laravelは機能テスト用にいくつかのプロセスのアサートを提供しています。以下は、それぞれのアサートについての説明です。As previously discussed[#faking-processes], Laravel provides several process assertions for your feature tests. We'll discuss each of these assertions below.

assertRanassertRan

指定したプロセスが、起動されたことをアサートします。Assert that a given process was invoked:

use Illuminate\Support\Facades\Process;

Process::assertRan('ls -la');

assertRanメソッドは、クロージャを引数に取り、プロセスのインスタンスとプロセス結果を受け取りますので、プロセスの設定オプションを調べられます。このクロージャが、trueを返した場合、アサートは「パス」となります。The assertRan method also accepts a closure, which will receive an instance of a process and a process result, allowing you to inspect the process' configured options. If this closure returns true, the assertion will "pass":

Process::assertRan(fn ($process, $result) =>
    $process->command === 'ls -la' &&
    $process->path === __DIR__ &&
    $process->timeout === 60
);

assertRanクロージャに渡たす、$processIlluminate\Process\PendingProcessインスタンスであり、$resultIlluminate\Contracts\Process\ProcessResultインスタンスです。The $process passed to the assertRan closure is an instance of Illuminate\Process\PendingProcess, while the $result is an instance of Illuminate\Contracts\Process\ProcessResult.

assertDidntRunassertDidntRun

指定したプロセスが、起動されなかったことをアサートします。Assert that a given process was not invoked:

use Illuminate\Support\Facades\Process;

Process::assertDidntRun('ls -la');

assertRanメソッドと同様に、assertDidntRunメソッドもクロージャを引数に取ります。クロージャはプロセスのインスタンスとプロセス結果を受け取りますので、プロセスの設定オプションを調べられます。このクロージャが、trueを返すと、アサートは「失敗」します。Like the assertRan method, the assertDidntRun method also accepts a closure, which will receive an instance of a process and a process result, allowing you to inspect the process' configured options. If this closure returns true, the assertion will "fail":

Process::assertDidntRun(fn (PendingProcess $process, ProcessResult $result) =>
    $process->command === 'ls -la'
);

assertRanTimesassertRanTimes

指定したプロセスが、指定回数だけ起動されたことをバリデートします。Assert that a given process was invoked a given number of times:

use Illuminate\Support\Facades\Process;

Process::assertRanTimes('ls -la', times: 3);

assertRanTimesメソッドも、クロージャを引数に取り、プロセスのインスタンスとプロセス結果を受け取りますので、プロセスの設定オプションを調べられます。このクロージャが、true を返し、プロセスが指定した回数だけ起動された場合、アサーションは「パス」となります。The assertRanTimes method also accepts a closure, which will receive an instance of a process and a process result, allowing you to inspect the process' configured options. If this closure returns true and the process was invoked the specified number of times, the assertion will "pass":

Process::assertRanTimes(function (PendingProcess $process, ProcessResult $result) {
    return $process->command === 'ls -la';
}, times: 3);

未指定プロセスの防止Preventing Stray Processes

もし、個別のテストや、テストスイート全体を通して、呼び出されたすべてのプロセスがFakeされていることを確認したい場合は、 preventStrayProcessesメソッドを呼び出してください。このメソッドを呼び出すと、対応するFake結果を持たないプロセスは、実際のプロセスを開始するのではなく、例外を投げます。If you would like to ensure that all invoked processes have been faked throughout your individual test or complete test suite, you can call the preventStrayProcesses method. After calling this method, any processes that do not have a corresponding fake result will throw an exception rather than starting an actual process:

use Illuminate\Support\Facades\Process;

Process::preventStrayProcesses();

Process::fake([
    'ls *' => 'Test output...',
]);

// Fakeレスポンスが返る
Process::run('ls -la');

// 例外が投げられる
Process::run('bash import.sh');

章選択

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

テストコード表示
両コード表示
Pestのみ表示
PHPUnitのみ表示
和文変換

対象文字列と置換文字列を半角スペースで区切ってください。(最大5組各10文字まで)

本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作