示例#1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $host = $input->getOption('host');
     $user = $input->getOption('user');
     $pass = $input->getOption('pass');
     $dbName = $input->getArgument('name');
     try {
         $this->dump = $this->pdoFactory->makeDump($host, $user, $pass, $dbName);
     } catch (\PDOException $e) {
         throw new RuntimeException('Error while connecting to database [' . $dbName . ']: ' . $e->getMessage());
     }
     if (false === $this->dump) {
         $output->writeln('<error>Something went wrong with the dump component instance.</error>');
         return false;
     }
     \Codeception\Configuration::config();
     if (!empty($input->getOption('dump-file'))) {
         $dumpFile = $input->getOption('dump-file');
     } else {
         $dumpFile = codecept_data_dir($input->getArgument('snapshot') . '.sql');
     }
     $output->writeln('<info>Dump file will be written to [' . $dumpFile . ']</info>');
     if (!empty($input->getOption('dist-dump-file'))) {
         $distDumpFile = $input->getOption('dist-dump-file');
     } else {
         $distDumpFile = codecept_data_dir($input->getArgument('snapshot') . '.dist.sql');
     }
     $output->writeln('<info>Distribution version of dump file will be written to [' . $distDumpFile . ']</info>');
     $skipTables = $input->getOption('skip-tables');
     if (!empty($skipTables)) {
         $tables = explode(',', $skipTables);
         foreach ($tables as $table) {
             $this->dump->tables[$table] = \MySQLDump::NONE;
         }
     }
     $memory = fopen('php://memory', 'w');
     $this->dump->write($memory);
     rewind($memory);
     $dumpContents = stream_get_contents($memory);
     if (!$this->filesystem->file_put_contents($dumpFile, $dumpContents)) {
         $output->writeln('<error>Could not write dump to [' . $dumpFile . ']</error>');
         return false;
     }
     $output->writeln('<info>Dump file written to [' . $dumpFile . ']</info>');
     $localUrl = $input->getOption('local-url');
     $distUrl = $input->getOption('dist-url');
     $localDomain = rtrim(preg_replace('~http(s)*:\\/\\/(www\\.)*~', '', $localUrl), '/');
     $distDomain = rtrim(preg_replace('~http(s)*:\\/\\/(www\\.)*~', '', $distUrl), '/');
     $distDumpContents = str_replace($localDomain, $distDomain, $dumpContents);
     if (!$this->filesystem->file_put_contents($distDumpFile, $distDumpContents)) {
         $output->writeln('<error>Could not write dist dump to [' . $distDumpFile . ']</error>');
         return false;
     }
     $output->writeln('<info>Distribution version of dump file written to [' . $distDumpFile . ']</info>');
     $output->writeln('<comment>Any occurrence of [' . $localDomain . '] in it was replaced with [' . $distDomain . ']</comment>');
     parent::execute($input, $output);
     return true;
 }
示例#2
0
 protected function _before()
 {
     $this->filename = __DIR__ . DIRECTORY_SEPARATOR . basename(codecept_root_dir());
     $this->filesystem = $this->prophesize('tad\\WPBrowser\\Filesystem\\Filesystem');
     $this->filesystem->is_dir(__DIR__)->willReturn(true);
     $this->filesystem->is_writeable(__DIR__)->willReturn(true);
     $this->event = $this->prophesize('\\Codeception\\Event\\SuiteEvent');
     $this->printEvent = $this->prophesize('\\Codeception\\Event\\PrintResultEvent');
 }
示例#3
0
 private function checkRootFolder($rootFolder)
 {
     if (!($this->filesystem->is_dir($rootFolder) && $this->filesystem->is_readable($rootFolder))) {
         throw new ExtensionException(__CLASS__, '[rootFolder] parameter [' . $rootFolder . '] is not an existing and readable directory.');
     }
 }
 /**
  * @param $localCodeceptionConfig
  */
 protected function ensureCodeceptionLocalConfigExists($localCodeceptionConfig)
 {
     if (!$this->filesystem->file_exists($localCodeceptionConfig)) {
         throw new RuntimeException('Bootstrap and configure your codeception locally before running the setup:scaffold command.');
     }
 }