コード例 #1
0
    public function testSave()
    {
        $filename = sprintf('%s/%s', sys_get_temp_dir(), uniqid());
        if (file_exists($filename)) {
            unlink($filename);
        }
        $config = new UserConfiguration();
        $config->addTrustedSignatures(array('foo', 'bar'));
        $config->addTrustedUsers(array('baz', 'qux'));
        $repositpory = new UserConfigurationRepository($filename);
        $repositpory->save($config);
        $expected = 'trust:
  signatures:
    - foo
    - bar
  users:
    - baz
    - qux
';
        $this->assertTrue(file_exists($filename));
        $this->assertEquals($expected, file_get_contents($filename));
        unlink($filename);
    }
コード例 #2
0
ファイル: RunCommand.php プロジェクト: TomzxForks/melody
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $melody = new Melody();
     $configRepository = new UserConfigurationRepository();
     $userConfig = $configRepository->load();
     $processHelper = $this->getHelperSet()->get('process');
     $cliExecutor = function (Process $process, $verbose) use($output, $processHelper) {
         if ($verbose) {
             // print debugging output for the build process
             $processHelper->mustRun($output, $process);
         } else {
             $callback = function ($type, $text) use($output) {
                 if ($type == 'out' && $output instanceof ConsoleOutputInterface) {
                     $output = $output->getErrorOutput();
                 }
                 $output->write($text);
             };
             return $process->run($callback);
         }
     };
     $runConfiguration = new RunConfiguration($input->getOption('no-cache'), $input->getOption('prefer-source'), $input->getOption('trust'));
     $script = $input->getArgument('script');
     $arguments = $input->getArgument('arguments');
     while (true) {
         try {
             $melody->run($script, $arguments, $runConfiguration, $userConfig, $cliExecutor);
             return 0;
         } catch (TrustException $e) {
             if (false === $this->confirmTrust($e->getResource(), $input, $output)) {
                 $output->writeln('<error>Operation aborted by the user.</error>');
                 return 1;
             }
             $userConfig->addTrustedSignature($e->getResource()->getSignature());
             $configRepository->save($userConfig);
         }
     }
 }