private function buildPolicy($method, callable $fn) { if (!method_exists('\\Shmock\\Policy', $method)) { throw new \InvalidArgumentException("{$method} does not exist on policies"); } $builder = new ClassBuilder(); $builder->setExtends("\\Shmock\\Policy"); $builder->addMethod($method, function (Invocation $i) use($fn) { return $i->callWith($fn); }, ['$className', '$methodName', '$value', '$static']); $clazz = $builder->create(); return new $clazz(); }