Skip to content

Scaffold Commands

Commands for generating binding and test code.

eventflow make:guard

Generate a guard binding class.

bash
eventflow make:guard "cart is not empty"

# With test
eventflow make:guard "cart is not empty" --test

# Custom namespace
eventflow make:guard "cart is not empty" --namespace="App\\Checkout\\Guards"

Output: Creating Guard

$ eventflow make:guard "cart is not empty"

EventFlow v1.0.0

Creating guard binding...

  Pattern:   'cart is not empty'
  Class:     CartIsNotEmptyGuard
  Namespace: App\Order\Guards
  File:      src/Order/Guards/CartIsNotEmptyGuard.php

────────────────────────────────────────

<?php

declare(strict_types=1);

namespace App\Order\Guards;

use EventFlow\Attributes\Guard;
use EventFlow\Behavior\GuardBehavior;

#[Guard('cart is not empty')]
class CartIsNotEmptyGuard extends GuardBehavior
{
    public function __invoke(array $context): bool
    {
        // TODO: Implement guard logic
        //
        // Example:
        //   $cart = $context['cart'] ?? null;
        //   return $cart !== null && count($cart->items) > 0;

        return false;
    }
}

────────────────────────────────────────
✓ Guard created: src/Order/Guards/CartIsNotEmptyGuard.php

Next steps:
  1. Implement the guard logic
  2. Create tests: eventflow make:binding-test "cart is not empty"
  3. Run tests: eventflow test:binding "cart is not empty"

Output: With Test (--test)

$ eventflow make:guard "cart is not empty" --test

EventFlow v1.0.0

Creating guard binding with test...

────────────────────────────────────────
GUARD
────────────────────────────────────────

  Pattern:   'cart is not empty'
  Class:     CartIsNotEmptyGuard
  File:      src/Order/Guards/CartIsNotEmptyGuard.php

  ✓ Created

────────────────────────────────────────
TEST
────────────────────────────────────────

  Class:     CartIsNotEmptyGuardTest
  File:      tests/Order/Guards/CartIsNotEmptyGuardTest.php

  ✓ Created

────────────────────────────────────────
✓ Guard and test created

Files created:
  → src/Order/Guards/CartIsNotEmptyGuard.php
  → tests/Order/Guards/CartIsNotEmptyGuardTest.php

Next steps:
  1. Implement the guard logic
  2. Run tests: eventflow test:binding "cart is not empty"

eventflow make:action

Generate an action binding class.

bash
eventflow make:action "send confirmation email"

# With test
eventflow make:action "send confirmation email" --test

Output: Creating Action

$ eventflow make:action "send confirmation email" --test

EventFlow v1.0.0

Creating action binding with test...

────────────────────────────────────────
ACTION
────────────────────────────────────────

  Pattern:   'send confirmation email'
  Class:     SendConfirmationEmailAction
  File:      src/Order/Actions/SendConfirmationEmailAction.php

<?php

declare(strict_types=1);

namespace App\Order\Actions;

use EventFlow\Attributes\Action;
use EventFlow\Attributes\TestedBy;
use EventFlow\Behavior\ActionBehavior;
use Tests\Order\Actions\SendConfirmationEmailActionTest;

#[Action('send confirmation email')]
#[TestedBy(SendConfirmationEmailActionTest::class)]
class SendConfirmationEmailAction extends ActionBehavior
{
    public function __invoke(array $context): array
    {
        // TODO: Implement action logic
        //
        // Example:
        //   $customer = $context['customer'] ?? null;
        //   if ($customer) {
        //       // Send email
        //   }

        return []; // Return context updates
    }
}

  ✓ Created

────────────────────────────────────────
TEST
────────────────────────────────────────

<?php

declare(strict_types=1);

namespace Tests\Order\Actions;

use PHPUnit\Framework\TestCase;
use App\Order\Actions\SendConfirmationEmailAction;
use EventFlow\Testing\Attributes\Tests;

#[Tests('send confirmation email')]
class SendConfirmationEmailActionTest extends TestCase
{
    private SendConfirmationEmailAction $action;

    protected function setUp(): void
    {
        $this->action = new SendConfirmationEmailAction();
    }

    public function test_executes_successfully(): void
    {
        $context = [
            // TODO: Add test context
        ];

        $result = ($this->action)($context);

        $this->assertIsArray($result);
    }
}

  ✓ Created

────────────────────────────────────────
✓ Action and test created

eventflow make:binding-test

Generate a test class for a binding pattern.

bash
eventflow make:binding-test "cart is not empty"

# Link to existing binding
eventflow make:binding-test "cart is not empty" --link
$ eventflow make:binding-test "cart is not empty" --link

EventFlow v1.0.0

Creating binding test...

  Finding binding for 'cart is not empty'...
    → Found: App\Order\Guards\CartNotEmptyGuard

────────────────────────────────────────
TEST CLASS
────────────────────────────────────────

<?php

declare(strict_types=1);

namespace Tests\Order\Guards;

use PHPUnit\Framework\TestCase;
use App\Order\Guards\CartNotEmptyGuard;
use EventFlow\Testing\Attributes\Tests;

#[Tests('cart is not empty')]
class CartNotEmptyGuardTest extends TestCase
{
    private CartNotEmptyGuard $guard;

    protected function setUp(): void
    {
        $this->guard = new CartNotEmptyGuard();
    }

    public function test_returns_false_when_context_is_empty(): void
    {
        $context = [];

        $result = ($this->guard)($context);

        $this->assertFalse($result);
    }

    public function test_returns_true_when_condition_is_met(): void
    {
        $context = [
            // TODO: Set up context for true case
        ];

        $result = ($this->guard)($context);

        $this->assertTrue($result);
    }
}

────────────────────────────────────────
BINDING UPDATE
────────────────────────────────────────

  Adding #[TestedBy] to CartNotEmptyGuard...

  Before:
    #[Guard('cart is not empty')]
    class CartNotEmptyGuard

  After:
    #[Guard('cart is not empty')]
    #[TestedBy(CartNotEmptyGuardTest::class)]
    class CartNotEmptyGuard

  ✓ Updated

────────────────────────────────────────
✓ Test created and linked

Files:
  Created: tests/Order/Guards/CartNotEmptyGuardTest.php
  Updated: src/Order/Guards/CartNotEmptyGuard.php

Run tests: eventflow test:binding "cart is not empty"

eventflow make:missing

Generate all missing bindings for a flow file.

bash
eventflow make:missing order.flow

# With tests
eventflow make:missing order.flow --test

# Dry run
eventflow make:missing order.flow --dry-run

Output: Creating Missing Bindings

$ eventflow make:missing order.flow --test

EventFlow v1.0.0

Analyzing order.flow...

  Missing bindings found:
    → 2 guards
    → 1 action

────────────────────────────────────────
CREATING BINDINGS
────────────────────────────────────────

1. Guard: 'payment is authorized'
   ────────────────────────────────────
   Binding: src/Order/Guards/PaymentIsAuthorizedGuard.php
   Test:    tests/Order/Guards/PaymentIsAuthorizedGuardTest.php
   ✓ Created

2. Guard: 'inventory is available'
   ────────────────────────────────────
   Binding: src/Order/Guards/InventoryIsAvailableGuard.php
   Test:    tests/Order/Guards/InventoryIsAvailableGuardTest.php
   ✓ Created

3. Action: 'reserve inventory'
   ────────────────────────────────────
   Binding: src/Order/Actions/ReserveInventoryAction.php
   Test:    tests/Order/Actions/ReserveInventoryActionTest.php
   ✓ Created

────────────────────────────────────────
✓ All missing bindings created

  Files created: 6
    → 3 binding classes
    → 3 test classes

Next steps:
  1. Implement binding logic
  2. Run tests: eventflow test order.flow --with-bindings

Released under the MIT License.