/** * * @param object $instance * @param MetadataClass $metadataClass */ private function invokeOtherMethods($instance, MetadataClass $metadataClass) { foreach ($metadataClass->getMethods() as $method) { if ($method->getName() === '__construct') { continue; } call_user_func_array([$instance, $method->getName()], $this->getMethodArguments($method)); } }
public function testGetInvalidTypeException() { $metadataClass = new MetadataClass('standalone', 'Asset\\StandaloneClass'); $metadataMethod = new MetadataMethod('__construct'); $metadataMethod->addArgument('unknown', 'param1'); $metadataMethod->addArgument(MetadataMethod::PRIMITIVE_TYPE, 'param2'); $metadataClass->registerInvoke($metadataMethod); $metadataMethod = new MetadataMethod('setParam3'); $metadataMethod->addArgument(MetadataMethod::PRIMITIVE_TYPE, 'data'); $metadataClass->registerInvoke($metadataMethod); $di = new DependencyInjection(); $di->register($metadataClass); $exception = null; try { $di->get('standalone'); } catch (\Exception $e) { $exception = $e; } $this->assertInstanceOf(InvalidTypeException::class, $exception); }
/** * * @param string $name * @param Config $classNode * @param bool $singleton * @return MetadataClass */ private function getMetadataClass($name, Config $classNode, $singleton = true) { $metadataClass = new MetadataClass($name, $classNode->getAttribute('class'), $singleton); foreach ($classNode->getNodes('method') as $methodNode) { $metadataMethod = $this->getMetadataDependencyMethod($methodNode); $metadataClass->registerInvoke($metadataMethod); } return $metadataClass; }