public function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $step = $input->getArgument('step');
     $config = $this->getSuiteConfig($suite, $input->getOption('config'));
     $class = $this->getClassName($step);
     $path = $this->buildPath(Configuration::supportDir() . 'Step' . DIRECTORY_SEPARATOR . ucfirst($suite), $step);
     $dialog = $this->getHelperSet()->get('question');
     $filename = $path . $class . '.php';
     $helper = $this->getHelper('question');
     $question = new Question("Add action to StepObject class (ENTER to exit): ");
     $gen = new StepObjectGenerator($config, ucfirst($suite) . '\\' . $step);
     if (!$input->getOption('silent')) {
         do {
             $question = new Question('Add action to StepObject class (ENTER to exit): ', null);
             $action = $dialog->ask($input, $output, $question);
             if ($action) {
                 $gen->createAction($action);
             }
         } while ($action);
     }
     $res = $this->save($filename, $gen->produce());
     if (!$res) {
         $output->writeln("<error>StepObject {$filename} already exists</error>");
         exit;
     }
     $output->writeln("<info>StepObject was created in {$filename}</info>");
 }
    public function execute(InputInterface $input, OutputInterface $output)
    {
        $suite = lcfirst($input->getArgument('suite'));
        $actor = $input->getArgument('actor');
        if ($this->containsInvalidCharacters($suite)) {
            $output->writeln("<error>Suite name '{$suite}' contains invalid characters. ([A-Za-z0-9_]).</error>");
            return;
        }
        $config = \Codeception\Configuration::config($input->getOption('config'));
        if (!$actor) {
            $actor = ucfirst($suite) . $config['actor'];
        }
        $config['class_name'] = $actor;
        $dir = \Codeception\Configuration::testsDir();
        if (file_exists($dir . $suite . '.suite.yml')) {
            throw new \Exception("Suite configuration file '{$suite}.suite.yml' already exists.");
        }
        $this->buildPath($dir . $suite . DIRECTORY_SEPARATOR, $config['settings']['bootstrap']);
        // generate bootstrap
        $this->save($dir . $suite . DIRECTORY_SEPARATOR . $config['settings']['bootstrap'], "<?php\n// Here you can initialize variables that will be available to your tests\n", true);
        $actorName = $this->removeSuffix($actor, $config['actor']);
        $file = $this->buildPath(\Codeception\Configuration::supportDir() . "Helper", "{$actorName}.php") . "{$actorName}.php";
        $gen = new Helper($actorName, $config['namespace']);
        // generate helper
        $this->save($file, $gen->produce());
        $conf = <<<EOF
class_name: {{actor}}
modules:
    enabled:
        - {{helper}}
EOF;
        $this->save($dir . $suite . '.suite.yml', (new Template($conf))->place('actor', $actorName . $config['actor'])->place('helper', $gen->getHelperName())->produce());
        $output->writeln("<info>Suite {$suite} generated</info>");
    }
Example #3
0
 public function updateActor(SuiteEvent $e)
 {
     $settings = $e->getSettings();
     $modules = $e->getSuite()->getModules();
     $actorFile = Configuration::supportDir() . '_generated' . DIRECTORY_SEPARATOR . $settings['class_name'] . 'Actions.php';
     // load guy class to see hash
     $handle = @fopen($actorFile, "r");
     if ($handle and is_writable($actorFile)) {
         $line = @fgets($handle);
         if (preg_match('~\\[STAMP\\] ([a-f0-9]*)~', $line, $matches)) {
             $hash = $matches[1];
             $currentHash = Actions::genHash($modules, $settings);
             // regenerate guy class when hashes do not match
             if ($hash != $currentHash) {
                 codecept_debug("Rebuilding {$settings['class_name']}...");
                 $actionsGenerator = new Actions($settings);
                 @fclose($handle);
                 $generated = $actionsGenerator->produce();
                 @file_put_contents($actorFile, $generated);
                 return;
             }
         }
         @fclose($handle);
     }
 }
 public function testCreateInSubpath()
 {
     $this->execute(array('suite' => 'shire', 'step' => 'User/Login', '--silent' => true));
     $generated = $this->log[0];
     $this->assertEquals(\Codeception\Configuration::supportDir() . 'Step/Shire/User/Login.php', $generated['filename']);
     $this->assertIsValidPhp($this->content);
 }
Example #5
0
 protected function buildActorsForConfig($configFile)
 {
     $config = $this->getGlobalConfig($configFile);
     $suites = $this->getSuites($configFile);
     $path = pathinfo($configFile);
     $dir = isset($path['dirname']) ? $path['dirname'] : getcwd();
     foreach ($config['include'] as $subConfig) {
         $this->output->writeln("<comment>Included Configuration: {$subConfig}</comment>");
         $this->buildActorsForConfig($dir . DIRECTORY_SEPARATOR . $subConfig);
     }
     if (!empty($suites)) {
         $this->output->writeln("<info>Building Actor classes for suites: " . implode(', ', $suites) . '</info>');
     }
     foreach ($suites as $suite) {
         $settings = $this->getSuiteConfig($suite, $configFile);
         $actionsGenerator = new ActionsGenerator($settings);
         $contents = $actionsGenerator->produce();
         $actorGenerator = new ActorGenerator($settings);
         $file = $this->buildPath(Configuration::supportDir() . '_generated', $settings['class_name']) . $this->getClassName($settings['class_name']) . 'Actions.php';
         $this->save($file, $contents, true);
         $this->output->writeln('<info>' . Configuration::config()['namespace'] . '\\' . $actorGenerator->getActorName() . "</info> includes modules: " . implode(', ', $actorGenerator->getModules()));
         $this->output->writeln(" -> {$settings['class_name']}Actions.php generated successfully. " . $actionsGenerator->getNumMethods() . " methods added");
         $contents = $actorGenerator->produce();
         $file = $this->buildPath(Configuration::supportDir(), $settings['class_name']) . $this->getClassName($settings['class_name']) . '.php';
         if ($this->save($file, $contents)) {
             $this->output->writeln("{$settings['class_name']}.php created.");
         }
     }
 }
 public function testNamespace()
 {
     $this->config['namespace'] = 'Shire';
     $this->execute(array('group' => 'Core'));
     $generated = $this->log[0];
     $this->assertEquals(\Codeception\Configuration::supportDir() . 'Group/Core.php', $generated['filename']);
     $this->assertContains('namespace Shire\\Group;', $generated['content']);
     $this->assertIsValidPhp($generated['content']);
 }
 protected function generateActorActions($actorActionsFile, $settings)
 {
     if (!file_exists(Configuration::supportDir() . '_generated')) {
         @mkdir(Configuration::supportDir() . '_generated');
     }
     $actionsGenerator = new Actions($settings);
     $generated = $actionsGenerator->produce();
     @file_put_contents($actorActionsFile, $generated);
 }
Example #8
0
 private function buildActions(array $settings)
 {
     $actionsGenerator = new ActionsGenerator($settings);
     $this->output->writeln(" -> {$settings['class_name']}Actions.php generated successfully. " . $actionsGenerator->getNumMethods() . " methods added");
     $content = $actionsGenerator->produce();
     $file = $this->buildPath(Configuration::supportDir() . '_generated', $settings['class_name']);
     $file .= $this->getClassName($settings['class_name']) . 'Actions.php';
     return $this->save($file, $content, true);
 }
 public function testGuyWithSuffix()
 {
     $this->execute(array('suite' => 'shire', 'actor' => 'HobbitGuy'));
     $conf = \Symfony\Component\Yaml\Yaml::parse($this->content);
     $this->assertEquals('HobbitGuy', $conf['class_name']);
     $this->assertContains('\\Helper\\Hobbit', $conf['modules']['enabled']);
     $helper = $this->log[1];
     $this->assertEquals(\Codeception\Configuration::supportDir() . 'Helper/Hobbit.php', $helper['filename']);
     $this->assertContains('class Hobbit extends \\Codeception\\Module', $helper['content']);
 }
Example #10
0
 public function initialize()
 {
     $this->dispatcher->dispatch(Events::MODULE_INIT, new Event\SuiteEvent($this->suite, null, $this->settings));
     foreach ($this->moduleContainer->all() as $module) {
         $module->_initialize();
     }
     if (!file_exists(Configuration::supportDir() . $this->settings['class_name'] . '.php')) {
         throw new Exception\ConfigurationException($this->settings['class_name'] . " class doesn't exist in suite folder.\nRun the 'build' command to generate it");
     }
     $this->dispatcher->dispatch(Events::SUITE_INIT, new Event\SuiteEvent($this->suite, null, $this->settings));
     ini_set('xdebug.show_exception_trace', 0);
     // Issue https://github.com/symfony/symfony/issues/7646
 }
Example #11
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $name = ucfirst($input->getArgument('name'));
     $config = Configuration::config($input->getOption('config'));
     $path = $this->buildPath(Configuration::supportDir() . 'Helper', $name);
     $filename = $path . $this->getClassName($name) . '.php';
     $res = $this->save($filename, (new Helper($name, $config['namespace']))->produce());
     if ($res) {
         $output->writeln("<info>Helper {$filename} created</info>");
     } else {
         $output->writeln("<error>Error creating helper {$filename}</error>");
     }
 }
Example #12
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $config = $this->getGlobalConfig($input->getOption('config'));
     $group = $input->getArgument('group');
     $class = ucfirst($group);
     $path = $this->buildPath(Configuration::supportDir() . 'Group' . DIRECTORY_SEPARATOR, $class);
     $filename = $path . $class . '.php';
     $gen = new GroupGenerator($config, $group);
     $res = $this->save($filename, $gen->produce());
     if (!$res) {
         $output->writeln("<error>Group {$filename} already exists</error>");
         return;
     }
     $output->writeln("<info>Group extension was created in {$filename}</info>");
     $output->writeln('To use this group extension, include it to "extensions" option of global Codeception config.');
 }
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $class = $input->getArgument('page');
     if (!$class) {
         $class = $suite;
         $suite = null;
     }
     $conf = $suite ? $this->getSuiteConfig($suite, $input->getOption('config')) : $this->getGlobalConfig($input->getOption('config'));
     if ($suite) {
         $suite = DIRECTORY_SEPARATOR . ucfirst($suite);
     }
     $path = $this->buildPath(Configuration::supportDir() . 'Page' . $suite, $class);
     $filename = $path . $this->getClassName($class) . '.php';
     $output->writeln($filename);
     $gen = new PageObjectGenerator($conf, ucfirst($suite) . '\\' . $class);
     $res = $this->save($filename, $gen->produce());
     if (!$res) {
         $output->writeln("<error>PageObject {$filename} already exists</error>");
         exit;
     }
     $output->writeln("<info>PageObject was created in {$filename}</info>");
 }
 public function testCreateInSubpath()
 {
     $this->execute(array('suite' => 'User/View'));
     $this->assertEquals(\Codeception\Configuration::supportDir() . 'Page/User/View.php', $this->filename);
     $this->assertIsValidPhp($this->content);
 }