/** * Set up test dependencies * * This sets up a stubbed shell command service to record command executions * and return predefined command responses. */ protected function setUp() { $this->commands = array('executed' => array()); $commands =& $this->commands; $this->responses = array(); $responses =& $this->responses; /** @var \TYPO3\Surf\Domain\Service\ShellCommandService|\PHPUnit_Framework_MockObject_MockObject $shellCommandService */ $shellCommandService = $this->getMock('TYPO3\\Surf\\Domain\\Service\\ShellCommandService'); $shellCommandService->expects($this->any())->method('execute')->will($this->returnCallback(function ($command) use(&$commands, &$responses) { if (is_array($command)) { $commands['executed'] = array_merge($commands['executed'], $command); } else { $commands['executed'][] = $command; if (isset($responses[$command])) { return $responses[$command]; } } return ''; })); $shellCommandService->expects($this->any())->method('executeOrSimulate')->will($this->returnCallback(function ($command) use(&$commands, $responses) { if (is_array($command)) { $commands['executed'] = array_merge($commands['executed'], $command); } else { $commands['executed'][] = $command; if (isset($responses[$command])) { return $responses[$command]; } } return ''; })); $this->task = $this->createTask(); if ($this->task instanceof ShellCommandServiceAwareInterface) { $this->task->setShellCommandService($shellCommandService); } $this->node = new \TYPO3\Surf\Domain\Model\Node('TestNode'); $this->node->setHostname('hostname'); $this->deployment = new \TYPO3\Surf\Domain\Model\Deployment('TestDeployment'); /** @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject $mockLogger */ $mockLogger = $this->getMock('Psr\\Log\\LoggerInterface'); $this->deployment->setLogger($mockLogger); $this->deployment->setWorkspacesBasePath('./Data/Surf'); $this->application = new \TYPO3\Surf\Domain\Model\Application('TestApplication'); $this->deployment->initialize(); }
/** * Get a deployment object by deployment name * * Looks up the deployment in directory ./.surf/[deploymentName].php * * The script has access to a deployment object as "$deployment". This could change * in the future. * * @param string $deploymentName * @param string $path * @return Deployment * @throws \RuntimeException * @throws InvalidConfigurationException */ protected function createDeployment($deploymentName, $path = null) { $deploymentConfigurationPath = $this->getDeploymentsBasePath($path); $workspacesBasePath = $this->getWorkspacesBasePath(); if (empty($deploymentName)) { $deploymentNames = $this->getDeploymentNames($path); if (count($deploymentNames) !== 1) { throw new InvalidConfigurationException('No deployment name given!', 1451865016); } $deploymentName = array_pop($deploymentNames); } $deploymentPathAndFilename = Files::concatenatePaths(array($deploymentConfigurationPath, $deploymentName . '.php')); if (file_exists($deploymentPathAndFilename)) { $deployment = new Deployment($deploymentName); $deployment->setDeploymentBasePath($deploymentConfigurationPath); $deployment->setWorkspacesBasePath($workspacesBasePath); $tempPath = Files::concatenatePaths(array($workspacesBasePath, $deploymentName)); $this->ensureDirectoryExists($tempPath); $deployment->setTemporaryPath($tempPath); require $deploymentPathAndFilename; } else { $this->createLogger()->error(sprintf("The deployment file %s does not exist.\n", $deploymentPathAndFilename)); $deployment = new FailedDeployment(); } return $deployment; }
/** * Get a deployment object by deployment name * * Looks up the deployment in directory ./.surf/[deploymentName].php * * The script has access to a deployment object as "$deployment". This could change * in the future. * * @param string $deploymentName * @param string $path * @return \TYPO3\Surf\Domain\Model\Deployment * @throws InvalidConfigurationException */ protected function createDeployment($deploymentName, $path = null) { $deploymentConfigurationPath = $this->getDeploymentsBasePath($path); $workspacesBasePath = $this->getWorkspacesBasePath(); if (empty($deploymentName)) { $deploymentNames = $this->getDeploymentNames($path); if (count($deploymentNames) !== 1) { throw new InvalidConfigurationException('No deployment name given!', 1451865016); } $deploymentName = array_pop($deploymentNames); } $deploymentPathAndFilename = $deploymentConfigurationPath . '/' . $deploymentName . '.php'; if (!file_exists($deploymentPathAndFilename)) { exit(sprintf("The deployment file %s does not exist.\n", $deploymentPathAndFilename)); } $deployment = new Deployment($deploymentName); $deployment->setDeploymentBasePath($deploymentConfigurationPath); $deployment->setWorkspacesBasePath($workspacesBasePath); require $deploymentPathAndFilename; return $deployment; }