Example #1
0
 /**
  * @covers LightnCandy\SafeString::escapeTemplate
  */
 public function testOn_escapeTemplate()
 {
     $method = new \ReflectionMethod('LightnCandy\\SafeString', 'escapeTemplate');
     $this->assertEquals('abc', $method->invokeArgs(null, array_by_ref(array('abc'))));
     $this->assertEquals('a\\\\bc', $method->invokeArgs(null, array_by_ref(array('a\\bc'))));
     $this->assertEquals('a\\\'bc', $method->invokeArgs(null, array_by_ref(array('a\'bc'))));
 }
Example #2
0
 public function execute($argv)
 {
     if (!is_array($argv)) {
         $argv = array($argv);
     }
     $argc = count($argv);
     if (empty($this->action)) {
         throw new \Jolt\Exception('controller_action_not_set');
     }
     try {
         $action = new \ReflectionMethod($this, $this->action);
     } catch (\ReflectionException $e) {
         throw new \Jolt\Exception('controller_action_not_part_of_class');
     }
     $paramCount = $action->getNumberOfRequiredParameters();
     if ($paramCount != $argc && $paramCount > $argc) {
         $argv = array_pad($argv, $paramCount, NULL);
     }
     ob_start();
     if ($action->isPublic()) {
         if ($action->isStatic()) {
             $action->invokeArgs(NULL, $argv);
         } else {
             $action->invokeArgs($this, $argv);
         }
     }
     $renderedController = ob_get_clean();
     if (!empty($renderedController)) {
         $this->renderedController = $renderedController;
     } else {
         $this->renderedController = $this->renderedView;
     }
     return $this->renderedController;
 }
 /**
  * @covers LightnCandy\LightnCandy::handleError
  */
 public function testOn_handleError()
 {
     $method = new \ReflectionMethod('LightnCandy\\LightnCandy', 'handleError');
     $method->setAccessible(true);
     $this->assertEquals(false, $method->invokeArgs(null, array_by_ref(array(array('error' => array())))));
     $this->assertEquals(true, $method->invokeArgs(null, array_by_ref(array(array('error' => array('some error'), 'flags' => array('errorlog' => 0, 'exception' => 0))))));
 }
Example #4
0
 /**
  * @covers LightnCandy\Token::toString
  */
 public function testOn_toString()
 {
     $method = new \ReflectionMethod('LightnCandy\\Token', 'toString');
     $this->assertEquals('c', $method->invokeArgs(null, array_by_ref(array(array(0, 'a', 'b', 'c', 'd', 'e')))));
     $this->assertEquals('cd', $method->invokeArgs(null, array_by_ref(array(array(0, 'a', 'b', 'c', 'd', 'e', 'f')))));
     $this->assertEquals('qd', $method->invokeArgs(null, array_by_ref(array(array(0, 'a', 'b', 'c', 'd', 'e', 'f'), array(3 => 'q')))));
 }
Example #5
0
 /**
  * @dataProvider orderByProvider
  */
 public function testAddOrderBy($alias, $orderBy, $expectedOrderBy)
 {
     foreach ($expectedOrderBy as $field => $order) {
         $this->queryBuilder->addOrderBy($field, $order)->shouldBeCalledTimes(1);
     }
     $this->addOrderByFunction->invokeArgs($this->orderByTrait, [$this->queryBuilder->reveal(), $alias, $orderBy]);
 }
Example #6
0
 public function testRelToAbs()
 {
     $method = new ReflectionMethod('gsavastano\\Dssg\\Dssg', 'relToAbs');
     $method->setAccessible(TRUE);
     $this->assertEquals('http://www.example.com/rel2abs', $method->invokeArgs(new Dssg(), array('/rel2abs', 'http://www.example.com/')));
     $this->assertEquals('http://www.example.com/../rel2abs', $method->invokeArgs(new Dssg(), array('../rel2abs', 'http://www.example.com/')));
     $this->assertNotEquals('http://www.example.com/rel2abs', $method->invokeArgs(new Dssg(), array('http://example.com/rel2abs', 'http://www.example.com/')));
 }
 /**
  * Call a class reference method with set parameters.
  * @param $classInstance instantiated class name
  */
 public function call($classInstance)
 {
     if (isset($this->parameters)) {
         $this->method->invokeArgs($classInstance, $this->parameters);
     } else {
         $this->method->invoke($classInstance);
     }
 }
Example #8
0
 public function __call($methodName, array $args)
 {
     $method = new \ReflectionMethod($this->class, $methodName);
     if (!$method->isPublic()) {
         $method->setAccessible(true);
     }
     return $method->isStatic() ? $method->invokeArgs(null, $args) : $method->invokeArgs($this->object, $args);
 }
Example #9
0
 /**
  * @covers LightnCandy\Compiler::addUsageCount
  */
 public function testOn_addUsageCount()
 {
     $method = new \ReflectionMethod('LightnCandy\\Compiler', 'addUsageCount');
     $method->setAccessible(true);
     $this->assertEquals(1, $method->invokeArgs(null, array_by_ref(array(array('usedCount' => array('test' => array())), 'test', 'testname'))));
     $this->assertEquals(3, $method->invokeArgs(null, array_by_ref(array(array('usedCount' => array('test' => array('testname' => 2))), 'test', 'testname'))));
     $this->assertEquals(5, $method->invokeArgs(null, array_by_ref(array(array('usedCount' => array('test' => array('testname' => 2))), 'test', 'testname', 3))));
 }
Example #10
0
 /**
  * @covers LightnCandy\Encoder::encq
  */
 public function testOn_encq()
 {
     $method = new \ReflectionMethod('LightnCandy\\Encoder', 'encq');
     $this->assertEquals('a', $method->invokeArgs(null, array_by_ref(array(array('flags' => array('mustlam' => 0, 'lambda' => 0)), 'a'))));
     $this->assertEquals('a&b', $method->invokeArgs(null, array_by_ref(array(array('flags' => array('mustlam' => 0, 'lambda' => 0)), 'a&b'))));
     $this->assertEquals('a'b', $method->invokeArgs(null, array_by_ref(array(array('flags' => array('mustlam' => 0, 'lambda' => 0)), 'a\'b'))));
     $this->assertEquals('`a'b', $method->invokeArgs(null, array_by_ref(array(array('flags' => array('mustlam' => 0, 'lambda' => 0)), '`a\'b'))));
 }
Example #11
0
 public function testCountryCodeSearch()
 {
     $method = new ReflectionMethod('Player', 'countryCode');
     $method->setAccessible(TRUE);
     $player = new Player(null);
     $this->assertEquals('FI', $method->invokeArgs($player, array('Finland')));
     $this->assertEquals('UNK', $method->invokeArgs($player, array('Random')));
     $this->assertEquals('UNK', $method->invokeArgs($player, array(123)));
 }
Example #12
0
 /**
  * @covers LightnCandy\Partial::prePartial
  */
 public function testOn_prePartial()
 {
     $method = new \ReflectionMethod('LightnCandy\\Partial', 'prePartial');
     $method->setAccessible(true);
     $this->assertEquals('hey', $method->invokeArgs(null, array_by_ref(array(array('prepartial' => false), 'hey', 'haha'))));
     $this->assertEquals('haha-hoho', $method->invokeArgs(null, array_by_ref(array(array('prepartial' => function ($cx, $tmpl, $name) {
         return "{$name}-{$tmpl}";
     }), 'hoho', 'haha'))));
 }
Example #13
0
 public function testCreateTableDDL()
 {
     $driver = new \T4\Dbal\Drivers\Mysql();
     $reflector = new ReflectionMethod($driver, 'createTableDDL');
     $reflector->setAccessible(true);
     $this->assertEquals('CREATE TABLE `foo`' . "\n" . '(' . "\n" . '`__id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,' . "\n" . 'PRIMARY KEY (`__id`)' . "\n" . ')', $reflector->invokeArgs($driver, ['foo', []]));
     $this->assertEquals('CREATE TABLE `foo`' . "\n" . '(' . "\n" . '`__id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,' . "\n" . '`foo` INT(11),' . "\n" . '`bar` VARCHAR(255),' . "\n" . 'PRIMARY KEY (`__id`)' . "\n" . ')', $reflector->invokeArgs($driver, ['foo', ['foo' => ['type' => 'int'], 'bar' => ['type' => 'string']]]));
     $this->assertEquals('CREATE TABLE `foo`' . "\n" . '(' . "\n" . '`__id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,' . "\n" . '`lnk` BIGINT UNSIGNED NOT NULL DEFAULT \'0\',' . "\n" . '`foo` INT(11),' . "\n" . '`bar` VARCHAR(255),' . "\n" . 'PRIMARY KEY (`__id`),' . "\n" . 'INDEX `lnk_idx` (`lnk`)' . "\n" . ')', $reflector->invokeArgs($driver, ['foo', ['lnk' => ['type' => 'link'], 'foo' => ['type' => 'int'], 'bar' => ['type' => 'string']]]));
 }
Example #14
0
 public function testCreateTableDDL()
 {
     $driver = new \T4\Dbal\Drivers\Pgsql();
     $reflector = new ReflectionMethod($driver, 'createTableDDL');
     $reflector->setAccessible(true);
     $this->assertEquals(['CREATE TABLE "foo"' . "\n" . '("__id" BIGSERIAL PRIMARY KEY)'], $reflector->invokeArgs($driver, ['foo', []]));
     $this->assertEquals(['CREATE TABLE "foo"' . "\n" . '("__id" BIGSERIAL PRIMARY KEY, "foo" INTEGER, "bar" VARCHAR)'], $reflector->invokeArgs($driver, ['foo', ['foo' => ['type' => 'int'], 'bar' => ['type' => 'string']]]));
     $this->assertEquals(['CREATE TABLE "foo"' . "\n" . '("__id" BIGSERIAL PRIMARY KEY, "lnk" BIGINT NOT NULL DEFAULT \'0\', "foo" INTEGER, "bar" VARCHAR)', 'CREATE INDEX ON "foo" ("lnk")'], $reflector->invokeArgs($driver, ['foo', ['lnk' => ['type' => 'link'], 'foo' => ['type' => 'int'], 'bar' => ['type' => 'string']]]));
 }
Example #15
0
 public function testEvalGroupParsesSimpleAndsAndOrs()
 {
     $reflectionMethod = new \ReflectionMethod($this->evaluator, 'evalGroup');
     $reflectionMethod->setAccessible(\true);
     $result = $reflectionMethod->invokeArgs($this->evaluator, [[1 => '0|0|0|1|0&1']]);
     $this->assertSame(1, $result);
     $result = $reflectionMethod->invokeArgs($this->evaluator, [[1 => '0|0|0|0|0&0']]);
     $this->assertSame(0, $result);
 }
Example #16
0
 public function testIsFloatScalePrecise()
 {
     $reflMethod = new \ReflectionMethod('MoneyLaundry\\Filter\\AbstractFilter', 'isFloatScalePrecise');
     $reflMethod->setAccessible(true);
     $mock = $this->getMockBuilder('MoneyLaundry\\Filter\\AbstractFilter')->enableProxyingToOriginalMethods()->getMockForAbstractClass();
     $this->assertTrue($reflMethod->invokeArgs($mock, [1.25, 2]));
     $this->assertFalse($reflMethod->invokeArgs($mock, [1.255, 2]));
     $reflMethod->setAccessible(false);
 }
Example #17
0
 /**
  *
  */
 public function testGetResponseReturnsSpecificValueIfKeyIsSupplied()
 {
     $method = new \ReflectionMethod('\\PutIO\\Helpers\\HTTP\\HTTPHelper', 'getResponse');
     $method->setAccessible(\true);
     $this->assertSame('yay', $method->invokeArgs($this->helper, ['{"valid": "json", "robots": "yay"}', \false, 'robots']));
     $this->assertFalse($method->invokeArgs($this->helper, ['{"valid": "json", "robots": "yay"}', \false, 'this key does not exist']));
     $this->assertTrue($method->invokeArgs($this->helper, ['{"status": "OK"}', \true]));
     $this->assertSame(['valid' => 'json', 'robots' => 'yay'], $method->invokeArgs($this->helper, ['{"valid": "json", "robots": "yay"}', \false, '']));
 }
Example #18
0
 /**
  * @covers LightnCandy\Context::updateHelperTable
  */
 public function testOn_updateHelperTable()
 {
     $method = new \ReflectionMethod('LightnCandy\\Context', 'updateHelperTable');
     $method->setAccessible(true);
     $this->assertEquals(array(), $method->invokeArgs(null, array_by_ref(array(array(), array()))));
     $this->assertEquals(array('flags' => array('exhlp' => 1), 'helpers' => array('abc' => 1)), $method->invokeArgs(null, array_by_ref(array(array('flags' => array('exhlp' => 1)), array('helpers' => array('abc'))))));
     $this->assertEquals(array('error' => array('You provide a custom helper named as \'abc\' in options[\'helpers\'], but the function abc() is not defined!'), 'flags' => array('exhlp' => 0)), $method->invokeArgs(null, array_by_ref(array(array('error' => array(), 'flags' => array('exhlp' => 0)), array('helpers' => array('abc'))))));
     $this->assertEquals(array('flags' => array('exhlp' => 1), 'helpers' => array('\\LightnCandy\\Runtime::raw' => '\\LightnCandy\\Runtime::raw')), $method->invokeArgs(null, array_by_ref(array(array('flags' => array('exhlp' => 1), 'helpers' => array()), array('helpers' => array('\\LightnCandy\\Runtime::raw'))))));
     $this->assertEquals(array('flags' => array('exhlp' => 1), 'helpers' => array('test' => '\\LightnCandy\\Runtime::raw')), $method->invokeArgs(null, array_by_ref(array(array('flags' => array('exhlp' => 1), 'helpers' => array()), array('helpers' => array('test' => '\\LightnCandy\\Runtime::raw'))))));
 }
Example #19
0
 public function testPrepareXPath()
 {
     $driver = $this->getSession()->getDriver();
     // Make the method accessible for testing purposes
     $method = new \ReflectionMethod('Behat\\Mink\\Driver\\SahiDriver', 'prepareXPath');
     $method->setAccessible(true);
     $this->assertEquals('No quotes', $method->invokeArgs($driver, array('No quotes')));
     $this->assertEquals("Single quote'", $method->invokeArgs($driver, array("Single quote'")));
     $this->assertEquals('Double quote\\"', $method->invokeArgs($driver, array('Double quote"')));
 }
 public function testStringMessage()
 {
     $mock = $this->getMockForAbstractClass('\\Concrete\\Core\\Validator\\AbstractTranslatableValidator');
     $method = new \ReflectionMethod($mock, 'getErrorString');
     $method->setAccessible(true);
     /** @type \Concrete\Core\Validator\AbstractTranslatableValidator $mock */
     $mock->setErrorString(5, 'ERROR');
     $this->assertEquals('ERROR', $method->invokeArgs($mock, array(5, '')));
     $this->assertEquals('default', $method->invokeArgs($mock, array(1, '', 'default')));
 }
 /**
  * @dataProvider validateConfigProvider
  */
 public function testValidateConfig($options, $expectedOptions = false, $expectedException = false, $expectedExceptionMessage = false)
 {
     $factory = new DropboxAdapterFactory($options);
     if ($expectedException) {
         $this->setExpectedException($expectedException, $expectedExceptionMessage);
     }
     $this->method->invokeArgs($factory, []);
     if (is_array($expectedOptions)) {
         $this->assertEquals($expectedOptions, $this->property->getValue($factory));
     }
 }
Example #22
0
 /**
  * @covers LightnCandy\Exporter::closure
  */
 public function testOn_closure()
 {
     $method = new \ReflectionMethod('LightnCandy\\Exporter', 'closure');
     $method->setAccessible(true);
     $this->assertEquals('function($a) {return;}', $method->invokeArgs(null, array_by_ref(array(array('flags' => array('standalone' => 0)), function ($a) {
         return;
     }))));
     $this->assertEquals('function($a) {return;}', $method->invokeArgs(null, array_by_ref(array(array('flags' => array('standalone' => 0)), function ($a) {
         return;
     }))));
 }
 public static function __callStatic($name, $arguments)
 {
     $method = new \ReflectionMethod('\\BCC\\EnumerableUtility\\Stringer', $name);
     if ($method->isStatic()) {
         $result = $method->invokeArgs(null, $arguments);
     } else {
         $result = $method->invokeArgs(new Stringer($arguments[0]), \array_slice($arguments, 1));
     }
     if ($result instanceof Stringer) {
         return (string) $result;
     }
     return $result;
 }
 public function testGetExcerpt()
 {
     $method = new ReflectionMethod(\Junky\PhpPrettyPrint\Html\HtmlBuilder::class, 'getExcerpt');
     $method->setAccessible(true);
     $really_long_string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
     // Default 250
     // + 3 trailing dots
     $this->assertEquals($method->invokeArgs(new HtmlBuilder(), [$really_long_string => 250]), 250);
     // less than 250
     $this->assertEquals($method->invokeArgs(new HtmlBuilder(), [$really_long_string => 153]), 153);
     // excerpt is false
     // god damn it phpunit...
     $this->assertEquals($method->invokeArgs(new HtmlBuilder(), [$really_long_string => strlen($really_long_string)]), strlen($really_long_string));
 }
Example #25
0
 public function testProcessRules()
 {
     $model = new RoleModelValidationStub(array(), self::validatorMock());
     $rules = RoleModelValidationStub::$rules;
     $processRules = new ReflectionMethod($model, 'processRules');
     $processRules->setAccessible(true);
     $expected = array('name' => 'required', 'email' => 'unique:foobar,email,');
     $result = $processRules->invokeArgs($model, array($rules));
     $this->assertEquals($expected, $result);
     $model->id = 42;
     $expected = array('name' => 'required', 'email' => 'unique:foobar,email,42');
     $result = $processRules->invokeArgs($model, array($rules));
     $this->assertEquals($expected, $result);
 }
Example #26
0
 public function invoke(array $params = null, array $posts = null)
 {
     $this->attributes->invoke();
     $this->controller->attributes->invoke();
     $args = Argument::createArgs($this->attributes, $this->parameters, $params, $posts);
     //        foreach ($this->parameters as $parameter) {
     //            var_dump($parameter->getClass());
     //            if (array_key_exists($parameter->name, $params)) {
     //                $args[$parameter->name] = $params[$parameter->name];
     //            } else {
     //                $args[$parameter->name] = null;
     //            }
     //        }
     return $this->reflector->invokeArgs($this->controller, $args);
 }
 public function invoke($methodName, array $methodArguments)
 {
     $reflectionMethod = new ReflectionMethod($this->person, $methodName);
     if (substr($methodName, 0, 3) == "get") {
         return $reflectionMethod->invokeArgs($this->person, $methodArguments);
     } else {
         if ($methodName == "setHotOrNotRating") {
             throw new BadMethodCallException("Illegal access");
         } else {
             if (substr($methodName, 0, 3) == "set") {
                 return $reflectionMethod->invokeArgs($this->person, $methodArguments);
             }
         }
     }
     return NULL;
 }
Example #28
0
 /**
  * Creates alias to all native methods of the resource.
  *
  * @param   string  $method  method name
  * @param   mixed   $args    arguments
  * @return  mixed
  */
 public function __call($method, $args)
 {
     $class = get_called_class();
     $obj = $class::instance();
     $method = new ReflectionMethod($obj, $method);
     return $method->invokeArgs($obj, $args);
 }
Example #29
0
function xx4($i)
{
    $xx = 'test';
    $x = new $xx();
    $m = new ReflectionMethod($x, 'xx');
    $m->invokeArgs($x, array($i));
}
Example #30
0
 /**
  * Runs the action.
  * The action method defined in the controller is invoked.
  * This method is required by {@link CAction}.
  */
 public function run()
 {
     $controller = $this->getController();
     $methodName = 'action' . $this->getId();
     $method = new ReflectionMethod($controller, $methodName);
     if (($n = $method->getNumberOfParameters()) > 0) {
         $params = array();
         foreach ($method->getParameters() as $i => $param) {
             $name = $param->getName();
             if (isset($_GET[$name])) {
                 if ($param->isArray()) {
                     $params[] = is_array($_GET[$name]) ? $_GET[$name] : array($_GET[$name]);
                 } else {
                     if (!is_array($_GET[$name])) {
                         $params[] = $_GET[$name];
                     } else {
                         throw new CHttpException(400, Yii::t('yii', 'Your request is invalid.'));
                     }
                 }
             } else {
                 if ($param->isDefaultValueAvailable()) {
                     $params[] = $param->getDefaultValue();
                 } else {
                     throw new CHttpException(400, Yii::t('yii', 'Your request is invalid.'));
                 }
             }
         }
         $method->invokeArgs($controller, $params);
     } else {
         $controller->{$methodName}();
     }
 }