/** * @param string $class * * @return LazyLoadingInterface|PageObject */ public function instantiate($class) { $decoratedFactory = $this->decoratedFactory; $initializer = function (&$wrappedObject, LazyLoadingInterface $proxy, $method, array $parameters, &$initializer) use($class, $decoratedFactory) { $initializer = null; $wrappedObject = $decoratedFactory->instantiate($class); return true; }; return $this->proxyFactory->createProxy($class, $initializer); }
function it_delegates_instantiation_to_the_decorated_factory(AbstractLazyFactory $proxyFactory, LazyLoadingInterface $proxy, PageObject $pageObject, Factory $decoratedFactory) { $decoratedFactory->create('Acme\\Page')->willReturn($pageObject); $proxyFactory->createProxy(Argument::any(), Argument::that(function ($callback) use($proxy, $pageObject) { $wrappedObject = new \stdClass(); $initializer = function () { }; $result = $callback($wrappedObject, $proxy->getWrappedObject(), null, array(), $initializer); if ($wrappedObject !== $pageObject->getWrappedObject()) { throw new \LogicException('Expected the proxy to be overwritten with the actual object'); } if (null !== $initializer) { throw new \LogicException('Expected the initializer callback to be set to null'); } return $result; }))->shouldBeCalled(); $this->create('Acme\\Page'); }