Ejemplo n.º 1
0
 /**
  * When running multiple environments, getClassesFromFile() method in SuiteManager is called once for each env.
  * See \Codeception\Codecept::runSuite() - for each env new SuiteManager is created and tests loaded.
  * Make sure that calling getClassesFromFile() multiple times will always return the same classes.
  *
  * @group core
  */
 public function testAddCestWithEnv()
 {
     $file = \Codeception\Configuration::dataDir() . 'SimpleNamespacedTest.php';
     $this->suiteman->loadTests($file);
     $this->assertEquals(3, $this->suiteman->getSuite()->count());
     $newSuiteMan = new \Codeception\SuiteManager($this->dispatcher, 'suite', \Codeception\Configuration::$defaultSuiteSettings);
     $newSuiteMan->loadTests($file);
     $this->assertEquals(3, $newSuiteMan->getSuite()->count());
 }
Ejemplo n.º 2
0
 public function testGroupEventsAreFired()
 {
     $events = [];
     $eventListener = function ($event, $eventName) use(&$events) {
         $events[] = $eventName;
     };
     $this->dispatcher->addListener('test.before', $eventListener);
     $this->dispatcher->addListener('test.before.admin', $eventListener);
     $this->dispatcher->addListener('test.after', $eventListener);
     $this->dispatcher->addListener('test.after.admin', $eventListener);
     $this->suiteman->loadTests(codecept_data_dir() . 'SimpleAdminGroupCest.php');
     $this->suiteman->run($this->runner, new \PHPUnit_Framework_TestResult(), ['silent' => true, 'colors' => false, 'steps' => true, 'debug' => false]);
     $this->assertContains('test.before', $events);
     $this->assertContains('test.before.admin', $events);
     $this->assertContains('test.after.admin', $events);
 }
Ejemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $output->writeln('Warning: this command may affect your Helper classes');
     $config = Configuration::config($input->getOption('config'));
     $suiteconf = Configuration::suiteSettings($suite, $config);
     $dispatcher = new EventDispatcher();
     $suiteManager = new SuiteManager($dispatcher, $suite, $suiteconf);
     if (isset($suiteconf['bootstrap'])) {
         if (file_exists($suiteconf['path'] . $suiteconf['bootstrap'])) {
             require_once $suiteconf['path'] . $suiteconf['bootstrap'];
         }
     }
     $suiteManager->loadTests();
     $tests = $suiteManager->getSuite()->tests();
     $dialog = $this->getHelperSet()->get('dialog');
     $helper = $this->matchHelper();
     if (!$helper) {
         $output->writeln("<error>No helpers for suite {$suite} is defined. Can't append new methods</error>");
         return;
     }
     if (!file_exists($helper_file = Configuration::helpersDir() . $helper . '.php')) {
         $output->writeln("<error>Helper class {$helper}.php doesn't exist</error>");
         return;
     }
     $replaced = 0;
     $analyzed = 0;
     foreach ($tests as $test) {
         if (!$test instanceof Cept) {
             continue;
         }
         $analyzed++;
         $test->testCodecept(false);
         $scenario = $test->getScenario();
         foreach ($scenario->getSteps() as $step) {
             if ($step->getName() == 'Comment') {
                 continue;
             }
             $action = $step->getAction();
             if (isset(SuiteManager::$actions[$action])) {
                 continue;
             }
             if (!$dialog->askConfirmation($output, "<question>\nAction '{$action}' is missing. Do you want to add it to helper class?\n</question>\n", false)) {
                 continue;
             }
             $example = sprintf('$I->%s(%s);', $action, $step->getArguments(true));
             $args = array_map(function ($a) {
                 return '$arg' . $a;
             }, range(1, count($step->getArguments())));
             $stub = sprintf($this->methodTemplate, $example, $action, implode(', ', $args));
             $contents = file_get_contents($helper_file);
             $contents = preg_replace('~}(?!.*})~ism', $stub, $contents);
             $this->save($helper_file, $contents, true);
             $output->writeln("Action '{$action}' added to helper {$helper}");
             $replaced++;
         }
     }
     $output->writeln("<info>Analysis finished. {$analyzed} tests analyzed. {$replaced} methods added</info>");
     $output->writeln("Run the 'build' command to finish");
 }
Ejemplo n.º 4
0
 public function runSuite($suite, $test = null)
 {
     $settings = Configuration::suiteSettings($suite, $this->config);
     $suiteManager = new SuiteManager($this->dispatcher, $suite, $settings);
     $test ? $suiteManager->loadTest($settings['path'] . $test) : $suiteManager->loadTests();
     if (!$this->runner->getPrinter()) {
         $printer = new PHPUnit\ResultPrinter\UI($this->dispatcher, $this->options);
         $this->runner->setPrinter($printer);
     }
     $suiteManager->run($this->runner, $this->result, $this->options);
     return $this->result;
 }
Ejemplo n.º 5
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->addStyles($output);
     $suite = $input->getArgument('suite');
     $test = $input->getArgument('test');
     $config = Configuration::config($input->getOption('config'));
     if (!Configuration::isEmpty() && !$test && strpos($suite, $config['paths']['tests']) === 0) {
         list(, $suite, $test) = $this->matchTestFromFilename($suite, $config['paths']['tests']);
     }
     $settings = $this->getSuiteConfig($suite, $input->getOption('config'));
     $dispatcher = new EventDispatcher();
     $dispatcher->addSubscriber(new ConsolePrinter(['colors' => !$input->getOption('no-ansi'), 'steps' => true, 'verbosity' => OutputInterface::VERBOSITY_VERBOSE]));
     $dispatcher->addSubscriber(new BootstrapLoader());
     $suiteManager = new SuiteManager($dispatcher, $suite, $settings);
     $moduleContainer = $suiteManager->getModuleContainer();
     foreach (Configuration::modules($settings) as $module) {
         $moduleContainer->mock($module, new Maybe());
     }
     $suiteManager->loadTests($test);
     $tests = $suiteManager->getSuite()->tests();
     $dispatcher->dispatch(Events::SUITE_INIT, new SuiteEvent($suiteManager->getSuite(), null, $settings));
     $dispatcher->dispatch(Events::SUITE_BEFORE, new SuiteEvent($suiteManager->getSuite(), null, $settings));
     foreach ($tests as $test) {
         if ($test instanceof \PHPUnit_Framework_TestSuite_DataProvider) {
             foreach ($test as $t) {
                 if ($t instanceof Test) {
                     $this->dryRunTest($output, $dispatcher, $t);
                 }
             }
         }
         if ($test instanceof Test and $test instanceof ScenarioDriven) {
             $this->dryRunTest($output, $dispatcher, $test);
         }
     }
     $dispatcher->dispatch(Events::SUITE_AFTER, new SuiteEvent($suiteManager->getSuite()));
 }
Ejemplo n.º 6
0
 public function runSuite($settings, $suite, $test = null)
 {
     $suiteManager = new SuiteManager($this->dispatcher, $suite, $settings);
     $suiteManager->initialize();
     $suiteManager->loadTests($test);
     $suiteManager->run($this->runner, $this->result, $this->options);
     return $this->result;
 }
Ejemplo n.º 7
0
    public function runSuite($settings, $suite, $test = null) {
        $suiteManager = new SuiteManager($this->dispatcher, $suite, $settings);

        $test
            ? $suiteManager->loadTest($settings['path'].$test)
            : $suiteManager->loadTests();

        $suiteManager->run($this->runner, $this->result, $this->options);

        return $this->result;
    }
Ejemplo n.º 8
0
 public function runSuite($suite, $test = null)
 {
     ini_set('memory_limit', isset($this->config['settings']['memory_limit']) ? $this->config['settings']['memory_limit'] : '1024M');
     $settings = Configuration::suiteSettings($suite, Configuration::config());
     $suiteManager = new SuiteManager($this->dispatcher, $suite, $settings);
     $test ? $suiteManager->loadTest($settings['path'] . $test) : $suiteManager->loadTests();
     $suiteManager->run($this->runner, $this->result, $this->options);
     return $this->result;
 }