Skip to content

Conversation

@yondifon
Copy link

What:

  • Bug Fix
  • New Feature

Description:

The toUseTrait expectation was failing to detect traits in inheritance scenarios. When a class extends another class that uses a trait, toUseTrait would incorrectly return false.

Problem:

use Illuminate\Foundation\Queue\Queueable;

abstract class Job
{
    use Queueable;
}

class ProcessPayment extends Job
{
    // Inherits Queueable trait from Job
}

arch('that jobs are queued properly')
    ->expect('App\Jobs')
    ->toUseTrait('Illuminate\Foundation\Queue\Queueable'); // Failed

Root cause: Only checked getTraitNames() which returns directly used traits, not inherited ones.

Solution: Updated to use ReflectionClass->getTraits() and walk the inheritance chain with getParentClass(). Also handles nested traits.

After fix:

arch('that jobs are queued properly')
    ->expect('App\Jobs')
    ->expect('App\Jobs')->toUseTrait('Illuminate\Foundation\Queue\Queueable'); // Now passes

# Also works with other common Laravel patterns:
arch('that jobs serialize models properly')
    ->expect('App\Jobs')
    ->toUseTrait('Illuminate\Queue\SerializesModels');

Added test coverage for direct usage, inheritance, and nested traits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant