/** * Test Clone */ public function testProtectedMethods() { $result = ConcreteSingleton::getInstance(); $reflection = new \ReflectionObject($result); $this->assertTrue($reflection->getMethod('__construct')->isProtected()); $this->assertTrue($reflection->getMethod('__clone')->isProtected()); }
/** * @param FormField $formField * @param KForm $form */ public function instanceMapFrom(FormField $formField, KForm $form) { $attribute = $formField->getFieldName(); $method = 'mappingFromFormField' . ucfirst($attribute); if ($this->instanceReflector->hasMethod($method)) { $methodReflector = $this->instanceReflector->getMethod($method); $parameters = array(); foreach ($methodReflector->getParameters() as $paramReflector) { switch (true) { case $paramReflector->getClass()->isSubclassOf(KForm::class): $parameters[] = $form; break; case $paramReflector->getClass()->isSubclassOf(FormField::class): $parameters[] = $formField; break; default: $parameters[] = $formField; break; } } call_user_func_array(array($this->instance, $method), $parameters); } else { $this->instance->{$attribute} = $formField->getValue(); } }
public function __call($method, $args) { if (!method_exists($this->entity, $method) or !is_callable(array($this->entity, $method))) { throw new OvoCommonException('Method ' . $method . ' not exists or is not public'); } $value = $this->reflectionObject->getMethod($method)->invokeArgs($this->entity, $args); if ($value == null) { $value = $this; } return $value; }
public function testProcessTaggedPlugins() { $r = new \ReflectionObject($this->compiler); $m = $r->getMethod('processTaggedDeployers'); $m->setAccessible(true); $m->invoke($this->compiler, $this->getFakeContainer()); $m = $r->getMethod('getDeployer'); $m->setAccessible(true); $result = $m->invoke($this->compiler, 'test'); $this->assertEquals($result, 'deployer.test'); }
/** * @see \Endeveit\Cache\Drivers\Redis::getRedisObject() */ public function testGetRedisObject() { $method = self::$driverReflection->getMethod('getRedisObject'); $method->setAccessible(true); $property = self::$driverReflection->getProperty('connectionsOptions'); $property->setAccessible(true); $options = $property->getValue(self::$driver); $this->assertCount(2, $options); foreach (array_keys($options) as $key) { $this->assertInstanceOf('Redis', $method->invoke(self::$driver, $key)); } }
public function runController($cName, $aName, $params) { $theController = new $cName(); $reflection_object = new ReflectionObject($theController); if ($reflection_object->hasMethod('before_action')) { $reflection_object->getMethod('before_action')->invoke($theController); } call_user_func_array(array($theController, $aName), $params); if ($reflection_object->hasMethod('after_action')) { $reflection_object->getMethod('after_action')->invoke($theController); } }
public function remap() { $ci =& get_instance(); $method = $ci->uri->rsegment(2); $parameters = array_slice($ci->uri->rsegment_array(), 2); $reflection = new ReflectionObject($ci); if ($reflection->hasMethod($method)) { $reflection->getMethod($method)->invokeArgs($ci, $parameters); } else { array_splice($parameters, 0, 0, $method); $reflection->getMethod("index")->invokeArgs($ci, $parameters); } }
public function __construct() { $this->context = AgaviContext::getInstance(); $this->parser = new AppKitFormatParserUtil(); $p =& $this->parser; $p->registerNamespace('xmlfn', AppKitFormatParserUtil::TYPE_METHOD); $ref = new ReflectionObject($this); // Register some methods $p->registerMethod('xmlfn', 'author', array(&$this, $ref->getMethod('valueAuthor'))); $p->registerMethod('xmlfn', 'instance', array(&$this, $ref->getMethod('valueDefaultInstance'))); $p->registerMethod('xmlfn', 'pagerMaxItems', array(&$this, $ref->getMethod('pagerMaxItems'))); $p->registerMethod('xmlfn', 'autoRefreshTime', array(&$this, $ref->getMethod('autoRefreshTime'))); }
public function testLockReleased() { $locker = new FileLockStrategy(__DIR__ . '/../../../../../app/cache/queue-test.bin'); $locker->clear(); $rLocker = new \ReflectionObject($locker); $method = $rLocker->getMethod('getFile'); $method->setAccessible(true); $file = $method->invoke($locker); $this->assertTrue(is_resource($file), true); $method2 = $rLocker->getMethod('releaseFile'); $method2->setAccessible(true); $method2->invokeArgs($locker, [$file]); $file = $method->invoke($locker); $this->assertTrue(is_resource($file), true); }
public function testNoConstructor() { $obj = Singleton::getInstance(); $refl = new \ReflectionObject($obj); $meth = $refl->getMethod('__construct'); $this->assertTrue($meth->isPrivate()); }
/** * Test build path. */ public function testBuildPath() { $reflection_object = new \ReflectionObject($this->client); $reflection_method = $reflection_object->getMethod('buildPath'); $reflection_method->setAccessible(TRUE); $this->assertEquals($reflection_method->invoke($this->client), 'HNK2IC/F_jM8Zls30dL/guid/-/2849493'); }
public static function execute($commande, $params) { session_start(); $endpoint=new static(); $commande = "API_".$commande; $endpointReflx = new ReflectionObject($endpoint); $methodReflx = $endpointReflx->getMethod($commande); try{ $result =$methodReflx->invokeArgs($endpoint, $params); $result = [ 'status'=>'success', 'value'=>$result ]; } catch(ErrorException $ex) { $result = [ 'status'=>'error', 'value'=>$ex->getMessage() ]; } session_commit(); return $result; }
public function testFilterResponseConvertsCookies() { $client = new Client(new TestHttpKernel()); $r = new \ReflectionObject($client); $m = $r->getMethod('filterResponse'); $m->setAccessible(true); $expected = array( 'foo=bar; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly', 'foo1=bar1; expires=Sun, 15 Feb 2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly' ); $response = new Response(); $response->headers->setCookie(new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true)); $domResponse = $m->invoke($client, $response); $this->assertEquals($expected[0], $domResponse->getHeader('Set-Cookie')); $response = new Response(); $response->headers->setCookie(new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true)); $response->headers->setCookie(new Cookie('foo1', 'bar1', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true)); $domResponse = $m->invoke($client, $response); $this->assertEquals($expected[0], $domResponse->getHeader('Set-Cookie')); $this->assertEquals($expected, $domResponse->getHeader('Set-Cookie', false)); }
public function testCommitNeedNotification() { $notifier = $this->getMock('Sismo\\Contrib\\CrossFingerNotifier'); $r = new \ReflectionObject($notifier); $m = $r->getMethod('commitNeedNotification'); $m->setAccessible(true); $project = new Project('Twig'); $commit = new Commit($project, '123456'); $commit->setAuthor('Fabien'); $commit->setMessage('Foo'); $commit2 = new Commit($project, '123455'); $commit2->setAuthor('Fabien'); $commit2->setMessage('Bar'); $commit2->setStatusCode('success'); $commit3 = clone $commit2; //a failed commit should be notified $this->assertTrue($m->invoke($notifier, $commit)); //a successful commit without predecessor should be notified $this->assertTrue($m->invoke($notifier, $commit2)); $project->setCommits(array($commit3)); //a successful commit with a successful predecessor should NOT be notified $this->assertFalse($m->invoke($notifier, $commit2)); $project->setCommits(array($commit2, $commit3)); //a failed commit with a successful predecessor should be notified $this->assertTrue($m->invoke($notifier, $commit)); }
protected function callProtectedMethod($object, $method, array $args = array()) { $reflectedObject = new \ReflectionObject($object); $reflectedMethod = $reflectedObject->getMethod($method); $reflectedMethod->setAccessible(true); return $reflectedMethod->invokeArgs($object, $args); }
public function invokeMethod($object, $methodName, array $args = array()) { $refObject = new \ReflectionObject($object); $method = $refObject->getMethod($methodName); $method->setAccessible(true); return $method->invokeArgs($object, $args); }
private function actionCall($service, $actionName) { $refObject = new ReflectionObject($service); $refMethod = $refObject->getMethod($actionName); $values = $this->parameterValues($refMethod); return $refMethod->invokeArgs($service, $values); }
/** * Returns the arguments to pass to the controller. * * @param Request $request A Request instance * @param mixed $controller A PHP callable * * @throws \RuntimeException When value for argument given is not provided */ public function getArguments(Request $request, $controller) { $attributes = $request->attributes->all(); if (is_array($controller)) { list($controller, $method) = $controller; $r = new \ReflectionObject($controller); $parameters = $r->getMethod($method)->getParameters(); $repr = sprintf('%s::%s()', get_class($controller), $method); } else { $r = new \ReflectionFunction($controller); $parameters = $r->getParameters(); $repr = 'Closure'; } $arguments = array(); foreach ($parameters as $param) { if (array_key_exists($param->getName(), $attributes)) { $arguments[] = $attributes[$param->getName()]; } elseif ($param->isDefaultValueAvailable()) { $arguments[] = $param->getDefaultValue(); } else { throw new \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument (because there is no default value or because there is a non optional argument after this one).', $repr, $param->getName())); } } return $arguments; }
/** * Call a private or protected method, giving the arguments as array * * @param object $object * @param string $method * @param array $args */ function call_private_method_array($object, $method, array $args) { $reflObj = new \ReflectionObject($object); $reflMethod = $reflObj->getMethod($method); $reflMethod->setAccessible(true); return $reflMethod->invokeArgs($object, $args); }
/** * @param string $methodName * @param Gruntfile $gruntfile * * @return ReflectionMethod */ protected function getMethod($methodName, Gruntfile $gruntfile) { $refObj = new ReflectionObject($gruntfile); $refMethod = $refObj->getMethod($methodName); $refMethod->setAccessible(true); return $refMethod; }
/** * Helper method to access some private/protected methods * @see lib/ezc/MvcTools/src/interfaces/ezcMvcController::__get() */ public function __get( $name ) { $ret = null; switch( $name ) { case 'cacheLocation': $ret = $this->getCacheLocation(); break; case 'cacheId': $refObj = new ReflectionObject( $this ); $refMethod = $refObj->getMethod( 'generateCacheId' ); $refMethod->setAccessible( true ); $ret = $refMethod->invoke( $this ); break; case 'cacheTTL': $ret = $this->getActionTTL(); break; default: $ret = parent::__get( $name ); } return $ret; }
static function get_eids($search_term, $prop_id, $type_id, $search_compare_op = 0) { $prop_name = Property::static_get_table_name($prop_id); $vptepte_class_name = "view_" . $prop_name . "_to_e_p_to_e"; // include_once (dirname(__FILE__) .'/../PropertyTypeEntity/'.$vptepte_class_name.'.php'); $theclass = new $vptepte_class_name(); $reflObject = new ReflectionObject($theclass); $reflMethod = $reflObject->getMethod("get_eids"); $reflParameters = $reflMethod->getParameters(); $args = array(); foreach ($reflParameters as $param) { //$paramName = $param->getName(); //$args[$param->getPosition()] = $paramName; $args[$param->getPosition()] = func_get_arg($param->getPosition()); //this way view_int_prop... will be passed the fourth argument. //Note: assumes get_eids signature matches order between here and the vptepte's } $eids = array(); if (!$type_id) { $type_hash = MixedQueries::get_type_list(); foreach ($type_hash as $_type_id => $type_name) { //$eids = array_merge($eids, $theclass->get_eids($search_term, $prop_id, $_type_id)); $args[2] = $_type_id; $eids = array_merge($eids, $reflMethod->invokeArgs($theclass, $args)); } } else { //$eids = $theclass->get_eids($search_term, $prop_id, $type_id); $eids = $reflMethod->invokeArgs($theclass, $args); } return $eids; }
public function execute($registry, $args = array()) { // Stop any magical methods being called if (substr($this->method, 0, 2) == '__') { return false; } // Initialize the class if (is_file($this->file)) { include_once $this->file; $controller = new $this->class($registry); } else { return false; } //print_r($args); // Now we have the controller we want to check if the corrasponding number of arguments matches the method being called. $reflection = new ReflectionObject($controller); $parameters = $reflection->getMethod($this->method)->getParameters(); foreach ($perameters as $perameter) { echo $perameter->name . "\n"; } if (count($perameters) != count($args)) { } print_r($perameters); // Call the method if set if (method_exists($controller, $this->method)) { return call_user_func_array(array($controller, $this->method), $args); } else { return false; } }
public function callRPCMethod() { $sRawMethod = $this->oRequest->method; @(list($sNameSpace, $sMethod) = explode('.', $sRawMethod)); if (is_null($sMethod)) { $sMethod = $sNameSpace; $sNameSpace = 'wp'; } $oInterface = $this->getRPCInterface($sNameSpace); if (!$this->hasRPCMethod($oInterface, $sMethod)) { $this->oResponse->error = 'Invalid RPC request: method [' . var_export($sMethod, true) . '] does not exist'; } else { if (is_null($this->oRequest->params) || !is_array($this->oRequest->params)) { throw new ExceptionResponseError('Invalid RPC request: missing parameters'); } $oReflectedInterface = new \ReflectionObject($oInterface); if ($oReflectedInterface->hasMethod($sMethod)) { /* @var $oReflectedMethod \ReflectionMethod */ $oReflectedMethod = $oReflectedInterface->getMethod($sMethod); if ($oReflectedMethod->isPublic()) { return $oReflectedMethod->invokeArgs($oInterface, $this->oRequest->params); } } } return null; }
/** * Guesses the template name to render and its variables and adds them to * the request object. * * @param FilterControllerEvent $event A FilterControllerEvent instance */ public function onKernelController(FilterControllerEvent $event) { if (!is_array($controller = $event->getController())) { return; } $request = $event->getRequest(); if (!($configuration = $request->attributes->get('_template'))) { return; } if (!$configuration->getTemplate()) { $guesser = $this->container->get('sensio_framework_extra.view.guesser'); $configuration->setTemplate($guesser->guessTemplateName($controller, $request, $configuration->getEngine())); } $request->attributes->set('_template', $configuration->getTemplate()); $request->attributes->set('_template_vars', $configuration->getVars()); $request->attributes->set('_template_streamable', $configuration->isStreamable()); // all controller method arguments if (!$configuration->getVars()) { $r = new \ReflectionObject($controller[0]); $vars = array(); foreach ($r->getMethod($controller[1])->getParameters() as $param) { $vars[] = $param->getName(); } $request->attributes->set('_template_default_vars', $vars); } }
protected function setAccessProtectedMethod($object, $methodName) { $reflect = new ReflectionObject($object); $method = $reflect->getMethod($methodName); $method->setAccessible(true); return $method; }
public function testLoadFile() { $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath . '/ini')); $r = new \ReflectionObject($loader); $m = $r->getMethod('loadFile'); $m->setAccessible(true); try { $m->invoke($loader, 'foo.yml'); $this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist'); $this->assertEquals('The service file "foo.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist'); } try { $m->invoke($loader, 'parameters.ini'); $this->fail('->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file'); $this->assertEquals('The service file "parameters.ini" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file'); } $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath . '/yaml')); foreach (array('nonvalid1', 'nonvalid2') as $fixture) { try { $m->invoke($loader, $fixture . '.yml'); $this->fail('->load() throws an InvalidArgumentException if the loaded file does not validate'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not validate'); $this->assertStringMatchesFormat('The service file "nonvalid%d.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not validate'); } } }
/** * @dataProvider provideAbsolutePaths */ public function testCanDetectAbsolutePaths($path) { $reflectionObject = new \ReflectionObject($this->locator); $methodReflection = $reflectionObject->getMethod('isAbsolutePath'); $methodReflection->setAccessible(true); $this->assertTrue($methodReflection->invoke($this->locator, $path), '->isAbsolutePath() returns true for an absolute path'); }
public function testParseFile() { $loader = new XmlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath . '/ini')); $r = new \ReflectionObject($loader); $m = $r->getMethod('parseFileToDOM'); $m->setAccessible(true); try { $m->invoke($loader, self::$fixturesPath . '/ini/parameters.ini'); $this->fail('->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file'); } catch (\Exception $e) { $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file'); $this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#', 'parameters.ini'), $e->getMessage(), '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file'); $e = $e->getPrevious(); $this->assertInstanceOf('InvalidArgumentException', $e, '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file'); $this->assertStringStartsWith('[ERROR 4] Start tag expected, \'<\' not found (in', $e->getMessage(), '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file'); } $loader = new XmlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath . '/xml')); try { $m->invoke($loader, self::$fixturesPath . '/xml/nonvalid.xml'); $this->fail('->parseFileToDOM() throws an InvalidArgumentException if the loaded file does not validate the XSD'); } catch (\Exception $e) { $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->parseFileToDOM() throws an InvalidArgumentException if the loaded file does not validate the XSD'); $this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#', 'nonvalid.xml'), $e->getMessage(), '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file'); $e = $e->getPrevious(); $this->assertInstanceOf('InvalidArgumentException', $e, '->parseFileToDOM() throws an InvalidArgumentException if the loaded file does not validate the XSD'); $this->assertStringStartsWith('[ERROR 1845] Element \'nonvalid\': No matching global declaration available for the validation root. (in', $e->getMessage(), '->parseFileToDOM() throws an InvalidArgumentException if the loaded file does not validate the XSD'); } $xml = $m->invoke($loader, self::$fixturesPath . '/xml/services1.xml'); $this->assertInstanceOf('DOMDocument', $xml, '->parseFileToDOM() returns an SimpleXMLElement object'); }
public function testGoBack() { $helper = new \Magento\TestFramework\Helper\ObjectManager($this); $storeManagerMock = $this->getMock('Magento\\Framework\\StoreManagerInterface'); $responseMock = $this->getMock('Magento\\Framework\\App\\Response\\Http', array(), array(), '', false); $responseMock->headersSentThrowsException = false; $requestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', array(), array(), '', false); $requestMock->expects($this->any())->method('getActionName')->will($this->returnValue('add')); $requestMock->expects($this->at(0))->method('getParam')->with('return_url')->will($this->returnValue('http://malicious.com/')); $requestMock->expects($this->any())->method('getParam')->will($this->returnValue(null)); $redirect = $this->getMock('Magento\\Framework\\App\\Response\\RedirectInterface'); $redirect->expects($this->any())->method('getRefererUrl')->will($this->returnValue('http://some-url/index.php/product.html')); $checkoutSessionMock = $this->getMock('Magento\\Checkout\\Model\\Session', array('setContinueShoppingUrl'), array(), '', false); $checkoutSessionMock->expects($this->once())->method('setContinueShoppingUrl')->with('http://some-url/index.php/product.html')->will($this->returnSelf()); $redirect->expects($this->once())->method('redirect')->will($this->returnValue('http://some-url/index.php/checkout/cart/')); $storeMock = $this->getMock('Magento\\Store\\Model\\Store', array(), array(), '', false); $storeMock->expects($this->any())->method('getBaseUrl')->will($this->returnValue('http://some-url/')); $configMock = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $configMock->expects($this->once())->method('getValue')->with('checkout/cart/redirect_to_cart')->will($this->returnValue('1')); $storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $arguments = array('response' => $responseMock, 'request' => $requestMock, 'checkoutSession' => $checkoutSessionMock, 'scopeConfig' => $configMock, 'redirect' => $redirect, 'storeManager' => $storeManagerMock); $controller = $helper->getObject('Magento\\Checkout\\Controller\\Cart', $arguments); $reflectionObject = new \ReflectionObject($controller); $reflectionMethod = $reflectionObject->getMethod('_goBack'); $reflectionMethod->setAccessible(true); $reflectionMethod->invoke($controller); }