/** * @param Prototype $prototype */ public function applyTo(Prototype $prototype) { foreach ($this->methods as $domain => $methods) { if (false === $prototype->canReach($domain)) { continue; } foreach ($methods as $alias => $method) { $prototype->{$alias} = $method; } } }
function it_can_apply_methods_to_prototype(Prototype $prototype, Method $method1, Method $method2, Method $method3) { $prototype->canReach('doctrine')->willReturn(true); $prototype->canReach('router')->willReturn(false); $prototype->__call('__set', ['getMethod1', $method1])->shouldBeCalled(); $prototype->__call('__set', ['getMethod3', $method3])->shouldBeCalled(); $this->addMethod('getMethod1', $method1, 'doctrine'); $this->addMethod('getMethod2', $method2, 'router'); $this->addMethod('getMethod3', $method3, 'doctrine'); $this->applyTo($prototype); }