Example #1
0
 public function testOptionMethods()
 {
     $item = new Item();
     $rmSetProduct = new \ReflectionMethod($item, 'setProduct');
     $rmSetProduct->setAccessible(true);
     $this->assertNull($item->getOption('noOption'));
     $rmSetOptions = new \ReflectionMethod($item, 'setOptions');
     $rmSetOptions->setAccessible(true);
     $rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate()));
     $rmSetOptions->invoke($item, array('option2' => 2, 'option3' => 3));
     $options = $item->getOptions();
     $this->assertCount(2, $options);
     $this->assertArrayHasKey('option2', $options);
     $this->assertArrayHasKey('option3', $options);
     $rmClearOptions = new \ReflectionMethod($item, 'clearOptions');
     $rmClearOptions->setAccessible(true);
     $rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate(false)));
     $this->setExpectedException('Vespolina\\Exception\\InvalidOptionsException');
     $rmClearOptions->invoke($item);
     $this->assertSame($options, $item->getOptions(), 'nothing should have been removed if the validation fails');
     $rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate()));
     $rmClearOptions->invoke($item);
     $this->assertEmpty($item->getOptions());
     $rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate(false)));
     $this->setExpectedException('Vespolina\\Exception\\InvalidOptionsException');
     $rmSetOptions->invokeArgs($item, array('failure' => 0));
     $this->assertEmpty($item->getOptions(), 'nothing should be added if the validation fails');
 }
Example #2
0
    public function testTrackPageView()
    {
        $viewer = CMTest_TH::createUser();
        $environment = new CM_Frontend_Environment(CM_Site_Abstract::factory(), $viewer);
        $client = new CMService_AdWords_Client();
        $pushConversion = new ReflectionMethod($client, '_pushConversion');
        $pushConversion->setAccessible(true);
        $pushConversion->invoke($client, $viewer, CMService_AdWords_Conversion::fromJson('{"google_conversion_id":123456,"google_conversion_language":"en","google_conversion_format":"1","google_conversion_color":"666666","google_conversion_label":"label","google_remarketing_only":true,"google_conversion_value":123,"google_conversion_currency":"USD","google_custom_params":{"a":1,"b":2}}'));
        $pushConversion->invoke($client, $viewer, CMService_AdWords_Conversion::fromJson('{"google_conversion_id":789}'));
        $this->assertSame('', $client->getJs());
        $this->assertSame(<<<EOD
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion_async.js" charset="utf-8"></script>
EOD
, $client->getHtml($environment));
        $client->trackPageView($environment, '/');
        $this->assertSame(<<<EOD
window.google_trackConversion({"google_conversion_id":123456,"google_conversion_language":"en","google_conversion_format":"1","google_conversion_color":"666666","google_conversion_label":"label","google_remarketing_only":true,"google_conversion_value":123,"google_conversion_currency":"USD","google_custom_params":{"a":1,"b":2}});window.google_trackConversion({"google_conversion_id":789});
EOD
, $client->getJs());
        $this->assertSame(<<<EOD
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion_async.js" charset="utf-8"></script><script type="text/javascript">
/* <![CDATA[ */
window.google_trackConversion({"google_conversion_id":123456,"google_conversion_language":"en","google_conversion_format":"1","google_conversion_color":"666666","google_conversion_label":"label","google_remarketing_only":true,"google_conversion_value":123,"google_conversion_currency":"USD","google_custom_params":{"a":1,"b":2}});window.google_trackConversion({"google_conversion_id":789});
//]]>
</script>
EOD
, $client->getHtml($environment));
    }
 /**
  * {@inheritdoc}
  */
 public function validate($object, Constraint $constraint)
 {
     if (null === $object) {
         return;
     }
     if (null !== $constraint->callback && null !== $constraint->methods) {
         throw new ConstraintDefinitionException('The Callback constraint supports either the option "callback" ' . 'or "methods", but not both at the same time.');
     }
     // has to be an array so that we can differentiate between callables
     // and method names
     if (null !== $constraint->methods && !is_array($constraint->methods)) {
         throw new UnexpectedTypeException($constraint->methods, 'array');
     }
     $methods = $constraint->methods ?: array($constraint->callback);
     foreach ($methods as $method) {
         if (is_array($method) || $method instanceof \Closure) {
             if (!is_callable($method)) {
                 throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Callback constraint is not a valid callable', $method[0], $method[1]));
             }
             call_user_func($method, $object, $this->context);
         } else {
             if (!method_exists($object, $method)) {
                 throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist', $method));
             }
             $reflMethod = new \ReflectionMethod($object, $method);
             if ($reflMethod->isStatic()) {
                 $reflMethod->invoke(null, $object, $this->context);
             } else {
                 $reflMethod->invoke($object, $this->context);
             }
         }
     }
 }
 private function _invoke($clz = '', $act = '', $param, $namespace = 'Home\\Controller\\')
 {
     $clz = ucwords($clz);
     $clz_name = $namespace . $clz . 'Controller';
     try {
         $ref_clz = new \ReflectionClass($clz_name);
         if ($ref_clz->hasMethod($act)) {
             $ref_fun = new \ReflectionMethod($clz_name, $act);
             if ($ref_fun->isPrivate() || $ref_fun->isProtected()) {
                 $ref_fun->setAccessible(true);
             }
             if ($ref_fun->isStatic()) {
                 $ref_fun->invoke(null);
             } else {
                 $ref_fun_par = $ref_fun->getParameters();
                 if (!empty($param) && is_array($param)) {
                     if (is_array($ref_fun_par) && count($ref_fun_par) == count($param)) {
                         $ref_fun->invokeArgs(new $clz_name(), $param);
                     } else {
                         $ref_fun->invoke(new $clz_name());
                     }
                 } else {
                     $ref_fun->invoke(new $clz_name());
                 }
             }
         }
     } catch (\LogicException $le) {
         $this->ajaxReturn(array('status' => '500', 'info' => '服务器内部发生严重错误'));
     } catch (\ReflectionException $re) {
         $this->ajaxReturn(array('status' => '404', 'info' => '访问' . $clz . '控制器下的非法操作', 'data' => array('code' => $re->getCode())));
     }
 }
Example #5
0
 public function testRetrievesAndCachesTargetData()
 {
     $ctime = strtotime('January 1, 2013');
     $a = $this->getMockBuilder('SplFileinfo')->setMethods(array('getSize', 'getMTime', '__toString'))->disableOriginalConstructor()->getMock();
     $a->expects($this->any())->method('getSize')->will($this->returnValue(10));
     $a->expects($this->any())->method('getMTime')->will($this->returnValue($ctime));
     $a->expects($this->any())->method('__toString')->will($this->returnValue(''));
     $b = $this->getMockBuilder('SplFileinfo')->setMethods(array('getSize', 'getMTime', '__toString'))->disableOriginalConstructor()->getMock();
     $b->expects($this->any())->method('getSize')->will($this->returnValue(11));
     $b->expects($this->any())->method('getMTime')->will($this->returnValue($ctime));
     $a->expects($this->any())->method('__toString')->will($this->returnValue(''));
     $c = 0;
     $converter = $this->getMockBuilder('Aws\\S3\\Sync\\KeyConverter')->setMethods(array('convert'))->getMock();
     $converter->expects($this->any())->method('convert')->will($this->returnCallback(function () use(&$c) {
         if (++$c == 1) {
             return 'foo';
         } else {
             return 'bar';
         }
     }));
     $targetIterator = new \ArrayIterator(array($b, $a));
     $targetIterator->rewind();
     $changed = new ChangedFilesIterator($targetIterator, $targetIterator, $converter, $converter);
     $ref = new \ReflectionMethod($changed, 'getTargetData');
     $ref->setAccessible(true);
     $this->assertEquals(array(10, $ctime), $ref->invoke($changed, 'bar'));
     $this->assertEquals(array(11, $ctime), $ref->invoke($changed, 'foo'));
     $this->assertFalse($ref->invoke($changed, 'baz'));
 }
 /**
  * {@inheritdoc}
  */
 public function validate($object, Constraint $constraint)
 {
     if (!$constraint instanceof Callback) {
         throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\Callback');
     }
     $method = $constraint->callback;
     if ($method instanceof \Closure) {
         $method($object, $this->context, $constraint->payload);
     } elseif (is_array($method)) {
         if (!is_callable($method)) {
             if (isset($method[0]) && is_object($method[0])) {
                 $method[0] = get_class($method[0]);
             }
             throw new ConstraintDefinitionException(sprintf('%s targeted by Callback constraint is not a valid callable', json_encode($method)));
         }
         call_user_func($method, $object, $this->context, $constraint->payload);
     } elseif (null !== $object) {
         if (!method_exists($object, $method)) {
             throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist in class %s', $method, get_class($object)));
         }
         $reflMethod = new \ReflectionMethod($object, $method);
         if ($reflMethod->isStatic()) {
             $reflMethod->invoke(null, $object, $this->context, $constraint->payload);
         } else {
             $reflMethod->invoke($object, $this->context, $constraint->payload);
         }
     }
 }
Example #7
0
 /**
  * Test extractParams().
  */
 public function testExtractParams()
 {
     $method = new \ReflectionMethod('Social\\Connection', 'extractParams');
     $method->setAccessible(true);
     $this->assertEquals(array(), $method->invoke(null, 'http://www.example.com'));
     $this->assertEquals(array('foo' => 'bar', 'fox' => 'dog'), $method->invoke(null, 'http://www.example.com?foo=bar&fox=dog'));
 }
 public function testRelativeURLs()
 {
     $hrefIsRelativeMethod = new ReflectionMethod('NavigationScraperService', 'hrefIsRelative');
     $hrefIsRelativeMethod->setAccessible(true);
     $service = new NavigationScraperService();
     $this->assertTrue($hrefIsRelativeMethod->invoke($service, '/blah'));
     $this->assertTrue($hrefIsRelativeMethod->invoke($service, 'blah/something'));
 }
 /**
  * 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 #10
0
 public function testEscape()
 {
     $method = new ReflectionMethod($this->feed, 'escape');
     $method->setAccessible(true);
     $this->assertEquals('&amp;', $method->invoke($this->feed, '&'));
     $this->assertEquals('&quot;', $method->invoke($this->feed, '"'));
     $this->assertEquals('&lt;br&gt;', $method->invoke($this->feed, '<br>'));
 }
 /**
  * @dataProvider dpParseOptions
  */
 public function testParseOptions(array $arguments, array $expected)
 {
     /** @var \Delusion\Suggestible $input */
     $input = new ArgvInput();
     Configurator::setCustomBehavior($input, 'getOption', $arguments);
     $this->method->invoke(self::$launcher, $input);
     $this->assertSame($expected, $this->params->all());
 }
Example #12
0
 public function testGetUniversalDomainName()
 {
     $reflector = new ReflectionMethod('\\T4\\Http\\Helpers', 'getUniversalDomainName');
     $reflector->setAccessible(true);
     $this->assertEquals('', $reflector->invoke(null, 'localhost'));
     $this->assertEquals('.mail.ru', $reflector->invoke(null, 'www.mail.ru'));
     $this->assertEquals('.mail.ru', $reflector->invoke(null, 'mail.ru'));
 }
 /**
  * @covers Aws\Common\Signature\AbstractSignature::getTimestamp
  */
 public function testGetTimestampReturnsConsistentTimestamp()
 {
     $signature = $this->getMockBuilder('Aws\\Common\\Signature\\AbstractSignature')->getMockForAbstractClass();
     $method = new \ReflectionMethod('Aws\\Common\\Signature\\AbstractSignature', 'getTimestamp');
     $method->setAccessible(true);
     // Ensure that the timestamp is the same when cached
     $t = $method->invoke($signature);
     $this->assertEquals($t, $method->invoke($signature));
 }
 public function test_create_speaker_return_speaker()
 {
     $method = new ReflectionMethod(get_class($this->speaker_seeker), 'create_speaker');
     $method->setAccessible(true);
     $speaker_mock = $method->invoke($this->speaker_seeker, 'Speaker_Mock');
     $this->assertTrue($speaker_mock instanceof Speaker_Mock);
     $speaker_mock = $method->invoke($this->speaker_seeker, 'Dummy_Speaker_Mock');
     $this->assertNull($speaker_mock);
 }
Example #15
0
 public function testIsDecompressionNeeded()
 {
     $prefix = 'CACHE_COMPRESSION';
     $method = new \ReflectionMethod('Magento\\Framework\\Cache\\Backend\\Decorator\\Compression', '_isDecompressionNeeded');
     $method->setAccessible(true);
     $this->assertFalse($method->invoke($this->_decorator, $this->_testString));
     $this->assertFalse($method->invoke($this->_decorator, 's' . $prefix . $this->_testString));
     $this->assertTrue($method->invoke($this->_decorator, $prefix . $this->_testString));
 }
Example #16
0
 /**
  * Test the private color parsing function. Combined colors.
  *
  * @depends test_class_defined
  */
 public function test_parse_color_pairs()
 {
     $m = new \ReflectionMethod("ansi", "parse_color");
     $m->setAccessible(true);
     $this->assertEquals(0x700, $m->invoke("ansi", "black_in_white"));
     $this->assertEquals(0x1710, $m->invoke("ansi", "Black_in_White"));
     $this->assertEquals(0x417, $m->invoke("ansi", "White_on_blue"));
     $this->assertEquals(0x117, $m->invoke("ansi", "White_on_red"));
 }
Example #17
0
 private function invokePrivateMethod($class, $method, $params, $object = null)
 {
     $method = new ReflectionMethod($class, $method);
     $method->setAccessible(TRUE);
     if ($object !== null) {
         return $method->invoke($object, $params);
     }
     return $method->invoke(new $class(), $params);
 }
 /**
  * @param mixed $offset
  * @param mixed $value
  * @param mixed
  */
 public function offsetSet($offset, $value)
 {
     $valueOffset = $this->offsetMethod->invoke($value, $this->offsetArgs);
     $this->checkValue($value);
     if (!is_null($offset) && $offset !== $valueOffset) {
         throw new \InvalidArgumentException();
     }
     return parent::offsetSet($valueOffset, $value);
 }
Example #19
0
 protected function runTest()
 {
     $this->prepareFormMethod->invoke($this->block);
     $form = $this->block->getForm();
     foreach ($this->expectedFields as $key) {
         $this->assertNotNull($form->getElement($key));
     }
     $this->assertGreaterThan(0, strpos($form->getElement('insert_variable')->getData('text'), 'Insert Variable'));
 }
 /**
  * @covers common\classes\Configuration::load_language
  */
 public function test_load_language()
 {
     $_COOKIE['language'] = 'EN';
     $configuration = $this->get_params('configuration');
     $method = new \ReflectionMethod($this->configuration, 'load_language');
     $method->setAccessible(true);
     $method->invoke($this->configuration, $configuration);
     unset($_COOKIE['language']);
     $method->invoke($this->configuration, $configuration);
 }
 public function testReadLineFromFile()
 {
     $r = new \ReflectionMethod(self::$storage, 'readLineFromFile');
     $r->setAccessible(true);
     $h = tmpfile();
     fwrite($h, "line1\n\n\nline2\n");
     fseek($h, 0, SEEK_END);
     $this->assertEquals('line2', $r->invoke(self::$storage, $h));
     $this->assertEquals('line1', $r->invoke(self::$storage, $h));
 }
Example #22
0
 public function testGetSerializer()
 {
     $mock = $this->getObjectForTrait('Jobby\\SerializerTrait');
     $method = new \ReflectionMethod($mock, 'getSerializer');
     $method->setAccessible(true);
     $serializer = $method->invoke($mock);
     $this->assertInstanceOf('\\SuperClosure\\Serializer', $serializer);
     $serializer2 = $method->invoke($mock);
     $this->assertSame($serializer, $serializer2);
 }
 /**
  * @see RedisLock::isFlagExist
  */
 public function testMethod_isFlagExist()
 {
     $key = static::TEST_KEY;
     $Method = new \ReflectionMethod(RedisLock::class, 'isFlagExist');
     $Method->setAccessible(true);
     $RedisLock = new RedisLock($this->getRedis(), $key);
     $this->assertSame(false, $Method->invoke($RedisLock, RedisLock::FLAG_CATCH_EXCEPTIONS));
     $RedisLock = new RedisLock($this->getRedis(), $key, RedisLock::FLAG_CATCH_EXCEPTIONS);
     $this->assertSame(true, $Method->invoke($RedisLock, RedisLock::FLAG_CATCH_EXCEPTIONS));
 }
Example #24
0
 public function testGetFieldUrisFromClass()
 {
     $reflectionMethod = new \ReflectionMethod(FieldURIManager::class, 'getFieldUrisFromClass');
     $reflectionMethod->setAccessible(true);
     $dictionaryURIs = $reflectionMethod->invoke(new DictionaryURIType(), DictionaryURIType::class);
     $this->assertEquals('contacts:PhysicalAddress:City', $dictionaryURIs['physicaladdress']['contacts']['city']);
     $this->assertEquals('contacts:ImAddress', $dictionaryURIs['imaddress']['contacts']);
     $unindexedFieldURIs = $reflectionMethod->invoke(new DictionaryURIType(), UnindexedFieldURIType::class);
     $this->assertEquals('item:Body', $unindexedFieldURIs['body']['item']);
 }
 public function testTaskEnabled()
 {
     $runner = new TaskRunner();
     $method = new ReflectionMethod($runner, 'taskEnabled');
     $method->setAccessible(true);
     $this->assertTrue($method->invoke($runner, 'TaskRunnerTest_EnabledTask'), 'Enabled task incorrectly marked as disabled');
     $this->assertFalse($method->invoke($runner, 'TaskRunnerTest_DisabledTask'), 'Disabled task incorrectly marked as enabled');
     $this->assertFalse($method->invoke($runner, 'TaskRunnerTest_AbstractTask'), 'Disabled task incorrectly marked as enabled');
     $this->assertTrue($method->invoke($runner, 'TaskRunnerTest_ChildOfAbstractTask'), 'Enabled task incorrectly marked as disabled');
 }
 public function testRegisterWrapper()
 {
     // WrapperFactory::getClass is protected, work around it to avoid
     // creating unnecessary instances and making the test more complex.
     $method = new \ReflectionMethod(get_class($this->factory), 'getWrapperClass');
     $method->setAccessible(true);
     $wrapper = $method->invoke($this->factory, 'proxy');
     $this->factory->registerWrapper('test', $wrapper);
     $this->assertEquals($wrapper, $method->invoke($this->factory, 'test'));
 }
 /** @test */
 public function test_getFileName_excludes_cookies()
 {
     $this->recorder->includeCookies(false);
     $request1 = new Request('GET', 'http://google.com', ['myheader' => 'myvalue', 'Cookie' => 'foo']);
     $request2 = new Request('GET', 'http://google.com', ['myheader' => 'myvalue']);
     $m = new ReflectionMethod($this->recorder, 'getFileName');
     $m->setAccessible(true);
     $this->assertSame('0ec133b60aaa14f35d2185c09e590a48.txt', $m->invoke($this->recorder, $request1));
     $this->assertSame('0ec133b60aaa14f35d2185c09e590a48.txt', $m->invoke($this->recorder, $request2));
 }
Example #28
0
 public function testParseAnnotations()
 {
     $docParser = new DocParser();
     $m = new \ReflectionMethod('Yosmanyga\\Resource\\Util\\DocParser', 'parseAnnotations');
     $m->setAccessible(true);
     $data = array("@AnnotationX({foo1: 'bar1',foo2: 'bar2'})");
     $this->assertEquals(array(0 => array('key' => 'AnnotationX', 'value' => "{foo1: 'bar1',foo2: 'bar2'}")), $m->invoke($docParser, $data));
     $data = array("@AnnotationX");
     $this->assertEquals(array(0 => array('key' => 'AnnotationX', 'value' => "")), $m->invoke($docParser, $data));
 }
 public function testMessageHaveUniqueId()
 {
     $messageTemplate = \Swift_Message::newInstance();
     $handler = new SwiftMailerHandler($this->mailer, $messageTemplate);
     $method = new \ReflectionMethod('Monolog\\Handler\\SwiftMailerHandler', 'buildMessage');
     $method->setAccessible(true);
     $method->invokeArgs($handler, array($messageTemplate, array()));
     $builtMessage1 = $method->invoke($handler, $messageTemplate, array());
     $builtMessage2 = $method->invoke($handler, $messageTemplate, array());
     $this->assertFalse($builtMessage1->getId() === $builtMessage2->getId(), 'Two different messages have the same id');
 }
Example #30
0
 public function testClientURLGenerator()
 {
     // Make the private method public for testing
     $method = new ReflectionMethod(AkismetClient::class, 'getUrl');
     $method->setAccessible(true);
     $client = new AkismetClient($this->key);
     $verifyUrl = $method->invoke($client, 'verify-key');
     $this->assertEquals('https://rest.akismet.com/1.1/verify-key', $verifyUrl, 'The verify-key url that\'s being generated doesn\'t contain the expected string.');
     $verifyUrl = $method->invoke($client, 'comment-check');
     $this->assertEquals("https://{$this->key}.rest.akismet.com/1.1/comment-check", $verifyUrl, 'The comment-check url that\'s being generated doesn\'t contain the expected string.');
 }