本文整理汇总了PHP中ReflectionProperty::setValue方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionProperty::setValue方法的具体用法?PHP ReflectionProperty::setValue怎么用?PHP ReflectionProperty::setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionProperty
的用法示例。
在下文中一共展示了ReflectionProperty::setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDuplicate
/**
* Method to test duplicate().
*
* @param string $label
* @param string $icon
* @param string $id
* @param string $prefix
* @param string $task
*
* @covers \Windwalker\Bootstrap\Dropdown::duplicate
* @dataProvider duplicateProvider
*/
public function testDuplicate($label, $icon, $id, $prefix, $task)
{
// Clean dropDownList property
$this->refDropDownList->setValue(array());
Dropdown::duplicate($id, $prefix);
$this->assertEquals(array('<li>' . '<a href = "javascript://" onclick="listItemTask(\'cb' . $id . '\', \'' . $task . '\')">' . ($icon ? '<span class="icon-' . $icon . '"></span> ' : '') . $label . '</a>' . '</li>'), $this->refDropDownList->getValue());
}
示例2: doInjection
protected function doInjection($instance, $className)
{
$propertiesAnnotations = $this->annotationManager->getPropertiesAnnotations($className);
foreach ($propertiesAnnotations as $propertyName => $annotations) {
if (isset($annotations['Inject'])) {
/** @var \A7\Annotations\Inject $inject */
$inject = $annotations['Inject'];
$reflectionProperty = new \ReflectionProperty($instance, $propertyName);
$reflectionProperty->setAccessible(true);
if (isset($annotations['var'])) {
$inject->setVar($annotations['var']);
}
$inject->isInjectObject();
if ($inject->isInjectObject()) {
$reflectionProperty->setValue($instance, $this->a7->get($inject->getName()));
} else {
$name = $inject->getName();
if (isset($name) && isset($this->parameters[$name])) {
$reflectionProperty->setValue($instance, $this->parameters[$name]);
}
}
}
}
return $instance;
}
示例3: __set
/**
* __set.
*
* Overloading method to set any $key property to $this->class or if not static,
* to $this->object.
*
* @param $key
* @param $value
* @return $this
*/
public function __set($key, $value)
{
$property = new \ReflectionProperty($this->class, $key);
$property->setAccessible(true);
$property->isStatic() ? $property->setValue($value) : $property->setValue($this->object, $value);
return $this;
}
示例4: doMockResponse
public function doMockResponse($set_minimal, $body_id, $set_title)
{
$restoreInstance = PMA\libraries\Response::getInstance();
// mock footer
$mockFooter = $this->getMockBuilder('PMA\\libraries\\Footer')->disableOriginalConstructor()->setMethods(array('setMinimal'))->getMock();
$mockFooter->expects($this->exactly($set_minimal))->method('setMinimal')->with();
// mock header
$mockHeader = $this->getMockBuilder('PMA\\libraries\\Header')->disableOriginalConstructor()->setMethods(array('setBodyId', 'setTitle', 'disableMenuAndConsole', 'addHTML'))->getMock();
$mockHeader->expects($this->exactly($body_id))->method('setBodyId')->with('loginform');
$mockHeader->expects($this->exactly($set_title))->method('setTitle')->with('Access denied!');
$mockHeader->expects($this->exactly($set_title))->method('disableMenuAndConsole')->with();
// set mocked headers and footers
$mockResponse = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('getHeader', 'getFooter', 'addHTML', 'header', 'headersSent'))->getMock();
$mockResponse->expects($this->exactly($set_title))->method('getFooter')->with()->will($this->returnValue($mockFooter));
$mockResponse->expects($this->exactly($set_title))->method('getHeader')->with()->will($this->returnValue($mockHeader));
$mockResponse->expects($this->any())->method('headersSent')->with()->will($this->returnValue(false));
$mockResponse->expects($this->exactly($set_title * 6))->method('addHTML')->with();
$attrInstance = new ReflectionProperty('PMA\\libraries\\Response', '_instance');
$attrInstance->setAccessible(true);
$attrInstance->setValue($mockResponse);
$headers = array_slice(func_get_args(), 3);
$header_method = $mockResponse->expects($this->exactly(count($headers)))->method('header');
call_user_func_array(array($header_method, 'withConsecutive'), $headers);
try {
$this->assertFalse($this->object->auth());
} finally {
$attrInstance->setValue($restoreInstance);
}
}
示例5: testStringifyFail
/**
* @expectedException \InvalidArgumentException
*/
public function testStringifyFail()
{
$ip = TestDataGenerator::ipString();
$range = new Range(new IP($ip), new IP($ip));
$mockConverter = $this->getMock('Bankiru\\IPTools\\Interfaces\\RangeConverterInterface');
$mockConverter->expects($this->once())->method('stringify')->with($this->equalTo($range))->willThrowException(new \InvalidArgumentException('INVALID RANGE'));
$this->refProp->setValue(null, array($mockConverter));
$this->instance->stringify($range);
$this->fail('parse should fail on invalid input');
}
示例6: testRemoveApiKey
public function testRemoveApiKey()
{
$user = User::create('Ma27', '123456', 'Ma27@sententiaregum.dev', new PhpPasswordHasher());
$p = new \ReflectionProperty($user, 'apiKey');
$p->setAccessible(true);
$this->assertEmpty($user->getApiKey());
$p->setValue($user, 'key');
$this->assertNotEmpty($user->getApiKey());
$p->setValue($user, null);
$this->assertEmpty($user->getApiKey());
}
示例7: testStreamIncludeWithRealFile
public function testStreamIncludeWithRealFile()
{
$property = new ReflectionProperty('rex_stream', 'useRealFiles');
$property->setAccessible(true);
$property->setValue(true);
$content = 'foo <?php echo "bar";';
$streamUrl = rex_stream::factory('test-stream/2', $content);
ob_start();
require $streamUrl;
$result = ob_get_clean();
$this->assertEquals('foo bar', $result);
$property->setValue(null);
}
示例8: testGetOptions
public function testGetOptions()
{
$this->getModel($this->validatorMock);
$appStateProperty = new \ReflectionProperty('Magento\\Framework\\Session\\Config', 'options');
$appStateProperty->setAccessible(true);
$original = $appStateProperty->getValue($this->config);
$valueForTest = ['test' => 'test2'];
$appStateProperty->setValue($this->config, $valueForTest);
$this->assertEquals($valueForTest, $this->config->getOptions());
$this->assertEquals($valueForTest, $this->config->toArray());
$appStateProperty->setValue($this->config, $original);
$this->assertEquals($original, $this->config->getOptions());
$this->assertEquals($original, $this->config->toArray());
}
示例9: setAttribute
/**
* Set protected/private attribute of object
*
* @param object &$object Object containing attribute
* @param string $attributeName Attribute name to change
* @param string $value Value to set attribute to
*
* @return null
*/
public function setAttribute(&$object, $attributeName, $value)
{
$class = is_object($object) ? get_class($object) : $object;
$reflection = new \ReflectionProperty($class, $attributeName);
$reflection->setAccessible(true);
$reflection->setValue($object, $value);
}
示例10: __construct
/**
* Constructs the exception.
* @link http://php.net/manual/en/errorexception.construct.php
* @param $message [optional]
* @param $code [optional]
* @param $severity [optional]
* @param $filename [optional]
* @param $lineno [optional]
* @param $previous [optional]
*/
public function __construct($message = '', $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, \Exception $previous = null)
{
parent::__construct($message, $code, $severity, $filename, $lineno, $previous);
if (function_exists('xdebug_get_function_stack')) {
$trace = array_slice(array_reverse(xdebug_get_function_stack()), 3, -1);
foreach ($trace as &$frame) {
if (!isset($frame['function'])) {
$frame['function'] = 'unknown';
}
// XDebug < 2.1.1: http://bugs.xdebug.org/view.php?id=695
if (!isset($frame['type']) || $frame['type'] === 'static') {
$frame['type'] = '::';
} elseif ($frame['type'] === 'dynamic') {
$frame['type'] = '->';
}
// XDebug has a different key name
if (isset($frame['params']) && !isset($frame['args'])) {
$frame['args'] = $frame['params'];
}
}
$ref = new \ReflectionProperty('Exception', 'trace');
$ref->setAccessible(true);
$ref->setValue($this, $trace);
}
}
示例11: testValidateSetEntityAttributeValuesWithoutResource
public function testValidateSetEntityAttributeValuesWithoutResource()
{
$product = $this->getMock('Magento\\Framework\\Model\\AbstractModel', ['someMethod', 'getResource', 'load'], [], '', false);
$this->_condition->setAttribute('someAttribute');
$product->setAtribute('attribute');
$product->setId(12);
$this->_configProperty->setValue($this->_condition, $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false));
$this->_entityAttributeValuesProperty->setValue($this->_condition, $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false));
$attribute = new \Magento\Framework\DataObject();
$attribute->setBackendType('multiselect');
$newResource = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product', ['getAttribute'], [], '', false);
$newResource->expects($this->any())->method('getAttribute')->with('someAttribute')->will($this->returnValue($attribute));
$newResource->_config = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
$product->expects($this->atLeastOnce())->method('getResource')->willReturn($newResource);
$this->_entityAttributeValuesProperty->setValue($this->_condition, [1 => [''], 2 => ['option1,option2,option3'], 3 => ['option1,option2,option3']]);
$this->assertFalse($this->_condition->validate($product));
$attribute = new \Magento\Framework\DataObject();
$attribute->setBackendType(null);
$attribute->setFrontendInput('multiselect');
$newResource = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product', ['getAttribute'], [], '', false);
$newResource->expects($this->any())->method('getAttribute')->with('someAttribute')->will($this->returnValue($attribute));
$newResource->_config = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
$product->setResource($newResource);
$product->setId(1);
$product->setData('someAttribute', 'value');
$this->assertFalse($this->_condition->validate($product));
}
示例12: enableOpenSSL
private function enableOpenSSL()
{
$ref = new \ReflectionProperty('Bitpay\\Util\\SecureRandom', 'hasOpenSSL');
$ref->setAccessible(true);
$ref->setValue(null);
$ref->setAccessible(false);
}
示例13: setProperty
/**
* @param object $object
* @param string $property
* @param mixed $value
* @return $this
*/
protected function setProperty($object, $property, $value)
{
$reflection = new \ReflectionProperty(get_class($object), $property);
$reflection->setAccessible(true);
$reflection->setValue($object, $value);
return $this;
}
示例14: testSearchPercentile
/**
* @covers ArticleQualityService::searchPercentile
*/
public function testSearchPercentile()
{
$mock = $this->getMockBuilder("\\ArticleQualityService")->disableOriginalConstructor()->setMethods(['__construct'])->getMock();
$refl = new \ReflectionMethod($mock, 'searchPercentile');
$refl->setAccessible(true);
$prop = new \ReflectionProperty($mock, 'percentiles');
$prop->setAccessible(true);
$prop->setValue($mock, [1 => 0.1, 2 => 0.2, 3 => 0.3, 4 => 0.4]);
$this->assertEquals(2, $refl->invoke($mock, 0.25));
$this->assertEquals(4, $refl->invoke($mock, 0.5));
$this->assertEquals(1, $refl->invoke($mock, 0.05));
$prop->setValue($mock, [-1 => -0.1, 0 => 0.05, 1 => 0.8]);
$this->assertEquals(-1, $refl->invoke($mock, -2));
$this->assertEquals(0, $refl->invoke($mock, 0.4));
$this->assertEquals(1, $refl->invoke($mock, 1));
}
示例15: updateRevision
protected function updateRevision(AbstractRevision $revision, AbstractRevision $previous = null)
{
$this->contentLengthProperty->setValue($revision, $this->calcContentLength($revision));
if ($previous !== null) {
$this->previousContentLengthProperty->setValue($revision, $this->calcContentLength($previous));
}
}