/** * Get a value by path and wrap it into another context * * The whitelist for the given path is applied to the new context. * * @param string $path * @return Context The wrapped value */ public function getAndWrap($path = null) { // There are some cases where the $path is a ProtectedContext, especially when doing s.th. like // foo()[myOffset]. In this case we need to unwrap it. if ($path instanceof ProtectedContext) { $path = $path->unwrap(); } $context = parent::getAndWrap($path); if ($context instanceof ProtectedContext && isset($this->whitelist[$path]) && is_array($this->whitelist[$path])) { $context->whitelist = $this->whitelist[$path]; } return $context; }
/** * @test * @dataProvider objectGetValues * * @param mixed $value * @param string $path * @param mixed $expectedGetValue */ public function getValueByPathForObjectValues($value, $path, $expectedGetValue) { $context = new Context($value); $getValue = $context->get($path); $this->assertSame($getValue, $expectedGetValue); }