public function testBeforeCallReturnValueDoesNotOverrideDefaultReturnValue() { $interceptor = new ReturnBeforeCallInterceptor(); InterceptorCache::registerInterceptor($interceptor, function ($x) { return true; }); $proxy = $this->builder->build(new ReflectionClass('Tmont\\Phroxy\\Tests\\ClassToBeProxied')); self::assertEquals('bar', $proxy->bar()); }
/** * Registers an interceptor for any resolved type that matches the filter * expression * * This method is merely a wrapper for {@link InterceptorCache::registerInterceptor()}. * * @uses InterceptorCache::registerInterceptor() * @param Interceptor $interceptor Interceptor implementation to register * @param Closure $matcher Predicate that takes a ReflectionMethod as an argument and returns a boolean * @returns Container */ public function registerInterceptor(Interceptor $interceptor, Closure $matcher) { InterceptorCache::registerInterceptor($interceptor, $matcher); return $this; }
public function testAddInterceptorToCache() { $interceptor = $this->getMock('Tmont\\Phroxy\\Interceptor'); $this->container->registerInterceptor($interceptor, function ($x) { return true; }); self::assertEquals(1, count(InterceptorCache::getInterceptors(new ReflectionMethod($interceptor, 'onBeforeMethodCall')))); }