PHP code example of havn / laravel-executable

1. Go to this page and download the library: Download havn/laravel-executable 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/ */

    

havn / laravel-executable example snippets


use Havn\Executable\QueueableExecutable;

class ProcessPayment
{
    use QueueableExecutable;

    public function __construct(
        private PaymentGateway $gateway,
    ) {}

    public function execute(Payment $payment): void
    {
        $this->gateway->charge($payment);
        
        $payment->update(['status' => 'completed']);
    }
}

// Sync — runs immediately, returns the result
ProcessPayment::sync()->execute($payment);

// Queue — dispatches to the queue
ProcessPayment::onQueue()->execute($payment);

// Prepare — returns a job without dispatching (for chains and batches)
$job = ProcessPayment::prepare()->execute($payment);

// Test — runs the real code in a testable context
ProcessPayment::test()->execute($payment);

ProcessPayment::onQueue('high-priority')
    ->delay(60)
    ->tries(3)
    ->execute($payment);

// Mock
ProcessPayment::mock()
    ->shouldExecute()
    ->with($payment)
    ->once();

// Spy
ProcessPayment::spy();
ProcessPayment::sync()->execute($payment);
ProcessPayment::assert()->executed()->with($payment);

// Queue assertions
Queue::fake();
ProcessPayment::onQueue()->execute($payment);
ProcessPayment::assert()->queued()->on('high-priority')->with($payment)->once();