public function closure() { \filter\Filter::on(isset($this) ? $this : get_called_class(), __FUNCTION__, func_get_args(), function ($chain) { return function () { $rand = rand(2, 5); $rand++; return $rand; }; }); }
/** * The default `'quit'` filter. */ protected function _quit() { return Filter::on($this, 'quit', [$this->suite()->passed()], function ($chain, $success) { }); }
Stub::on($subclass)->method('::filterable', function () { return Filter::on(get_called_class(), 'filterable', func_get_args(), function ($chain, $message) { return "Hello {$message}"; }); }); Filter::apply($class, 'filterable', 'spec.be_prefix'); Filter::apply($subclass, 'filterable', 'spec.my_prefix'); expect($subclass::filterable('World!'))->toBe('Hello Be My World!'); expect($subclass::filterable('World!'))->toBe('Hello Be My World!'); }); it("invalidates parent cached filters", function () { $class = $this->class; $subclass = Stub::classname(['extends' => $class]); Stub::on($subclass)->method('::filterable', function () { return Filter::on(get_called_class(), 'filterable', func_get_args(), function ($chain, $message) { return "Hello {$message}"; }); }); Filter::apply($class, 'filterable', 'spec.be_prefix'); Filter::apply($subclass, 'filterable', 'spec.my_prefix'); expect($subclass::filterable('World!'))->toBe('Hello Be My World!'); Filter::apply($subclass, 'filterable', 'spec.no_chain'); expect($subclass::filterable('World!'))->toBe("No Man's My World!"); }); it("throws an Exception when trying to apply a filter using an unexisting closure", function () { $class = $this->class; $closure = function () use($class) { Filter::apply($class, 'filterable', 'spec.unexisting_closure'); }; expect($closure)->toThrow(new Exception('Undefined filter `spec.unexisting_closure`.')); });
protected function dump() { \filter\Filter::on(isset($this) ? $this : get_called_class(), __FUNCTION__, func_get_args(), function ($chain) { return String::dump('Hello'); }); }