public function testProxyGenerationMethodsExistingConstructor()
 {
     $factory = new ProxyGeneratorFactory();
     $generator = $factory->getLookupMethodProxyGenerator("LookupMethodProxyGeneratorTest");
     $bean = new Bean();
     $bean->class = '\\MooDev\\Bounce\\Proxy\\ProxyTestClass';
     $bean->name = "out";
     $bean->lookupMethods = array(new LookupMethod("getInner", "in"), new LookupMethod("getThingy", "thingy"));
     $class = $generator->loadProxy($bean);
     $rClass = new \ReflectionClass($class);
     $constructor = $rClass->getConstructor();
     $this->assertEquals(4, $constructor->getNumberOfParameters());
     $this->assertEquals(2, $constructor->getNumberOfRequiredParameters());
     $this->assertEquals(4, count($rClass->getMethods()));
     $params = $constructor->getParameters();
     reset($params);
     each($params);
     /**
      * @var \ReflectionParameter $param
      */
     list($key, $param) = each($params);
     $this->assertEquals("a", $param->getName());
     list($key, $param) = each($params);
     $this->assertEquals("b", $param->getName());
     $this->assertEquals("foo", @$param->getDefaultValue());
     list($key, $param) = each($params);
     $this->assertEquals("cat", $param->getName());
     $this->assertEquals("harhar", @$param->getDefaultValue());
     $this->assertTrue($rClass->hasMethod("getA"));
     $this->assertTrue($rClass->hasProperty("a"));
     $this->assertTrue($rClass->hasProperty("b"));
     $this->assertTrue($rClass->hasProperty("c"));
     $this->assertTrue($rClass->hasMethod("getInner"));
     $this->assertEquals(0, $rClass->getMethod("getInner")->getNumberOfParameters());
     $this->assertTrue($rClass->hasMethod("getThingy"));
     $this->assertEquals(0, $rClass->getMethod("getThingy")->getNumberOfParameters());
     $mockBeanFactory = m::mock('\\MooDev\\Bounce\\Context\\BeanFactory');
     $mockBeanFactory->shouldReceive("createByName")->with("in")->andReturn("wheeee");
     $mockBeanFactory->shouldReceive("createByName")->with("thingy")->andReturn("wooooo");
     /**
      * @var ProxyTestClass $instance
      */
     $instance = $rClass->newInstance($mockBeanFactory, "z", "x", "k");
     $this->assertEquals("z", $instance->a);
     $this->assertEquals("x", $instance->b);
     $this->assertEquals("k", $instance->c);
     $this->assertEquals("z", $instance->getA());
     $this->assertEquals("wheeee", $instance->getInner());
     $this->assertEquals("wooooo", $instance->getThingy());
 }
Ejemplo n.º 2
0
 protected function importContext(Context $context)
 {
     $lookupProxyGenerator = null;
     if ($this->proxyGeneratorFactory) {
         $lookupProxyGenerator = $this->proxyGeneratorFactory->getLookupMethodProxyGenerator($context->uniqueId);
     }
     $configurator = $this->registerConfigurator();
     $configBeanFactory = new SymfonyConfigBeanFactory($configurator, $lookupProxyGenerator);
     foreach ($context->childContexts as $childContext) {
         $this->importContext($childContext);
     }
     foreach ($context->beans as $bean) {
         if (empty($bean->name)) {
             // TODO: wat.
             continue;
         }
         $this->container->setDefinition($bean->name, $configBeanFactory->create($bean));
     }
     $this->container->addResource(new FileResource($context->fileName));
 }
Ejemplo n.º 3
0
 /**
  * Returns an instance of the BeanFactory, using the globally shared version
  * if applicable.
  *
  * @param Config\Context $context
  * @param bool $globalShared [true] whether to use a global shared factory if possible
  * @return \MooDev\Bounce\Context\BeanFactory
  */
 public static function getInstance(Config\Context $context, $globalShared = true)
 {
     if (!isset(self::$proxyGeneratorFactory)) {
         self::$proxyGeneratorFactory = new ProxyGeneratorFactory();
     }
     $uniqueId = null;
     //Do we have a unique ID? If not, then we're not shared.
     if ($globalShared && !is_null($context->uniqueId)) {
         $uniqueId = $context->uniqueId;
         if (isset(self::$_globalFactories[$uniqueId])) {
             return self::$_globalFactories[$uniqueId];
         }
     }
     $factory = new BeanFactory();
     $factory->_contextConfig = $context;
     $factory->_lookupMethodProxyGenerator = self::$proxyGeneratorFactory->getLookupMethodProxyGenerator($uniqueId);
     if ($uniqueId !== null) {
         //Remember this in the shared cache
         self::$_globalFactories[$context->uniqueId] = $factory;
     }
     return $factory;
 }