Exemple #1
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suiteName = $input->getArgument('suite');
     $this->output = $output;
     $config = \Codeception\Configuration::config($input->getOption('config'));
     $settings = \Codeception\Configuration::suiteSettings($suiteName, $config);
     $options = $input->getOptions();
     $options['debug'] = true;
     $options['steps'] = true;
     $this->codecept = new \Codeception\Codecept($options);
     $dispatcher = $this->codecept->getDispatcher();
     $suiteManager = new SuiteManager($dispatcher, $suiteName, $settings);
     $this->suite = $suiteManager->getSuite();
     $this->test = new Cept($dispatcher, array('name' => 'interactive', 'file' => 'interactive'));
     $guy = $settings['class_name'];
     $scenario = new Scenario($this->test);
     $I = new $guy($scenario);
     $this->listenToSignals();
     $output->writeln("<info>Interactive console started for suite {$suiteName}</info>");
     $output->writeln("<info>Try Codeception commands without writing a test</info>");
     $output->writeln("<info>type 'exit' to leave console</info>");
     $output->writeln("<info>type 'actions' to see all available actions for this suite</info>");
     $dispatcher->dispatch('suite.before', new Suite($this->suite, $this->codecept->getResult(), $settings));
     $dispatcher->dispatch('test.parsed', new \Codeception\Event\Test($this->test));
     $dispatcher->dispatch('test.before', new \Codeception\Event\Test($this->test));
     $output->writeln("\n\n\$I = new {$settings['class_name']}(\$scenario);");
     $scenario->run();
     $this->executeCommands($output, $I, $settings['bootstrap']);
     $dispatcher->dispatch('test.after', new \Codeception\Event\Test($this->test));
     $dispatcher->dispatch('suite.after', new Suite($this->suite));
     $output->writeln("<info>Bye-bye!</info>");
 }
Exemple #2
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");
 }
Exemple #3
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suiteName = $input->getArgument('suite');
     $this->output = $output;
     $config = Configuration::config($input->getOption('config'));
     $settings = Configuration::suiteSettings($suiteName, $config);
     $options = $input->getOptions();
     $options['debug'] = true;
     $options['steps'] = true;
     $this->codecept = new Codecept($options);
     $dispatcher = $this->codecept->getDispatcher();
     $this->test = (new Cept())->configDispatcher($dispatcher)->configName('interactive')->config('file', 'interactive')->initConfig();
     $suiteManager = new SuiteManager($dispatcher, $suiteName, $settings);
     $suiteManager->initialize();
     $this->suite = $suiteManager->getSuite();
     $scenario = new Scenario($this->test);
     $actor = $settings['class_name'];
     $I = new $actor($scenario);
     $this->listenToSignals();
     $output->writeln("<info>Interactive console started for suite {$suiteName}</info>");
     $output->writeln("<info>Try Codeception commands without writing a test</info>");
     $output->writeln("<info>type 'exit' to leave console</info>");
     $output->writeln("<info>type 'actions' to see all available actions for this suite</info>");
     $suiteEvent = new SuiteEvent($this->suite, $this->codecept->getResult(), $settings);
     $dispatcher->dispatch(Events::SUITE_BEFORE, $suiteEvent);
     $dispatcher->dispatch(Events::TEST_PARSED, new TestEvent($this->test));
     $dispatcher->dispatch(Events::TEST_BEFORE, new TestEvent($this->test));
     $output->writeln("\n\n\$I = new {$settings['class_name']}(\$scenario);");
     $scenario->run();
     $this->executeCommands($output, $I, $settings['bootstrap']);
     $dispatcher->dispatch(Events::TEST_AFTER, new TestEvent($this->test));
     $dispatcher->dispatch(Events::SUITE_AFTER, new SuiteEvent($this->suite));
     $output->writeln("<info>Bye-bye!</info>");
 }
 /**
  * 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() . 'SimpleCestWithNamespace.php';
     $this->suiteman->addCest($file);
     $this->assertEquals(3, $this->suiteman->getSuite()->count());
     $newSuiteMan = Stub::make('\\Codeception\\SuiteManager', array('dispatcher' => $this->dispatcher, 'suite' => new PHPUnit_Framework_TestSuite(), 'settings' => array('bootstrap' => false, 'class_name' => 'CodeGuy', 'namespace' => '')));
     $newSuiteMan->addCest($file);
     $this->assertEquals(3, $newSuiteMan->getSuite()->count());
 }
 /**
  * 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());
 }
Exemple #6
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;
 }
 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);
 }
Exemple #8
0
 /**
  * @param $module
  *
  * @return \Codeception\Module
  * @throws \Codeception\Exception\TestRuntime
  */
 public function getModule($module)
 {
     if (SuiteManager::hasModule($module)) {
         return SuiteManager::$modules[$module];
     }
     throw new TestRuntime("Module {$module} is not enabled for this test suite");
 }
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suiteName = $input->getArgument('suite');
     $this->output = $output;
     $config = Configuration::config($input->getOption('config'));
     $settings = Configuration::suiteSettings($suiteName, $config);
     $options = $input->getOptions();
     $options['debug'] = true;
     $options['silent'] = true;
     $options['interactive'] = false;
     $options['colors'] = true;
     Debug::setOutput(new Output($options));
     $this->codecept = new Codecept($options);
     $dispatcher = $this->codecept->getDispatcher();
     $suiteManager = new SuiteManager($dispatcher, $suiteName, $settings);
     $suiteManager->initialize();
     $this->suite = $suiteManager->getSuite();
     $moduleContainer = $suiteManager->getModuleContainer();
     $this->actions = array_keys($moduleContainer->getActions());
     $this->test = new Cept(null, null);
     $this->test->getMetadata()->setServices(['dispatcher' => $dispatcher, 'modules' => $moduleContainer]);
     $scenario = new Scenario($this->test);
     if (isset($config["namespace"])) {
         $settings['class_name'] = $config["namespace"] . '\\' . $settings['class_name'];
     }
     $actor = $settings['class_name'];
     $I = new $actor($scenario);
     $this->listenToSignals();
     $output->writeln("<info>Interactive console started for suite {$suiteName}</info>");
     $output->writeln("<info>Try Codeception commands without writing a test</info>");
     $output->writeln("<info>type 'exit' to leave console</info>");
     $output->writeln("<info>type 'actions' to see all available actions for this suite</info>");
     $suiteEvent = new SuiteEvent($this->suite, $this->codecept->getResult(), $settings);
     $dispatcher->dispatch(Events::SUITE_BEFORE, $suiteEvent);
     $dispatcher->dispatch(Events::TEST_PARSED, new TestEvent($this->test));
     $dispatcher->dispatch(Events::TEST_BEFORE, new TestEvent($this->test));
     $output->writeln("\n\n<comment>\$I</comment> = new {$settings['class_name']}(\$scenario);");
     $this->executeCommands($input, $output, $I, $settings['bootstrap']);
     $dispatcher->dispatch(Events::TEST_AFTER, new TestEvent($this->test));
     $dispatcher->dispatch(Events::SUITE_AFTER, new SuiteEvent($this->suite));
     $output->writeln("<info>Bye-bye!</info>");
 }
Exemple #10
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()));
 }
Exemple #11
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;
 }
 public function testAddTest()
 {
     $file = $file = \Codeception\Configuration::dataDir() . 'SimpleTest.php';
     $this->suiteman->addTest($file);
     $this->assertEquals(1, $this->suiteman->getSuite()->count());
 }
Exemple #13
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;
    }
Exemple #14
0
 protected function hasModule($name)
 {
     return SuiteManager::hasModule($name);
 }
Exemple #15
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;
 }