1. Go to this page and download the library: Download directorytree/runnable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
directorytree / runnable example snippets
$response = ProcessPayment::run($order);
use function Pest\Laravel\post;
use function Pest\Laravel\actingAs;
it('can pay for an order', function () {
$user = User::factory()->create();
$order = Order::factory()->for($user)->create([
'total' => 5000,
'status' => 'pending',
]);
actingAs($user);
$action = ProcessPayment::fake(
new PaymentResponse(success: true),
);
post(route('orders.pay', $order))
->assertRedirect(route('orders.show', $order));
$action->shouldHaveReceived('handle')->once();
});
namespace App\Actions;
use App\Models\Order;
use Stripe\StripeClient;
use App\Payments\PaymentResponse;
use DirectoryTree\Runnable\Runnable;
class ProcessPayment
{
use Runnable;
public function __construct(
protected StripeClient $stripe
) {}
public function handle(Order $order): PaymentResponse
{
$payment = $this->stripe->paymentIntents->create([
// ...
]);
return new PaymentResponse(success: $payment->status === 'succeeded');
}
}
use App\Actions\ProcessPayment;
$response = ProcessPayment::run($order);
use App\Actions\ProcessPayment;
use DirectoryTree\Runnable\Facades\Run;
$response = Run::execute(ProcessPayment::class, $order);
use App\Actions\ProcessPayment;
use function DirectoryTree\Runnable\run;
$response = run(ProcessPayment::class, $order);
use App\Actions\ProcessPayment;
use DirectoryTree\Runnable\Facades\Run;
$response = Run::execute(new ProcessPayment($stripe), $order);
use App\Actions\ProcessPayment;
use function DirectoryTree\Runnable\run;
$response = run(new ProcessPayment($stripe), $order);
use App\Actions\ProcessPayment;
use function DirectoryTree\Runnable\run;
$fake = ProcessPayment::fake($response);
$result = run(new ProcessPayment($stripe), $order);
expect($result)->toBe($response);
$fake->shouldHaveReceived('handle')->with($order)->once();
$fake->shouldNotHaveReceived('handle');
use DirectoryTree\Runnable\Facades\Run;
$fake = Run::fake(ProcessPayment::class, $response);