2019-12-21 10:41:38 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Fakes;
|
|
|
|
|
2019-12-29 11:49:31 +08:00
|
|
|
use Blessing\Filter as BaseFilter;
|
2019-12-21 10:41:38 +08:00
|
|
|
use PHPUnit\Framework\Assert;
|
|
|
|
|
|
|
|
class Filter extends BaseFilter
|
|
|
|
{
|
|
|
|
protected $applied = [];
|
|
|
|
|
|
|
|
public function apply(string $hook, $init, $args = [])
|
|
|
|
{
|
|
|
|
$this->applied[$hook] = array_merge([$init], $args);
|
|
|
|
|
|
|
|
return parent::apply($hook, $init, $args);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function fake(): Filter
|
|
|
|
{
|
2019-12-29 11:49:31 +08:00
|
|
|
$fake = resolve(Filter::class);
|
2019-12-21 10:41:38 +08:00
|
|
|
|
|
|
|
app()->instance(BaseFilter::class, $fake);
|
|
|
|
|
|
|
|
return $fake;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function assertApplied(string $hook, $predicate = null)
|
|
|
|
{
|
|
|
|
Assert::assertArrayHasKey(
|
|
|
|
$hook, $this->applied,
|
|
|
|
"Expected Filter '$hook' was not applied."
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!empty($predicate)) {
|
|
|
|
Assert::assertTrue(
|
|
|
|
call_user_func_array($predicate, $this->applied[$hook]),
|
|
|
|
"Arguments of Filter '$hook' does not satisfies the predicate."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|