Neos\ContentRepository\Domain\Service\ContextFactory::create PHP Method

create() public method

The context properties to give depend on the implementation of the context object, for the Neos\ContentRepository\Domain\Service\Context it should look like this: array( 'workspaceName' => 'live', 'currentDateTime' => new \Neos\Flow\Utility\Now(), 'dimensions' => array(...), 'targetDimensions' => array('language' => 'de', 'persona' => 'Lisa'), 'invisibleContentShown' => FALSE, 'removedContentShown' => FALSE, 'inaccessibleContentShown' => FALSE ) This array also shows the defaults that get used if you don't provide a certain property.
public create ( array $contextProperties = [] ) : Context
$contextProperties array
return Context
    public function create(array $contextProperties = array())
    {
        $contextProperties = $this->mergeContextPropertiesWithDefaults($contextProperties);
        $contextIdentifier = $this->getIdentifier($contextProperties);
        if (!isset($this->contextInstances[$contextIdentifier])) {
            $this->validateContextProperties($contextProperties);
            $context = $this->buildContextInstance($contextProperties);
            $this->contextInstances[$contextIdentifier] = $context;
        }
        return $this->contextInstances[$contextIdentifier];
    }

Usage Example

 /**
  * @test
  */
 public function setDateTimeAllowsForMockingTheCurrentTime()
 {
     $simulatedCurrentTime = new \DateTime();
     $simulatedCurrentTime->add(new \DateInterval('P1D'));
     $context = $this->contextFactory->create(array('currentDateTime' => $simulatedCurrentTime));
     $this->assertEquals($simulatedCurrentTime, $context->getCurrentDateTime());
 }
All Usage Examples Of Neos\ContentRepository\Domain\Service\ContextFactory::create