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(); }
/** * Helper function to add all called methods to the class builder * * @param \Shmock\ClassBuilder\ClassBuilder $builder * @param callable $resolveCall * @return \Shmock\ClassBuilder\ClassBuilder */ protected function addMethodsToBuilder(ClassBuilder $builder, callable $resolveCall) { foreach (array_unique($this->expectedStaticMethodCalls) as $methodCall) { $inspector = new MethodInspector($this->className, $methodCall); $builder->addStaticMethod($methodCall, $resolveCall, $inspector->signatureArgs()); } return $builder; }