trait InteractsWithAop

Provides a test helper for invoking a method through the AOP pipeline without relying on generated proxies.

In full application or Testbench integration tests, AOP proxies may already be generated and those tests should call the target method normally. This trait is for tests where the target is not already proxied, or where the goal is to exercise aspect pipeline behavior directly.

callWithAspects() invokes the same dispatcher used by generated proxies before calling the original method via reflection.

Methods

bool
isAopProxied(object $instance)

Determine if the given instance is already running through an AOP proxy.

mixed
callWithAspects(object $instance, string $method, array $arguments = [])

Call a method through the registered AOP aspect pipeline.

Details

at line 38
protected bool isAopProxied(object $instance)

Determine if the given instance is already running through an AOP proxy.

This is useful in tests that need to handle both execution paths explicitly. In isolated runs, the target class may be proxied during bootstrap and should be called normally. In larger test runs, load order may mean the original class was loaded before proxy generation, so the test must use callWithAspects() instead.

Keeping this check separate makes it clear whether the test is using the real proxy path or the manual pipeline path.

Parameters

object $instance

Return Value

bool

at line 55
protected mixed callWithAspects(object $instance, string $method, array $arguments = [])

Call a method through the registered AOP aspect pipeline.

Builds a ProceedingJoinPoint for the given instance and method, resolves matching aspects from AspectCollector, and executes them in priority order. The original method is called via reflection at the end of the pipeline. The instance must not already be proxied.

Parameters

object $instance

The object instance to call the method on

string $method

The method name to intercept

array $arguments

Method arguments as key => value pairs (parameter names as keys)

Return Value

mixed