.
This commit is contained in:
commit
a5ce423afe
30 changed files with 1807 additions and 0 deletions
47
tests/Aspects/TrackingAspect.php
Normal file
47
tests/Aspects/TrackingAspect.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Aspects;
|
||||
|
||||
use Attribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_METHOD)]
|
||||
class TrackingAspect
|
||||
{
|
||||
public static array $calls = [];
|
||||
|
||||
public function before(object|string $target, mixed ...$args): void
|
||||
{
|
||||
self::$calls[] = ['event' => 'before', 'args' => $args];
|
||||
}
|
||||
|
||||
public function after(object|string $target, mixed $result): mixed
|
||||
{
|
||||
self::$calls[] = ['event' => 'after', 'result' => $result];
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function clearCalls(): void
|
||||
{
|
||||
self::$calls = [];
|
||||
}
|
||||
|
||||
public static function getLastBefore(): ?array
|
||||
{
|
||||
foreach (array_reverse(self::$calls) as $call) {
|
||||
if ($call['event'] === 'before') {
|
||||
return $call;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getLastAfter(): ?array
|
||||
{
|
||||
foreach (array_reverse(self::$calls) as $call) {
|
||||
if ($call['event'] === 'after') {
|
||||
return $call;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue