Neos\ContentRepository\Tests\Behavior\Features\Bootstrap\NodeOperationsTrait::createWorkspaceIfNeeded PHP Method

createWorkspaceIfNeeded() protected method

Make sure that the "live" workspace and the requested $workspaceName workspace exist.
protected createWorkspaceIfNeeded ( string $workspaceName = null ) : void
$workspaceName string
return void
    protected function createWorkspaceIfNeeded($workspaceName = null)
    {
        /** @var WorkspaceRepository $workspaceRepository */
        $workspaceRepository = $this->getObjectManager()->get(WorkspaceRepository::class);
        $liveWorkspace = $workspaceRepository->findOneByName('live');
        if ($liveWorkspace === null) {
            $liveWorkspace = new Workspace('live');
            $workspaceRepository->add($liveWorkspace);
            $this->getPersistenceManager()->persistAll();
            $this->resetNodeInstances();
        }
        if ($workspaceName !== null) {
            $requestedWorkspace = $workspaceRepository->findOneByName($workspaceName);
            if ($requestedWorkspace === null) {
                $requestedWorkspace = new Workspace($workspaceName, $liveWorkspace);
                $workspaceRepository->add($requestedWorkspace);
                $this->getPersistenceManager()->persistAll();
                $this->resetNodeInstances();
            }
        }
    }