/** * @param bool $canReturnToStock * @param bool $manageStock * @param bool $result * @dataProvider canReturnItemsToStockDataProvider */ public function testCanReturnItemsToStock($canReturnToStock, $manageStock, $result) { $productId = 7; $property = new \ReflectionProperty($this->items, '_canReturnToStock'); $property->setAccessible(true); $this->assertNull($property->getValue($this->items)); $this->scopeConfig->expects($this->once())->method('getValue')->with($this->equalTo(\Magento\CatalogInventory\Model\Stock\Item::XML_PATH_CAN_SUBTRACT), $this->equalTo(\Magento\Store\Model\ScopeInterface::SCOPE_STORE))->will($this->returnValue($canReturnToStock)); if ($canReturnToStock) { $orderItem = $this->getMock('Magento\\Sales\\Model\\Order\\Item', ['getProductId', '__wakeup'], [], '', false); $orderItem->expects($this->once())->method('getProductId')->will($this->returnValue($productId)); $creditMemoItem = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo\\Item', ['setCanReturnToStock', 'getOrderItem', '__wakeup'], [], '', false); $creditMemo = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo', [], [], '', false); $creditMemo->expects($this->once())->method('getAllItems')->will($this->returnValue([$creditMemoItem])); $creditMemoItem->expects($this->once())->method('getOrderItem')->will($this->returnValue($orderItem)); $this->stockItemMock->expects($this->once())->method('getManageStock')->with($this->equalTo($productId))->will($this->returnValue($manageStock)); $creditMemoItem->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf()); $order = $this->getMock('Magento\\Sales\\Model\\Order', ['setCanReturnToStock', '__wakeup'], [], '', false); $order->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf()); $creditMemo->expects($this->once())->method('getOrder')->will($this->returnValue($order)); $this->registryMock->expects($this->any())->method('registry')->with('current_creditmemo')->will($this->returnValue($creditMemo)); } $this->assertSame($result, $this->items->canReturnItemsToStock()); $this->assertSame($result, $property->getValue($this->items)); // lazy load test $this->assertSame($result, $this->items->canReturnItemsToStock()); }
public function __construct($class, $property) { $property = new ReflectionProperty($class, $property); list($description, $tags) = Kodoc::parse($property->getDocComment()); $this->description = $description; if ($modifiers = $property->getModifiers()) { $this->modifiers = '<small>' . implode(' ', Reflection::getModifierNames($modifiers)) . '</small> '; } if (isset($tags['var'])) { if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/', $tags['var'][0], $matches)) { $this->type = $matches[1]; if (isset($matches[2])) { $this->description = Markdown($matches[2]); } } } $this->property = $property; // Show the value of static properties, but only if they are public or we are php 5.3 or higher and can force them to be accessible if ($property->isStatic() and ($property->isPublic() or version_compare(PHP_VERSION, '5.3', '>='))) { // Force the property to be accessible if (version_compare(PHP_VERSION, '5.3', '>=')) { $property->setAccessible(TRUE); } // Don't debug the entire object, just say what kind of object it is if (is_object($property->getValue($class))) { $this->value = '<pre>object ' . get_class($property->getValue($class)) . '()</pre>'; } else { $this->value = Kohana::debug($property->getValue($class)); } } }
public function __construct($class, $property, $default = null) { $property = new \ReflectionProperty($class, $property); list($description, $tags) = $this->userguide->parse($property->getDocComment()); $this->description = $description; if ($modifiers = $property->getModifiers()) { $this->modifiers = '<small>' . implode(' ', \Reflection::getModifierNames($modifiers)) . '</small> '; } if (isset($tags['var'])) { if (preg_match('/^(\\S*)(?:\\s*(.+?))?$/s', $tags['var'][0], $matches)) { $this->type = $matches[1]; if (isset($matches[2])) { $this->description = $this->markdown->transform($matches[2]); } } } $this->property = $property; // Show the value of static properties, but only if they are public or we are php 5.3 or // higher and can force them to be accessible if ($property->isStatic()) { $property->setAccessible(true); // Don't debug the entire object, just say what kind of object it is if (is_object($property->getValue($class))) { $this->value = '<pre>object ' . get_class($property->getValue($class)) . '()</pre>'; } else { $this->value = Debug::vars($property->getValue($class)); } } // Store the defult property $this->default = Debug::vars($default); }
function reflectProperty($class, $property) { $propInfo = new ReflectionProperty($class, $property); echo "**********************************\n"; echo "Reflecting on property {$class}::{$property}\n\n"; echo "__toString():\n"; var_dump($propInfo->__toString()); echo "export():\n"; var_dump(ReflectionProperty::export($class, $property, true)); echo "export():\n"; var_dump(ReflectionProperty::export($class, $property, false)); echo "getName():\n"; var_dump($propInfo->getName()); echo "isPublic():\n"; var_dump($propInfo->isPublic()); echo "isPrivate():\n"; var_dump($propInfo->isPrivate()); echo "isProtected():\n"; var_dump($propInfo->isProtected()); echo "isStatic():\n"; var_dump($propInfo->isStatic()); $instance = new $class(); if ($propInfo->isPublic()) { echo "getValue():\n"; var_dump($propInfo->getValue($instance)); $propInfo->setValue($instance, "NewValue"); echo "getValue() after a setValue():\n"; var_dump($propInfo->getValue($instance)); } echo "\n**********************************\n"; }
/** * @param bool $canReturnToStock * @param bool $manageStock * @param bool $result * @dataProvider canReturnItemsToStockDataProvider */ public function testCanReturnItemsToStock($canReturnToStock, $manageStock, $result) { $productId = 7; $property = new \ReflectionProperty($this->items, '_canReturnToStock'); $property->setAccessible(true); $this->assertNull($property->getValue($this->items)); $this->stockConfiguration->expects($this->once())->method('canSubtractQty')->will($this->returnValue($canReturnToStock)); if ($canReturnToStock) { $orderItem = $this->getMock('Magento\\Sales\\Model\\Order\\Item', ['getProductId', '__wakeup', 'getStore'], [], '', false); $store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId'], [], '', false); $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue(10)); $orderItem->expects($this->any())->method('getStore')->will($this->returnValue($store)); $orderItem->expects($this->once())->method('getProductId')->will($this->returnValue($productId)); $creditMemoItem = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo\\Item', ['setCanReturnToStock', 'getOrderItem', '__wakeup'], [], '', false); $creditMemo = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo', [], [], '', false); $creditMemo->expects($this->once())->method('getAllItems')->will($this->returnValue([$creditMemoItem])); $creditMemoItem->expects($this->any())->method('getOrderItem')->will($this->returnValue($orderItem)); $this->stockItemMock->expects($this->once())->method('getManageStock')->will($this->returnValue($manageStock)); $creditMemoItem->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf()); $order = $this->getMock('Magento\\Sales\\Model\\Order', ['setCanReturnToStock', '__wakeup'], [], '', false); $order->expects($this->once())->method('setCanReturnToStock')->with($this->equalTo($manageStock))->will($this->returnSelf()); $creditMemo->expects($this->once())->method('getOrder')->will($this->returnValue($order)); $this->registryMock->expects($this->any())->method('registry')->with('current_creditmemo')->will($this->returnValue($creditMemo)); } $this->assertSame($result, $this->items->canReturnItemsToStock()); $this->assertSame($result, $property->getValue($this->items)); // lazy load test $this->assertSame($result, $this->items->canReturnItemsToStock()); }
/** * @param $entity * @return \ActiveLAMP\Taxonomy\Entity\PluralVocabularyField|ArrayCollection */ public function extractValueInField($entity) { $this->property->setAccessible(true); $field = $this->property->getValue($entity); $this->property->setAccessible(false); return $field; }
/** * 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()); }
public function __get($key) { $property = new \ReflectionProperty($this->class, $key); if (!$property->isPublic()) { $property->setAccessible(true); } return $property->isStatic() ? $property->getValue() : $property->getValue($this->object); }
/** * Prepares the environment before running a test. */ protected function setUp() { parent::setUp(); $this->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; $_SERVER['HTTP_USER_AGENT'] = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.2) Gecko/2008092313 Ubuntu/8.04 (hardy) Firefox/3.0.2 FirePHP/0.1.2"; $this->Log_FirePHP = new Log_FirePHPTable("Test"); $this->unique_base = $this->prop_unique_base->getValue($this->Log_FirePHP); }
/** * @covers ::autoFilter */ public function testAutoFilter() { $property = new \ReflectionProperty(get_class($this->container), 'autoFilter'); $property->setAccessible(true); $this->assertFalse($property->getValue($this->container)); $this->container->autoFilter(); $this->assertTrue($property->getValue($this->container)); }
/** * Constructor * @param \PHP_CodeSniffer_File $phpcsFile */ public function __construct(PHP_CodeSniffer_File $phpcsFile) { $this->phpcsFile = $phpcsFile; $this->reflection = new ReflectionProperty($this->phpcsFile, 'ruleset'); $this->reflection->setAccessible(true); $this->current = $this->reflection->getValue($this->phpcsFile); $this->backup = $this->current; }
/** * @static * * @param FormBuilderInterface $formBuilder * * @return array */ private static function getKeys(FormBuilderInterface $formBuilder) { if (!self::$reflection) { self::$reflection = new \ReflectionProperty(get_class($formBuilder), 'children'); self::$reflection->setAccessible(true); } return array_keys(self::$reflection->getValue($formBuilder)); }
/** * @return Writer */ protected function getWriter() { if (null == $this->refField) { $this->refField = new \ReflectionProperty(get_parent_class($this), 'writer'); $this->refField->setAccessible(true); } return $this->refField->getValue($this); }
public function getValue($entity) { $value = null; if ($this->property) { $value = $this->property->getValue($entity); } return $value; }
private function getProperty($classOrObject, $property) { $property = new \ReflectionProperty(is_object($classOrObject) ? get_class($classOrObject) : $classOrObject, $property); if (!$property->isPublic()) { $property->setAccessible(true); } return $property->isStatic() ? $property->getValue($classOrObject) : $property->getValue(); }
/** * Тест установки флага инверсии. * @covers \Epay\Sign::setInvert() */ public function testSetInvert() { $reflection = new \ReflectionProperty($this->sign, 'invertResult'); $reflection->setAccessible(true); $this->sign->setInvert(true); $this->assertTrue($reflection->getValue($this->sign)); $this->sign->setInvert(false); $this->assertFalse($reflection->getValue($this->sign)); }
/** * @param object $object * * @return bool */ public function isLabelSet($object) { $this->reflectionProperty->setAccessible(true); $v = $this->reflectionProperty->getValue($object); if (true === $v) { return true; } return false; }
public function testLookAhead() { $scanner = new Scanner(new File(FILES_DIR . 'not_empty_file')); $property = new \ReflectionProperty('PHPML\\Parser\\Scanner', 'lookAhead'); $property->setAccessible(true); $this->assertEquals(Token::T_OPEN_TAG | Token::T_TEXT, $property->getValue($scanner)); $scanner->setLookAhead(Token::T_ATTRIBUTE); $this->assertEquals(Token::T_ATTRIBUTE, $property->getValue($scanner)); }
/** * @test */ public function dequeue() { $property = new \ReflectionProperty('\\Ackintosh\\Snidel\\Task\\Queue', 'dequeuedCount'); $property->setAccessible(true); $this->assertSame(0, $property->getValue($this->queue)); $this->queue->enqueue(new Task('receivesArgumentsAndReturnsIt', 'foo', null)); $this->queue->dequeue(); $this->assertSame(1, $property->getValue($this->queue)); }
public function testSetRate() { $card = new IdCard(); $rp = new \ReflectionProperty($card, 'rate'); $rp->setAccessible(true); $this->assertNull($rp->getValue($card)); $card->setRate(10); $this->assertEquals(10, $rp->getValue($card)); }
public function testFilePath() { $mgr = $this->createImageSeekManager(null, null, null, null, array('filePath' => '/no-trailing')); $rp = new \ReflectionProperty($mgr, 'filePath'); $rp->setAccessible(true); $this->assertSame('/no-trailing/', $rp->getValue($mgr)); $mgr = $this->createImageSeekManager(null, null, null, null, array('filePath' => '/trailing/')); $this->assertSame('/trailing/', $rp->getValue($mgr)); }
/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { $option = 'com_advencedmodeltest'; $this->reflectedJComponentHelper = new \ReflectionProperty('JComponentHelper', 'components'); $this->reflectedJComponentHelper->setAccessible(true); $this->originComponents = $this->reflectedJComponentHelper->getValue(); $newComponents = $this->originComponents; $newComponents[$option] = (object) array('id' => 9999999, 'option' => $option, 'params' => new \JRegistry(array('foo' => 'bar', 'bar' => 'foo', 'foobar' => 123)), 'enabled' => true); $this->reflectedJComponentHelper->setValue($newComponents); }
/** * @dataProvider providerSetter * @param string $property * @param mixed $value */ public function testSetter($property, $value) { $bridge = new Bridge(); $reflection = new \ReflectionProperty($bridge, $property); $reflection->setAccessible(true); $this->assertNull($reflection->getValue($bridge)); $setter = 'set' . ucfirst($property); $bridge->{$setter}($value); $this->assertEquals($value, $reflection->getValue($bridge)); }
public function testSetLogger() { $this->assertInstanceOf('Psr\\Log\\LoggerAwareInterface', $this->twitter); $loggerProperty = new \ReflectionProperty($this->twitter, 'logger'); $loggerProperty->setAccessible(true); $this->assertSame($this->logger, $loggerProperty->getValue($this->twitter)); $newLogger = $this->getMock('Psr\\Log\\LoggerInterface'); $this->twitter->setLogger($newLogger); $this->assertSame($newLogger, $loggerProperty->getValue($this->twitter)); }
public static function setUpBeforeClass() { // The strategy has already been created during the bootstrapping of EngineBlock. Thus it needs to be removed // temporarily while we execute tests. $refl = new ReflectionClass('EngineBlock_Log_Monolog_Handler_FingersCrossed_ManualOrErrorLevelActivationStrategyFactory'); self::$strategyProperty = $refl->getProperty('strategy'); self::$strategyProperty->setAccessible(true); self::$wasStrategy = self::$strategyProperty->getValue(); self::$strategyProperty->setValue(null); }
private function getKeys($transformer) { if ($this->keyReflectionCache === null) { // Using reflection since we want to support more then just the repeated form type. $reflection = new \ReflectionProperty(get_class($transformer), 'keys'); $reflection->setAccessible(true); $this->keyReflectionCache = $reflection; } return $this->keyReflectionCache->getValue($transformer); }
/** * testSetContainer * * @return void */ public function testSetContainer() { $bundle = new StubBundle('test'); $refContainer = new \ReflectionProperty($bundle, 'container'); $refContainer->setAccessible(true); $bundle->setContainer(new StubContainer()); $this->assertInstanceOf('Windwalker\\Test\\Bundle\\Stub\\StubContainer', $refContainer->getValue($bundle)); $bundle->setContainer(new Container()); $this->assertInstanceOf('Windwalker\\DI\\Container', $refContainer->getValue($bundle)); }
/** * @test */ public function it_should_add_a_handler() { $commandBus = new CommandBus(); $handler = new CommandHandler_stub(); $reflection = new \ReflectionProperty($commandBus, 'handlers'); $reflection->setAccessible(true); $this->assertSame([], $reflection->getValue($commandBus)); $commandBus->addHandler($handler, 'HCLabs\\Bills\\Tests\\Command\\Command_stub'); $this->assertSame(['HCLabs\\Bills\\Tests\\Command\\Command_stub' => $handler], $reflection->getValue($commandBus)); }
public function testSetGetIsJson() { $isJsonProperty = new \ReflectionProperty(get_class($this->_inlineParser), '_isJson'); $isJsonProperty->setAccessible(true); $this->assertFalse($isJsonProperty->getValue($this->_inlineParser)); $setIsJsonMethod = new \ReflectionMethod($this->_inlineParser, 'setIsJson'); $setIsJsonMethod->setAccessible(true); $setIsJsonMethod->invoke($this->_inlineParser, true); $this->assertTrue($isJsonProperty->getValue($this->_inlineParser)); }
public static function setupBeforeClass() { $reflectedClass = new ReflectionClass('CM_Class_Abstract'); self::$_configCacheFlag = $reflectedClass->getProperty('_classConfigCacheEnabled'); self::$_configCacheFlag->setAccessible(true); self::$_configCacheFlagBackup = self::$_configCacheFlag->getValue(); self::$_configCacheFlag->setValue(true); CM_Config::get()->CM_Class_AbstractMock = new stdClass(); CM_Config::get()->CM_Class_AbstractMock->types[CM_Class_Implementation::getTypeStatic()] = 'CM_Class_Implementation'; }