Skip to content

Commit

Permalink
feat: implement type inclusion for expectFilter mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
badasswp committed Feb 1, 2025
1 parent 010d556 commit 34b2e0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion php/WP_Mock/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ public static function anyOf(): AnyOf
*/
public static function type(string $expected): Type
{
return Mockery::type($expected);
$type = Mockery::type($expected);
Filter::$objects[ $expected ] = spl_object_hash($type);

return $type;
}
}
11 changes: 11 additions & 0 deletions php/WP_Mock/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ abstract class Hook
/** @var array<mixed> collection of processors */
protected $processors = [];

/** @var array<mixed> collection of objects mapped to their Type hashes */
public static array $objects = [];

/**
* Hook constructor.
*
Expand Down Expand Up @@ -62,6 +65,14 @@ protected function safe_offset($value): string
}

if (is_object($value)){
if (! $value instanceof Type) {
$class = get_class($value);

if (isset(static::$objects[ $class ])) {
return static::$objects[ $class ];
}
}

return spl_object_hash($value);
}

Expand Down

0 comments on commit 34b2e0f

Please sign in to comment.