Example #1
1
 /**
  * @dataProvider getPreNormalizationTests
  */
 public function testPreNormalize($denormalized, $normalized)
 {
     $node = new ArrayNode('foo');
     $r = new \ReflectionMethod($node, 'preNormalize');
     $r->setAccessible(true);
     $this->assertSame($normalized, $r->invoke($node, $denormalized));
 }
 public function testAccessor()
 {
     $reflectionMethod = new \ReflectionMethod(BladedFacade::class, 'getFacadeAccessor');
     $reflectionMethod->setAccessible(true);
     $this->assertSame(BladedServiceProvider::PROVIDES_SERVICE, $reflectionMethod->invoke(null));
     $reflectionMethod->setAccessible(false);
 }
 public function testUses()
 {
     $usesMethod = new \ReflectionMethod($this->testInstance, 'uses');
     $usesMethod->setAccessible(true);
     $this->assertSame(['Illuminate\\Translation\\TranslationServiceProvider'], $usesMethod->invoke($this->testInstance));
     $usesMethod->setAccessible(false);
 }
 public function testUses()
 {
     $reflectionMethod = new \ReflectionMethod($this->testInstance, 'uses');
     $reflectionMethod->setAccessible(true);
     $this->assertSame([ValidationLocatorServiceProvider::class], $reflectionMethod->invoke($this->testInstance));
     $reflectionMethod->setAccessible(false);
 }
 public function testUses()
 {
     $usesMethod = new \ReflectionMethod($this->testInstance, 'uses');
     $usesMethod->setAccessible(true);
     $this->assertSame([SessionServiceProvider::class, RoutingServiceProvider::class], $usesMethod->invoke($this->testInstance));
     $usesMethod->setAccessible(false);
 }
 /**
  * @param \ReflectionMethod $setterMethod
  */
 public function setSetterMethod($setterMethod)
 {
     $this->setterMethod = $setterMethod;
     if ($this->setterMethod) {
         $this->setterMethod->setAccessible(TRUE);
     }
 }
Example #7
0
 /**
  * Constructor
  *
  * @param string $class
  * @param string $name
  */
 public function __construct($class, $name)
 {
     $this->class = $class;
     $this->name = $name;
     $this->reflection = new \ReflectionMethod($class, $name);
     $this->reflection->setAccessible(true);
 }
 public function testAccessor()
 {
     $method = new \ReflectionMethod(ValidationLocator::class, 'getFacadeAccessor');
     $method->setAccessible(true);
     $this->assertSame(ValidationLocatorServiceProvider::PROVIDES_LOCATOR, $method->invoke(null));
     $method->setAccessible(false);
 }
 public function testFacade()
 {
     $accessorMethod = new \ReflectionMethod(NavigationBagFacade::class, 'getFacadeAccessor');
     $accessorMethod->setAccessible(true);
     $this->assertSame(NavigationBagServiceProvider::PROVIDES_SERVICE, $accessorMethod->invoke(null));
     $accessorMethod->setAccessible(false);
 }
 /**
  * Test the sanity check for behaviour on empty children list
  * which should never happen as this is protected method
  */
 public function testGetLastChildKey()
 {
     $object = JsonNode::factory(array());
     $method = new \ReflectionMethod($object, 'getLastChildKey');
     $method->setAccessible(true);
     $this->assertNull($method->invoke($object));
     $method->setAccessible(false);
 }
 public function setup()
 {
     $class = new \ReflectionClass('BsbFlysystem\\Adapter\\Factory\\DropboxAdapterFactory');
     $this->property = $class->getProperty('options');
     $this->property->setAccessible(true);
     $this->method = $class->getMethod('validateConfig');
     $this->method->setAccessible(true);
 }
 public function __construct(PropertyAnnotation $annotation, \ReflectionMethod $reflection)
 {
     $this->reflection = $reflection;
     $this->annotation = $annotation;
     if ($this->reflection->isPrivate() || $this->reflection->isProtected()) {
         $this->reflection->setAccessible(true);
     }
 }
 public function setup()
 {
     $class = new \ReflectionClass('BsbFlysystemTest\\Assets\\SimpleAdapterFactory');
     $this->property = $class->getProperty('options');
     $this->property->setAccessible(true);
     $this->method = $class->getMethod('mergeMvcConfig');
     $this->method->setAccessible(true);
 }
 /**
  * Set up
  */
 protected function setUp()
 {
     require_once 'Fixtures/ConditionMatcherUserFuncs.php';
     $this->backupApplicationContext = GeneralUtility::getApplicationContext();
     $this->conditionMatcher = $this->getMockForAbstractClass(AbstractConditionMatcher::class);
     $this->evaluateConditionCommonMethod = new \ReflectionMethod(AbstractConditionMatcher::class, 'evaluateConditionCommon');
     $this->evaluateConditionCommonMethod->setAccessible(TRUE);
 }
 /**
  * @dataProvider shortTypesToFqcnProvider
  */
 public function testGetFormTypeFqcn($shortType, $expected)
 {
     $configuratorMock = $this->getMockBuilder('JavierEguiluz\\Bundle\\EasyAdminBundle\\Configuration\\Configurator')->disableOriginalConstructor()->getMock();
     $type = new EasyAdminFormType($configuratorMock, array(), array());
     $method = new \ReflectionMethod($type, 'getFormTypeFqcn');
     $method->setAccessible(true);
     $this->assertSame($expected, $method->invoke($type, $shortType));
     $method->setAccessible(false);
 }
Example #16
0
 public function setUp()
 {
     parent::setUp();
     $this->orderByTrait = $this->getObjectForTrait(OrderByTrait::class);
     $this->queryBuilder = $this->prophesize(QueryBuilder::class);
     $reflectionClass = new \ReflectionClass($this->orderByTrait);
     $this->addOrderByFunction = $reflectionClass->getMethod('addOrderBy');
     $this->addOrderByFunction->setAccessible(true);
 }
 /**
  * @param AclCheckerInterface $aclChecker
  * @param Stopwatch           $stopwatch
  */
 public function __construct(AclCheckerInterface $aclChecker, Stopwatch $stopwatch)
 {
     $this->getObjectToSecure = new \ReflectionMethod('Nuxia\\AclBundle\\Manager\\AclChecker', 'getObjectToSecure');
     $this->getObjectToSecure->setAccessible(true);
     $aclIdentifierProperty = new \ReflectionProperty('Nuxia\\AclBundle\\Manager\\AclChecker', 'aclIdentifier');
     $aclIdentifierProperty->setAccessible(true);
     $this->aclIdentifier = $aclIdentifierProperty->getValue($aclChecker);
     $this->aclChecker = $aclChecker;
     $this->stopwatch = $stopwatch;
     $this->checks = [];
 }
Example #18
0
 public function testShutDownCallback()
 {
     $shutDownMethod = new \ReflectionMethod($this->testInstance, 'shutDownCallback');
     $shutDownMethod->setAccessible(true);
     /**
      * @var callable $shutDownCallback
      */
     $shutDownCallback = $shutDownMethod->invoke($this->testInstance);
     $shutDownCallback();
     $shutDownMethod->setAccessible(false);
 }
Example #19
0
 public function testSetupCurrencyCode()
 {
     $reflMethod = new \ReflectionMethod('MoneyLaundry\\Filter\\AbstractFilter', 'setupCurrencyCode');
     $reflMethod->setAccessible(true);
     $mock = $this->getMockBuilder('MoneyLaundry\\Filter\\AbstractFilter')->enableProxyingToOriginalMethods()->setMethods(['getFormatter', 'getCurrencyCode'])->getMockForAbstractClass();
     $formatter = \NumberFormatter::create('it_IT', \NumberFormatter::CURRENCY);
     $mock->expects($this->at(0))->method('getFormatter')->willReturn($formatter);
     $mock->expects($this->at(1))->method('getCurrencyCode')->willReturn($formatter->getTextAttribute(\NumberFormatter::CURRENCY_CODE));
     $this->assertSame($formatter->getTextAttribute(\NumberFormatter::CURRENCY_CODE), $reflMethod->invoke($mock));
     $reflMethod->setAccessible(false);
 }
Example #20
0
 /**
  * @covers Doctrine\ODM\PHPCR\DocumentManager::contains
  */
 public function testContains()
 {
     $session = $this->getMock('PHPCR\\SessionInterface');
     $dm = DocumentManager::create($session);
     $obj = new \stdClass();
     $uow = $dm->getUnitOfWork();
     $method = new \ReflectionMethod($uow, 'registerDocument');
     $method->setAccessible(true);
     $method->invoke($uow, $obj, '/foo');
     $method->setAccessible(false);
     $this->assertTrue($dm->contains($obj));
 }
Example #21
0
 /**
  * @param object $object
  * @param string $method
  * @param array  $args
  *
  * @return mixed
  */
 protected function callPrivateMethod($object, $method, $args = array())
 {
     $reflectionMethod = new \ReflectionMethod($object, $method);
     if ($reflectionMethod->isPrivate() || $reflectionMethod->isProtected()) {
         $reflectionMethod->setAccessible(true);
         $result = $reflectionMethod->invokeArgs($reflectionMethod->isStatic() ? null : $object, $args);
         $reflectionMethod->setAccessible(false);
         return $result;
     } else {
         return call_user_func_array(array($object, $method), $args);
     }
 }
 protected function setUp()
 {
     $this->method = new \ReflectionMethod(self::$launcher, 'overwriteParams');
     $this->method->setAccessible(true);
     $property = new \ReflectionProperty(self::$launcher, 'container');
     $property->setAccessible(true);
     /** @var ContainerBuilder $container */
     $container = $property->getValue(self::$launcher);
     $this->params = $container->getParameterBag();
     $this->assertInternalType('array', $this->params->all());
     $this->assertEmpty($this->params->all());
 }
Example #23
0
 public function setUp()
 {
     $this->expectedFields = ['base_fieldset', 'template_code', 'template_subject', 'orig_template_variables', 'variables', 'template_variables', 'insert_variable', 'template_text', 'template_styles'];
     $this->objectManager = Bootstrap::getObjectManager();
     $this->template = $this->objectManager->get('Magento\\Email\\Model\\Template')->setId(1)->setTemplateType(TemplateTypesInterface::TYPE_HTML);
     $this->registry = $this->objectManager->get('Magento\\Framework\\Registry');
     if ($this->registry->registry('current_email_template') == null) {
         $this->registry->register('current_email_template', $this->template);
     }
     $this->block = $this->objectManager->create('Magento\\Email\\Block\\Adminhtml\\Template\\Edit\\Form');
     $this->prepareFormMethod = new \ReflectionMethod('Magento\\Email\\Block\\Adminhtml\\Template\\Edit\\Form', '_prepareForm');
     $this->prepareFormMethod->setAccessible(true);
 }
Example #24
0
 /**
  * When instancing a Field use reflection to connect the Form
  *
  * @param string $name the name of the field
  * @param array $attr the html attributes
  * @param array $settings the settings of the field
  * @param bool|true $label show the label
  *
  * @internal A Form must be passed for the field to work
  */
 public function __construct($name, array $attr = array(), array $settings = array(), $label = true)
 {
     $args = func_get_args();
     $this->init();
     $setup = new \ReflectionMethod($this, 'setup');
     $setup->setAccessible(true);
     $args = $this->assignAutoArgs($args);
     if ($this instanceof ScriptField) {
         $this->enqueueScripts();
     }
     $setup->invokeArgs($this, $args);
     $setup->setAccessible(false);
 }
 public function testLifetime()
 {
     $cache = $this->_getCacheDriver();
     // Test save
     $cache->save('test_key', 'testing this out', 10);
     // Test contains to test that save() worked
     $this->assertTrue($cache->contains('test_key'));
     // Test fetch
     $this->assertEquals('testing this out', $cache->fetch('test_key'));
     // access private methods
     $getFilename = new \ReflectionMethod($cache, 'getFilename');
     $getNamespacedId = new \ReflectionMethod($cache, 'getNamespacedId');
     $getFilename->setAccessible(true);
     $getNamespacedId->setAccessible(true);
     $id = $getNamespacedId->invoke($cache, 'test_key');
     $filename = $getFilename->invoke($cache, $id);
     $data = '';
     $lifetime = 0;
     $resource = fopen($filename, "r");
     if (false !== ($line = fgets($resource))) {
         $lifetime = (int) $line;
     }
     while (false !== ($line = fgets($resource))) {
         $data .= $line;
     }
     $this->assertNotEquals(0, $lifetime, 'previous lifetime could not be loaded');
     // update lifetime
     $lifetime = $lifetime - 20;
     file_put_contents($filename, $lifetime . PHP_EOL . $data);
     // test expired data
     $this->assertFalse($cache->contains('test_key'));
     $this->assertFalse($cache->fetch('test_key'));
 }
 /**
  * @covers ::buildSelector
  */
 public function testBuildSelector()
 {
     $this->stringTranslation->expects($this->any())->method('translate')->willReturnArgument(0);
     $method = new \ReflectionMethod($this->sut, 'buildSelector');
     $method->setAccessible(TRUE);
     $plugin_id = $this->randomMachineName();
     $plugin_label = $this->randomMachineName();
     $plugin_definition = $this->getMock(PluginLabelDefinitionInterface::class);
     $plugin_definition->expects($this->atLeastOnce())->method('getLabel')->willReturn($plugin_label);
     $plugin = $this->getMock(PluginInspectionInterface::class);
     $plugin->expects($this->atLeastOnce())->method('getPluginDefinition')->willReturn($plugin_definition);
     $plugin->expects($this->atLeastOnce())->method('getPluginId')->willReturn($plugin_id);
     $this->selectablePluginType->expects($this->atLeastOnce())->method('ensureTypedPluginDefinition')->willReturnArgument(0);
     $this->sut->setSelectedPlugin($plugin);
     $selector_title = $this->randomMachineName();
     $this->sut->setLabel($selector_title);
     $selector_description = $this->randomMachineName();
     $this->sut->setDescription($selector_description);
     $element = array('#parents' => array('foo', 'bar'), '#title' => $selector_title);
     $form_state = $this->getMock(FormStateInterface::class);
     $available_plugins = array($plugin);
     $expected_build_plugin_id = array('#ajax' => array('callback' => array(Radios::class, 'ajaxRebuildForm'), 'effect' => 'fade', 'event' => 'change', 'progress' => 'none', 'trigger_as' => array('name' => 'foo[bar][select][container][change]')), '#attached' => ['library' => ['plugin/plugin_selector.plugin_radios']], '#default_value' => $plugin_id, '#empty_value' => 'select', '#options' => array($plugin_id => $plugin_label), '#required' => FALSE, '#title' => $selector_title, '#description' => $selector_description, '#type' => 'radios');
     $expected_build_change = array('#ajax' => array('callback' => array(AdvancedPluginSelectorBase::class, 'ajaxRebuildForm')), '#attributes' => array('class' => array('js-hide')), '#limit_validation_errors' => array(array('foo', 'bar', 'select', 'plugin_id')), '#name' => 'foo[bar][select][container][change]', '#submit' => [[AdvancedPluginSelectorBase::class, 'rebuildForm']], '#type' => 'submit', '#value' => 'Choose');
     $build = $method->invokeArgs($this->sut, array($element, $form_state, $available_plugins));
     $this->assertEquals($expected_build_plugin_id, $build['container']['plugin_id']);
     $this->assertEquals($expected_build_change, $build['container']['change']);
     $this->assertSame('container', $build['container']['#type']);
 }
function executePrivateMethod($object, $method, $arguments)
{
    $reflectedMethod = new \ReflectionMethod($object, $method);
    $reflectedMethod->setAccessible(true);
    $result = $reflectedMethod->invoke($object, ...$arguments);
    return $result;
}
 public function testGetPageFactory()
 {
     $element = $this->createElement();
     $method = new \ReflectionMethod(get_class($element), 'getPageFactory');
     $method->setAccessible(true);
     $this->assertSame($this->pageFactory, $method->invoke($element));
 }
Example #29
0
 /**
  * @dataProvider parseUrlExceptionProvider
  */
 public function testParseUrlException($url)
 {
     $this->setExpectedException('rex_socket_exception');
     $method = new ReflectionMethod('rex_socket', 'parseUrl');
     $method->setAccessible(true);
     $method->invoke(null, $url);
 }
 /**
  * @expectedException JMS\SerializerBundle\Exception\XmlErrorException
  * @expectedExceptionMessage [FATAL] Start tag expected, '<' not found
  */
 public function testInvalidXml()
 {
     $driver = $this->getDriver();
     $ref = new \ReflectionMethod($driver, 'loadMetadataFromFile');
     $ref->setAccessible(true);
     $ref->invoke($driver, new \ReflectionClass('stdClass'), __DIR__ . '/xml/invalid.xml');
 }