public function testAddFileReadError() { vfsStreamWrapper::setRoot($root = vfsStream::newDirectory('test')); $root->addChild(vfsStream::newFile('test.php', 00)); $this->setExpectedException('CmPayments\\Crate\\Exception\\FileException', 'failed to open stream'); $this->crate->addFile('vfs://test/test.php'); }
/** * @override */ protected function execute(InputInterface $input, OutputInterface $output) { if (false === $input->getOption('stub') && null === $input->getArgument('local')) { $output->writeln('<error>The <info>local</info> argument is required.</error>'); return 1; } $this->config = $this->getConfig($input); $phar = $input->getArgument('phar'); $file = $input->getArgument('file'); // load bootstrap file if (null !== ($bootstrap = $this->config->getBootstrapFile())) { $this->config->loadBootstrap(); $this->putln('?', "Loading bootstrap file: {$bootstrap}"); unset($bootstrap); } $this->putln('*', 'Adding to the Phar...'); if (false === is_file($phar)) { $output->writeln(sprintf('<error>The path "%s" is not a file or does not exist.</error>', $phar)); return 1; } if (false === is_file($file)) { $output->writeln(sprintf('<error>The path "%s" is not a file or does not exist.</error>', $file)); return 1; } if (false == preg_match('/^\\w+:\\/\\//', $file)) { $file = realpath($file); } $this->crate = Crate::create($phar); // set replacement values, if any if (array() !== ($values = $this->config->getProcessedReplacements())) { $this->putln('?', 'Setting replacement values...'); if ($this->isVerbose()) { foreach ($values as $key => $value) { $this->putln('+', "{$key}: {$value}"); } } $this->crate->setValues($values); unset($values, $key, $value); } // register configured compactors if (array() !== ($compactors = $this->config->getCompactors())) { $this->putln('?', 'Registering compactors...'); foreach ($compactors as $compactor) { $this->putln('+', get_class($compactor)); $this->crate->addCompactor($compactor); } } // add the file $phar = $this->crate->getPhar(); $local = str_replace('\\', '/', Path::canonical($input->getArgument('local'))); if (isset($phar[$local]) && false === $input->getOption('replace')) { $output->writeln(sprintf('<error>The file "%s" already exists in the Phar.</error>', $local)); return 1; } if ($input->getOption('binary')) { $this->putln('?', "Adding binary file: {$file}"); $phar->addFile($file, $local); } elseif ($input->getOption('stub')) { $this->putln('?', "Using stub file: {$file}"); $this->crate->setStubUsingFile($file); } elseif ($input->getOption('main')) { $this->putln('?', "Adding main file: {$file}"); if (false === ($contents = @file_get_contents($file))) { $error = error_get_last(); throw new RuntimeException($error['message']); } $this->crate->addFromString($local, preg_replace('/^#!.*\\s*/', '', $contents)); } else { $this->putln('?', "Adding file: {$file}"); $this->crate->addFile($file, $local); } unset($this->crate, $phar); $this->putln('*', 'Done.'); return 0; }