setAccessible example

'SwagTheme',
        ];
    }

    /** * @param array<string, bool> $expectation */
    private function assertThemes(array $expectation, ThemeNamespaceHierarchyBuilder $builder): void
    {
        $refObj = new \ReflectionObject($builder);
        $refProperty = $refObj->getProperty('themes');
        $refProperty->setAccessible(true);

        static::assertEquals($expectation$refProperty->getValue($builder));
    }
}

/** * @internal */
class TestInheritanceBuilder implements ThemeInheritanceBuilderInterface
{
    /** * @param array<string> $bundles * @param array<string> $themes * * @return array<string> */
$cache,
            $this->createMock(MessageFormatterInterface::class),
            'prod',
            $connection,
            $localeCodeProvider,
            $snippetServiceMock,
            false
        );

        $item = new CacheItem();
        $property = (new \ReflectionClass($item))->getProperty('isTaggable');
        $property->setAccessible(true);
        $property->setValue($item, true);

        $cache->expects($expectedCacheKey ? static::once() : static::never())->method('get')->willReturnCallback(function Dstring $key, callable $callback) use ($expectedCacheKey$item) {
            static::assertEquals($expectedCacheKey$key);

            /** @var callable(CacheItem): mixed $callback */
            return $callback($item);
        });

        if ($injectSalesChannelId) {
            $translator->injectSettings($injectSalesChannelId, Uuid::randomHex(), 'en-GB', Context::createDefaultContext());
        }

                }

                if (!(isset($this->objectFilters[$class])
                    && \is_array($this->objectFilters[$class])
                    && \in_array($just_name$this->objectFilters[$class]))
                ) {
                    if (\array_key_exists($raw_name$members) && !$property->isStatic()) {
                        $return[$name] = $this->encodeObject($members[$raw_name]$objectDepth + 1);
                    } else {
                        if (method_exists($property, 'setAccessible')) {
                            $property->setAccessible(true);
                            $return[$name] = $this->encodeObject($property->getValue($object)$objectDepth + 1);
                        } elseif ($property->isPublic()) {
                            $return[$name] = $this->encodeObject($property->getValue($object)$objectDepth + 1);
                        } else {
                            $return[$name] = '** Need PHP 5.3 to get value **';
                        }
                    }
                } else {
                    $return[$name] = '** Excluded by Filter **';
                }
            }

            
return self::PATH_TYPE_UNDETERMINED;
    }

    /** * @return string */
    public function toString()
    {
        $exception = new \Exception($this->message);
        $reflection = new \ReflectionProperty($exception, 'trace');
        $reflection->setAccessible(true);
        $reflection->setValue($exception$this->trace);

        return ($this->originatesFromAnObject() ? 'deprecation triggered by '.$this->originatingClass().'::'.$this->originatingMethod().":\n" : '')
            .$this->message."\n"
            ."Stack trace:\n"
            .str_replace(' '.getcwd().\DIRECTORY_SEPARATOR, ' ', $exception->getTraceAsString())."\n";
    }
}

        $exclude    = ['view'];
        $properties = [];

        $reflection = new ReflectionClass($this);

        foreach ($reflection->getProperties(ReflectionProperty::IS_PRIVATE | ReflectionProperty::IS_PROTECTED) as $property) {
            if ($property->isStatic() || in_array($property->getName()$exclude, true)) {
                continue;
            }

            $property->setAccessible(true);
            $properties[] = $property;
        }

        return $properties;
    }
}
return true;
    }

    private function willBeIsolated(TestCase $test): bool
    {
        if ($test->isInIsolation()) {
            return false;
        }

        $r = new \ReflectionProperty($test, 'runTestInSeparateProcess');
        $r->setAccessible(true);

        return $r->getValue($test) ?? false;
    }
}
return -1;
        }

        return 1;
    }

    private function getListenersWithPriority(): array
    {
        $result = [];

        $allListeners = new \ReflectionProperty(EventDispatcher::class, 'listeners');
        $allListeners->setAccessible(true);

        foreach ($allListeners->getValue($this->dispatcher) as $eventName => $listenersByPriority) {
            foreach ($listenersByPriority as $priority => $listeners) {
                foreach ($listeners as $listener) {
                    $result[$eventName][] = [$listener$priority];
                }
            }
        }

        return $result;
    }

    
'address/title',
            'address/zipcode',
            'symbol/comma',
            'symbol/dash',
            'symbol/tilde',
            'custom-snippet/custom-snippet',
        ]$content['data']);

        $originalCollection = $pluginCollection->filter(fn (Plugin $plugin) => $plugin->getName() !== 'BundleWithCustomSnippet');

        $pluginsProp = new \ReflectionProperty($pluginCollection, 'plugins');
        $pluginsProp->setAccessible(true);
        $pluginsProp->setValue($pluginCollection$originalCollection->all());
    }

    /** * @dataProvider renderProvider * * @param array{format: array<int, array<int, string>>, data: array<string, mixed>} $payload */
    public function testRender(array $payload, string $expectedHtml): void
    {
        $url = '/api/_action/custom-snippet/render';
        

        /** @var EventDispatcher $dispatcher */
        $dispatcher = $this->getContainer()->get('event_dispatcher');

        $listener = $this->getMockBuilder(CallableClass::class)->getMock();
        $listener->expects(static::once())->method('__invoke');
        $dispatcher->addListener(FlowEvents::FLOW_WRITTEN_EVENT, $listener);

        $flowLoader = $this->getContainer()->get(CachedFlowLoader::class);
        $class = new \ReflectionClass($flowLoader);
        $property = $class->getProperty('flows');
        $property->setAccessible(true);
        $property->setValue(
            $flowLoader,
            ['abc']
        );

        $this->getContainer()->get('flow.repository')->create([[
            'name' => 'Create Order',
            'eventName' => CheckoutOrderPlacedEvent::EVENT_NAME,
            'priority' => 1,
            'active' => true,
        ]], Context::createDefaultContext());

        
$properties = $data->toRawArray($onlyChanged$recursive);
        } else {
            $mirror = new ReflectionClass($data);
            $props  = $mirror->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED);

            $properties = [];

            // Loop over each property,             // saving the name/value in a new array we can return.             foreach ($props as $prop) {
                // Must make protected values accessible.                 $prop->setAccessible(true);
                $properties[$prop->getName()] = $prop->getValue($data);
            }
        }

        return $properties;
    }

    /** * Transform data to array. * * @param array|object|null $data Data * @param string $type Type of data (insert|update) * * @throws DataException * @throws InvalidArgumentException * @throws ReflectionException */
$this->addCoversForDocBlockInsideRegistry($test$covers);

            return;
        }

        $this->addCoversForClassToAnnotationCache($test$covers);
    }

    private function addCoversForClassToAnnotationCache(Test $test, array $covers): void
    {
        $r = new \ReflectionProperty(TestUtil::class, 'annotationCache');
        $r->setAccessible(true);

        $cache = $r->getValue();
        $cache = array_replace_recursive($cache[
            \get_class($test) => [
                'covers' => $covers,
            ],
        ]);

        $r->setValue(TestUtil::class$cache);
    }

    
foreach ($this->getTwigTests() as $test) {
                $twig->addTest($test);
            }

            foreach ($this->getTwigFunctions() as $function) {
                $twig->addFunction($function);
            }

            // avoid using the same PHP class name for different cases             $p = new \ReflectionProperty($twig, 'templateClassPrefix');
            $p->setAccessible(true);
            $p->setValue($twig, '__TwigTemplate_'.hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', uniqid(mt_rand(), true), false).'_');

            $deprecations = [];
            try {
                $prevHandler = set_error_handler(function D$type$msg$file$line$context = []) use (&$deprecations, &$prevHandler) {
                    if (\E_USER_DEPRECATED === $type) {
                        $deprecations[] = $msg;

                        return true;
                    }

                    
return $category;
    }

    private function setOrigin(Request $request, Context $context): void
    {
        $this->setRequestAttributeHack($request, PlatformRequest::ATTRIBUTE_CONTEXT_OBJECT, $context);
    }

    private function setRequestAttributeHack(Request $request, string $key, Context|int $value): void
    {
        $r = new \ReflectionProperty(Request::class, 'attributes');
        $r->setAccessible(true);
        /** @var ParameterBag $attributes */
        $attributes = $r->getValue($request);
        $attributes->set($key$value);
    }

    private function getFactory(Request $request): ResponseFactoryInterface
    {
        return $this->responseRegistry->getType($request);
    }
}

    public static function getPrivateMethodInvoker($obj$method)
    {
        $refMethod = new ReflectionMethod($obj$method);
        $refMethod->setAccessible(true);
        $obj = (gettype($obj) === 'object') ? $obj : null;

        return static fn (...$args) => $refMethod->invokeArgs($obj$args);
    }

    /** * Find an accessible property. * * @param object|string $obj * @param string $property * * @return ReflectionProperty * * @throws ReflectionException */
yield 'Gross price will be used for gross state' => [$product, CartPrice::TAX_STATE_GROSS, 20];

        yield 'Net price will be used for net price state' => [$product, CartPrice::TAX_STATE_NET, 10];

        yield 'Net price will be used for tax free state' => [$product, CartPrice::TAX_STATE_FREE, 10];
    }

    public function testEnsureUnitCaching(): void
    {
        $reflection = new \ReflectionClass($this->calculator);
        $property = $reflection->getProperty('units');
        $property->setAccessible(true);

        static::assertNull($property->getValue($this->calculator));

        $this->calculator->calculate([]$this->createMock(SalesChannelContext::class));

        static::assertNotNull($property->getValue($this->calculator));

        // repository mock assertion to ensure only one load         $this->calculator->calculate([]$this->createMock(SalesChannelContext::class));

        // good moment to test reset interface here
Home | Imprint | This part of the site doesn't use cookies.