Пример #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $basedir = new Path(getcwd());
     // Find extension metadata
     $info = new Info($basedir->string('info.xml'));
     $info->load($ctx);
     if ($info->getType() != 'module') {
         $output->writeln('<error>Wrong extension type: ' . $attrs['type'] . '</error>');
         return;
     }
     // Find the main phpunit
     $civicrm_api3 = $this->getContainer()->get('civicrm_api3');
     if (!$civicrm_api3 || !$civicrm_api3->local) {
         $output->writeln("<error>'test' requires access to local CiviCRM source tree. Configure civicrm_api3_conf_path.</error>");
         return;
     }
     global $civicrm_root;
     if (empty($civicrm_root) || !is_dir($civicrm_root)) {
         $output->writeln("<error>Failed to locate CiviCRM root path: {$civicrm_root}</error>");
         return;
     }
     $phpunit_bin = "{$civicrm_root}/tools/scripts/phpunit";
     if (!file_exists($phpunit_bin)) {
         $output->writeln("<error>Failed to locate PHPUnit:\n  {$phpunit_bin}</error>");
         $output->writeln("<error>Have you configured CiviCRM for testing? See also:\n  http://wiki.civicrm.org/confluence/display/CRM/Setting+up+your+personal+testing+sandbox+HOWTO</error>");
         return;
     }
     $test_settings_path = "{$civicrm_root}/tests/phpunit/CiviTest/civicrm.settings.php";
     $test_settings_dist_path = "{$civicrm_root}/tests/phpunit/CiviTest/civicrm.settings.dist.php";
     if (!file_exists($test_settings_path) && !file_exists($test_settings_dist_path)) {
         $output->writeln("<error>Failed to locate test settings:\n  {$test_settings_path}</error>");
         $output->writeln("<error>Have you configured CiviCRM for testing? See also:\n  http://wiki.civicrm.org/confluence/display/CRM/Setting+up+your+personal+testing+sandbox+HOWTO</error>");
         return;
     }
     if (file_exists($test_settings_path) && self::checkLegacyExtensionSettings($test_settings_path)) {
         $output->writeln("<comment>Warning: Possible conflicts in {$test_settings_path}</comment>");
         $output->writeln("<comment>The following options may conflict with civix-based testing: 'ext_repo_url', 'extensionsDir', and/or 'extensionsURL'.</comment>");
     }
     $phpunit_boot = $this->getBootstrapFile($info->getKey(), $input->getOption('clear'));
     if (empty($phpunit_boot) || !file_exists($phpunit_boot)) {
         $output->writeln("<error>Failed to create PHPUnit bootstrap file</error>");
         return;
     }
     $tests_dir = implode(DIRECTORY_SEPARATOR, array(getcwd(), 'tests', 'phpunit'));
     // Prepare the command
     $command = array();
     $command[] = $phpunit_bin;
     $command[] = '--include-path';
     $command[] = $tests_dir;
     $command[] = '--bootstrap';
     $command[] = $phpunit_boot;
     $command[] = '--colors';
     if ($input->getOption('filter')) {
         $command[] = '--filter';
         $command[] = $input->getOption('filter');
     }
     if ($input->getOption('configuration')) {
         $command[] = '--configuration';
         $command[] = $basedir->string('phpunit.xml');
     }
     if ($input->getOption('debug')) {
         $command[] = '--debug';
     }
     $command[] = $input->getArgument('<TestClass>');
     // Run phpunit with our "tests" directory
     chdir("{$civicrm_root}/tools");
     $process = new Process(call_user_func_array(array('\\CRM\\CivixBundle\\Command\\TestRunCommand', 'createPhpShellCommand'), $command), NULL, NULL, NULL, self::TIMEOUT);
     $process->run(function ($type, $buffer) use($output) {
         $output->write($buffer);
     });
     $output->write("\n");
 }