public function testRecursive() { $config = Config::fromFile(__DIR__ . '/config/config-clean-files-recur.json'); $tasks = $config->getTasks(); $tmpDir = dirname($this->tmpFile); $processor = $this->getMock(Processor::class); $processor->expects($this->once())->method('setCurrentWorkingDirectory')->with($this->equalTo(dirname(__DIR__))); $processor->expects($this->once())->method('execute')->with($this->equalTo("rm -Rf {$tmpDir}/recur/recur.srvclean")); if (!file_exists($tmpDir . '/recur')) { mkdir($tmpDir . '/recur'); } touch($tmpDir . '/recur/recur.srvclean'); $tasks->each(function (TaskInterface $task, $name) use($processor) { $this->assertEquals('removeTmp', $name); $this->assertInstanceOf(ProcessAwareInterface::class, $task); $task->setCurrentWorkingDirectory(dirname(__DIR__)); if ($task instanceof ProcessAwareInterface) { $task->setProcessor($processor); } if ($task instanceof LoggerAwareInterface) { $task->setLogger($this->logger); } $task->execute(); }); unlink($tmpDir . '/recur/recur.srvclean'); rmdir($tmpDir . '/recur'); }
/** * @param InputInterface $input * @param OutputInterface $output * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $cwd = getcwd(); $configFile = $input->getOption('config'); if ($configFile === null) { $configFile = $cwd . '/srvcleaner.json'; } $logger = new ConsoleLogger($output, [LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL, LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL, LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL, LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL, LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL, LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL, LogLevel::INFO => OutputInterface::VERBOSITY_NORMAL, LogLevel::DEBUG => OutputInterface::VERBOSITY_VERBOSE]); $config = Config::fromFile($configFile); $tasks = $config->getTasks(); $tasks->each(function (TaskInterface $task) use($cwd, $input, $logger) { if ($task instanceof ProcessAwareInterface) { $task->setProcessor(new Processor()); } if ($task instanceof LoggerAwareInterface) { $task->setLogger($logger); } $task->setCurrentWorkingDirectory($cwd); $task->execute($input->getOption('dry-run')); }); }
public function testTaskNameAndSrcCannotBeEmpty() { $this->setExpectedException(ConfigurationException::class); $config = Config::fromFile(__DIR__ . '/config/config-task-empty.json'); $config->getTasks(); }
public function testNoLogger() { $this->setExpectedException(RuntimeException::class); $config = Config::fromFile(__DIR__ . '/config/config-clean-directories.json'); $tasks = $config->getTasks(); $processor = $this->getMock(Processor::class); $tasks->each(function (TaskInterface $task) use($processor) { $task->setCurrentWorkingDirectory(dirname(__DIR__)); if ($task instanceof ProcessAwareInterface) { $task->setProcessor($processor); } $task->execute(); }); }