コード例 #1
0
ファイル: Printer.php プロジェクト: Vrian7ipx/cascadadev
 public function __construct($options)
 {
     $this->options = $options;
     $this->logDir = Configuration::outputDir();
     $this->settings = array_merge($this->settings, Configuration::config()['coverage']);
     self::$coverage = new \PHP_CodeCoverage();
 }
コード例 #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $config = \Codeception\Configuration::config();
     $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
     @mkdir($path = \Codeception\Configuration::dataDir() . 'scenarios');
     @mkdir($path = $path . DIRECTORY_SEPARATOR . $suite);
     $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
     $suiteManager = new \Codeception\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();
     foreach ($tests as $test) {
         if (!$test instanceof \Codeception\TestCase\Cept) {
             continue;
         }
         $test->loadScenario();
         $features = $test->getScenarioText();
         $name = $this->underscore(substr($test->getFileName(), 0, -8));
         $output->writeln("* {$name} generated");
         file_put_contents($path . DIRECTORY_SEPARATOR . $name . '.txt', $features);
     }
 }
コード例 #3
0
ファイル: Runner.php プロジェクト: Vrian7ipx/cascadadev
 public function __construct()
 {
     $this->config  = Configuration::config();
     $this->logDir = Configuration::outputDir(); // prepare log dir
     $this->phpUnitOverriders();
     parent::__construct();
 }
コード例 #4
0
ファイル: Build.php プロジェクト: BatVane/Codeception
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = \Codeception\Configuration::config();
     $suites = \Codeception\Configuration::suites();
     foreach ($suites as $suite) {
         $settings = \Codeception\Configuration::suiteSettings($suite, $config);
         $modules = \Codeception\Configuration::modules($settings);
         $phpdoc = array();
         $methodCounter = 0;
         foreach ($modules as $modulename => $module) {
             $class = new \ReflectionClass('\\Codeception\\Module\\' . $modulename);
             $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
             $phpdoc[] = '';
             $phpdoc[] = 'Methods from ' . $modulename;
             foreach ($methods as $method) {
                 if (strpos($method->name, '_') === 0) {
                     continue;
                 }
                 $params = array();
                 foreach ($method->getParameters() as $param) {
                     if ($param->isOptional()) {
                         continue;
                     }
                     $params[] = '$' . $param->name;
                 }
                 $params = implode(', ', $params);
                 $phpdoc[] = '@method ' . $settings['class_name'] . ' ' . $method->name . '(' . $params . ')';
                 $methodCounter++;
             }
         }
         $contents = sprintf($this->template, implode("\r\n * ", $phpdoc), 'class', $settings['class_name'], '\\Codeception\\AbstractGuy');
         file_put_contents($file = $settings['path'] . $settings['class_name'] . '.php', $contents);
         $output->writeln("{$file} generated sucessfully. {$methodCounter} methods added");
     }
 }
コード例 #5
0
ファイル: Analyze.php プロジェクト: lenninsanchez/donadores
 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");
 }
コード例 #6
0
ファイル: GenerateSuite.php プロジェクト: cakephp/codeception
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = ucfirst($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 = $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, 'bootstrap.php');
     // generate bootstrap
     $this->save($dir . $suite . DIRECTORY_SEPARATOR . 'bootstrap.php', "<?php\n// Here you can initialize variables that will be available to your tests\n", true);
     $actorName = $this->removeSuffix($actor, $config['actor']);
     // generate helper
     $this->save(\Codeception\Configuration::helpersDir() . $actorName . 'Helper.php', (new Helper($actorName, $config['namespace']))->produce());
     $enabledModules = ['Cake\\Codeception\\Helper', 'App\\TestSuite\\Codeception\\' . $actorName . 'Helper'];
     if ('Unit' === $suite) {
         array_shift($enabledModules);
     }
     $conf = ['class_name' => $actorName . $config['actor'], 'modules' => ['enabled' => $enabledModules]];
     $this->save($dir . $suite . '.suite.yml', Yaml::dump($conf, 2));
     $output->writeln("<info>Suite {$suite} generated</info>");
 }
コード例 #7
0
ファイル: GenerateSuite.php プロジェクト: pfz/codeception
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $guy = $input->getArgument('guy');
     $config = \Codeception\Configuration::config($input->getOption('config'));
     $dir = \Codeception\Configuration::projectDir() . $config['paths']['tests'] . DIRECTORY_SEPARATOR;
     if (file_exists($dir . DIRECTORY_SEPARATOR . $suite)) {
         throw new \Exception("Directory {$suite} already exists.");
     }
     if (file_exists($dir . $suite . '.suite.yml')) {
         throw new \Exception("Suite configuration file '{$suite}.suite.yml' already exists.");
     }
     @mkdir($dir . DIRECTORY_SEPARATOR . $suite);
     // generate bootstrap
     file_put_contents($dir . DIRECTORY_SEPARATOR . $suite . '/_bootstrap.php', "<?php\n// Here you can initialize variables that will for your tests\n");
     if (strpos(strrev($guy), 'yuG') !== 0) {
         $guy = $guy . 'Guy';
     }
     $guyname = substr($guy, 0, -3);
     // generate helper
     file_put_contents(\Codeception\Configuration::projectDir() . $config['paths']['helpers'] . DIRECTORY_SEPARATOR . $guyname . 'Helper.php', "<?php\nnamespace Codeception\\Module;\n\n// here you can define custom functions for {$guy} \n\nclass {$guyname}Helper extends \\Codeception\\Module\n{\n}\n");
     $conf = array('class_name' => $guy, 'modules' => array('enabled' => array($guyname . 'Helper')));
     file_put_contents($dir . $suite . '.suite.yml', Yaml::dump($conf, 2));
     $output->writeln("<info>Suite {$suite} generated</info>");
 }
コード例 #8
0
ファイル: Console.php プロジェクト: Eli-TW/Codeception
 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>");
 }
コード例 #9
0
ファイル: GenerateCept.php プロジェクト: BatVane/Codeception
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $filename = $input->getArgument('test');
     $config = \Codeception\Configuration::config();
     $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
     $guy = $suiteconf['class_name'];
     $file = sprintf($this->template, $guy);
     if (file_exists($suiteconf['path'] . DIRECTORY_SEPARATOR . $filename)) {
         $output->writeln("<comment>Test {$filename} already exists</comment>");
         return;
     }
     if (strpos(strrev($filename), strrev('Cept')) === 0) {
         $filename .= '.php';
     }
     if (strpos(strrev($filename), strrev('Cept.php')) !== 0) {
         $filename .= 'Cept.php';
     }
     if (strpos(strrev($filename), strrev('.php')) !== 0) {
         $filename .= '.php';
     }
     $filename = str_replace('\\', '/', $filename);
     $dirs = explode('/', $filename);
     array_pop($dirs);
     $path = $suiteconf['path'] . DIRECTORY_SEPARATOR;
     foreach ($dirs as $dir) {
         $path .= $dir . DIRECTORY_SEPARATOR;
         @mkdir($path);
     }
     file_put_contents($suiteconf['path'] . DIRECTORY_SEPARATOR . $filename, $file);
     $output->writeln("<info>Test was generated in {$filename}</info>");
 }
コード例 #10
0
ファイル: Runner.php プロジェクト: NaszvadiG/ImageCMS
 public function __construct()
 {
     $this->config = Configuration::config();
     $this->log_dir = Configuration::logDir();
     // prepare log dir
     parent::__construct();
 }
コード例 #11
0
ファイル: Console.php プロジェクト: lenninsanchez/donadores
 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>");
 }
コード例 #12
0
ファイル: Build.php プロジェクト: namnv609/Codeception
 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.");
         }
     }
 }
コード例 #13
0
    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>");
    }
コード例 #14
0
ファイル: Run.php プロジェクト: lenninsanchez/donadores
 protected function currentNamespace()
 {
     $config = Configuration::config();
     if (!$config['namespace']) {
         throw new \RuntimeException("Can't include into runner suite without a namespace;\nUse 'refactor:add-namespace' command to fix it'");
     }
     return $config['namespace'];
 }
コード例 #15
0
ファイル: DbSnapshot.php プロジェクト: lucatume/wp-browser
 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;
 }
コード例 #16
0
/**
 * Calls setup functions that might be required for plugins to work.
 *
 * @throws \Codeception\Exception\Configuration
 */
function tribe_call_setup_functions()
{
    $config = \Codeception\Configuration::config();
    if (isset($config['php']['globals']['wp_tests_options']['setup_functions']) && is_array($config['php']['globals']['wp_tests_options']['setup_functions'])) {
        foreach ($config['php']['globals']['wp_tests_options']['setup_functions'] as $function) {
            call_user_func($function);
        }
    }
}
コード例 #17
0
ファイル: Test.php プロジェクト: kansey/yii2albom
 public function produce()
 {
     $actor = $this->settings['class_name'];
     if ($this->settings['namespace']) {
         $actor = $this->settings['namespace'] . '\\' . $actor;
     }
     $ns = $this->getNamespaceString($this->settings['namespace'] . '\\' . $this->name);
     return (new Template($this->template))->place('namespace', $ns)->place('name', $this->getShortClassName($this->name))->place('actorClass', $actor)->place('actor', lcfirst(Configuration::config()['actor']))->produce();
 }
コード例 #18
0
ファイル: Build.php プロジェクト: solutionDrive/Codeception
 private function buildActor(array $settings)
 {
     $actorGenerator = new ActorGenerator($settings);
     $this->output->writeln('<info>' . Configuration::config()['namespace'] . '\\' . $actorGenerator->getActorName() . "</info> includes modules: " . implode(', ', $actorGenerator->getModules()));
     $content = $actorGenerator->produce();
     $file = $this->buildPath(Configuration::supportDir(), $settings['class_name']) . $this->getClassName($settings['class_name']);
     $file .= '.php';
     return $this->save($file, $content);
 }
コード例 #19
0
ファイル: CestTest.php プロジェクト: BatVane/Codeception
 public function setUp()
 {
     $this->dispatcher = new Symfony\Component\EventDispatcher\EventDispatcher();
     $conf = \Codeception\Configuration::config();
     require_once \Codeception\Configuration::dataDir() . 'DummyClass.php';
     $file = \Codeception\Configuration::dataDir() . 'SimpleCest.php';
     require_once $file;
     $this->testcase = new \Codeception\TestCase\Cest($this->dispatcher, array('name' => '', 'file' => $file, 'class' => new SimpleCest(), 'method' => 'helloWorld', 'static' => false, 'signature' => 'DummyClass.helloWorld'));
 }
コード例 #20
0
ファイル: Codecept.php プロジェクト: BatVane/Codeception
 public function __construct($options = array())
 {
     $this->result = new \PHPUnit_Framework_TestResult();
     $this->dispatcher = new EventDispatcher();
     $this->config = \Codeception\Configuration::config();
     $this->options = $this->mergeOptions($options);
     $this->path = $this->config['paths']['tests'];
     $this->registerSubscribers();
     $this->registerListeners();
 }
コード例 #21
0
ファイル: Printer.php プロジェクト: Eli-TW/Codeception
 public function __construct($options)
 {
     $this->options = $options;
     $this->logDir = Configuration::outputDir();
     $this->settings = array_merge($this->settings, Configuration::config()['coverage']);
     self::$coverage = new \PHP_CodeCoverage();
     // Apply filter
     $filter = new Filter(self::$coverage);
     $filter->whiteList(Configuration::config())->blackList(Configuration::config());
 }
コード例 #22
0
 public function __construct()
 {
     //grab the global config file
     $config = Configuration::config();
     //get  the unit settings
     $settings = Configuration::suiteSettings("unit", $config);
     //get the settings for the db module
     $dbConfig = (isset($settings['modules']['config']['Db'])) ? $settings['modules']['config']['Db'] : array();
     //set the config for the helper module
     $this->_setConfig($dbConfig);
 }
コード例 #23
0
ファイル: CodeHelper.php プロジェクト: atabak/orm
 /**
  * Gets a working DB connection
  *
  * @returns \Fuel\Database\Connection
  */
 public function getDbInstance()
 {
     if ($this->connection === null) {
         // Grab the DB config from codeception and create a DB instance we can use to talk to the database with
         $config = Configuration::config();
         $dbConfig = $config['modules']['config']['Db'];
         /** @type Connection $fuelDBConnection */
         $this->connection = \Fuel\Database\DB::connection(['dsn' => $dbConfig['dsn'], 'username' => $dbConfig['user'], 'password' => $dbConfig['password']]);
     }
     return $this->connection;
 }
コード例 #24
0
ファイル: GenerateHelper.php プロジェクト: itillawarra/cmfive
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $name = ucfirst($input->getArgument('name'));
     $config = \Codeception\Configuration::config($input->getOption('config'));
     $file = \Codeception\Configuration::helpersDir() . "{$name}Helper.php";
     $res = $this->save($file, (new Helper($name, $config['namespace']))->produce());
     if ($res) {
         $output->writeln("<info>Helper {$file} created</info>");
     } else {
         $output->writeln("<error>Error creating helper {$file}</error>");
     }
 }
コード例 #25
0
ファイル: Yii2.php プロジェクト: Dossar/boltbse
 public function _before(TestCase $test)
 {
     $this->client = new Yii2Connector();
     $this->client->configFile = Configuration::projectDir() . $this->config['configFile'];
     $mainConfig = Configuration::config()['config'];
     if (isset($mainConfig['test_entry_url'])) {
         $this->client->setServerParameter('HTTPS', parse_url($mainConfig['test_entry_url'], PHP_URL_SCHEME) === 'https');
     }
     $this->app = $this->client->startApp();
     if ($this->config['cleanup'] && isset($this->app->db)) {
         $this->transaction = $this->app->db->beginTransaction();
     }
 }
コード例 #26
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>");
     }
 }
コード例 #27
0
ファイル: Test.php プロジェクト: hitechdk/Codeception
 protected function setUp()
 {
     $actor = $this->actor;
     if ($actor) {
         $property = lcfirst(Configuration::config()['actor']);
         $this->{$property} = new $actor($this->scenario);
         // BC compatibility hook
         $actorProperty = lcfirst($actor);
         $this->{$actorProperty} = $this->{$property};
     }
     $this->_before();
     $this->prepareActorForTest();
 }
コード例 #28
0
ファイル: GenerateScenarios.php プロジェクト: pfz/codeception
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $suite = $input->getArgument('suite');
     $config = \Codeception\Configuration::config($input->getOption('config'));
     $suiteconf = \Codeception\Configuration::suiteSettings($suite, $config);
     if ($input->getOption('path')) {
         $path = $input->getOption('path');
     } else {
         $path = \Codeception\Configuration::dataDir() . 'scenarios';
     }
     @mkdir($path);
     if (!is_writable($path)) {
         throw new \Codeception\Exception\Configuration("Path for logs is not writable. Please, set appropriate access mode for log path.");
     }
     $path = $path . DIRECTORY_SEPARATOR . $suite;
     if ($input->getOption('single-file')) {
         file_put_contents($path . '.txt', '');
     } else {
         @mkdir($path);
     }
     $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
     $suiteManager = new \Codeception\SuiteManager($dispatcher, $suite, $suiteconf);
     if ($suiteconf['bootstrap']) {
         if (file_exists($suiteconf['path'] . $suiteconf['bootstrap'])) {
             require_once $suiteconf['path'] . $suiteconf['bootstrap'];
         }
     }
     $suiteManager->loadTests();
     $tests = $suiteManager->getSuite()->tests();
     if ($input->getOption('format')) {
         $format = $input->getOption('format');
     } else {
         $format = 'text';
     }
     foreach ($tests as $test) {
         if (!$test instanceof \Codeception\TestCase\Cept) {
             continue;
         }
         $test->preload();
         $features = $test->getScenarioText($format);
         $name = $this->underscore(substr($test->getFileName(), 0, -8));
         if ($input->getOption('single-file')) {
             file_put_contents($path . '.txt', $features . PHP_EOL, FILE_APPEND);
             $output->writeln("* {$name} rendered");
         } else {
             file_put_contents($path . DIRECTORY_SEPARATOR . $name . '.txt', $features);
             $output->writeln("* {$name} generated");
         }
     }
 }
コード例 #29
0
ファイル: JUnit.php プロジェクト: foxman209/Codeception
 public function startTest(\PHPUnit_Framework_Test $test)
 {
     if (!$test instanceof Reported) {
         return parent::startTest($test);
     }
     $this->currentTestCase = $this->document->createElement('testcase');
     $isStrict = Configuration::config()['settings']['strict_xml'];
     foreach ($test->getReportFields() as $attr => $value) {
         if ($isStrict and !in_array($attr, $this->strictAttributes)) {
             continue;
         }
         $this->currentTestCase->setAttribute($attr, $value);
     }
 }
コード例 #30
0
ファイル: Yii2.php プロジェクト: namnv609/Codeception
 public function _before(\Codeception\TestCase $test)
 {
     $this->client = new \Codeception\Lib\Connector\Yii2();
     $this->client->configFile = \Codeception\Configuration::projectDir() . $this->config['configFile'];
     $mainConfig = \Codeception\Configuration::config();
     if (isset($mainConfig['config']) && isset($mainConfig['config']['test_entry_url'])) {
         $this->client->setServerParameter('HTTP_HOST', (string) parse_url($mainConfig['config']['test_entry_url'], PHP_URL_HOST));
         $this->client->setServerParameter('HTTPS', (string) parse_url($mainConfig['config']['test_entry_url'], PHP_URL_SCHEME) === 'https');
     }
     $this->app = $this->client->startApp();
     if ($this->config['cleanup'] and isset($this->app->db)) {
         $this->transaction = $this->app->db->beginTransaction();
     }
 }