本文整理汇总了PHP中Codeception\Configuration类的典型用法代码示例。如果您正苦于以下问题:PHP Configuration类的具体用法?PHP Configuration怎么用?PHP Configuration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$options = $input->getOptions();
if ($input->getArgument('test')) {
$options['steps'] = true;
}
$suite = $input->getArgument('suite');
$test = $input->getArgument('test');
$codecept = new \Codeception\Codecept((array) $options);
$suites = $suite ? array($suite) : \Codeception\Configuration::suites();
$output->writeln(\Codeception\Codecept::versionString() . "\nPowered by " . \PHPUnit_Runner_Version::getVersionString());
if ($suite and $test) {
$codecept->runSuite($suite, $test);
}
if (!$test) {
foreach ($suites as $suite) {
$codecept->runSuite($suite);
}
}
$codecept->printResult();
if (!$input->getOption('no-exit')) {
if ($codecept->getResult()->failureCount() or $codecept->getResult()->errorCount()) {
exit(1);
}
}
}
示例2: __construct
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();
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$suites = $this->getSuites($input->getOption('config'));
$output->writeln("<info>Building Guy classes for suites: " . implode(', ', $suites) . '</info>');
foreach ($suites as $suite) {
$settings = $this->getSuiteConfig($suite, $input->getOption('config'));
$namespace = rtrim($settings['namespace'], '\\');
$modules = \Codeception\Configuration::modules($settings);
$code = array();
$methodCounter = 0;
$output->writeln('<info>' . $settings['class_name'] . "</info> includes modules: " . implode(', ', array_keys($modules)));
$docblock = array();
foreach ($modules as $module) {
$docblock[] = "use " . get_class($module) . ";";
}
$methods = array();
$actions = \Codeception\Configuration::actions($modules);
foreach ($actions as $action => $moduleName) {
if (in_array($action, $methods)) {
continue;
}
$module = $modules[$moduleName];
$method = new \ReflectionMethod(get_class($module), $action);
$code[] = $this->addMethod($method);
$methods[] = $action;
$methodCounter++;
}
$docblock = $this->prependAbstractGuyDocBlocks($docblock);
$contents = sprintf($this->template, $namespace ? "namespace {$namespace};" : '', implode("\n", $docblock), 'class', $settings['class_name'], '\\Codeception\\AbstractGuy', implode("\n\n ", $code));
$file = $settings['path'] . $this->getClassName($settings['class_name']) . '.php';
$this->save($file, $contents, true);
$output->writeln("{$settings['class_name']}.php generated successfully. {$methodCounter} methods added");
}
}
示例4: updateActor
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);
}
}
示例5: execute
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>");
}
示例6: execute
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: execute
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>");
}
示例8: _before
public function _before(\Codeception\TestCase $test)
{
require_once \Codeception\Configuration::projectDir() . 'src/includes/autoload.php';
require_once \Codeception\Configuration::projectDir() . 'src/includes/classmap.php';
require_once \Codeception\Configuration::projectDir() . 'src/Vendor/autoload.php';
spl_autoload_register('autoloadlitpi');
include_once \Codeception\Configuration::projectDir() . 'src/libs/smarty/Smarty.class.php';
//Overwrite remoteaddr
$_SERVER['REMOTE_ADDR'] = $this->config['remoteaddr'];
//INIT REGISTRY VARIABLE - MAIN STORAGE OF APPLICATION
$registry = \Litpi\Registry::getInstance();
$request = \Litpi\Request::createFromGlobals();
$response = new \Litpi\Response();
$session = new \Litpi\Session();
$registry->set('request', $request);
$registry->set('response', $response);
$registry->set('session', $session);
require_once \Codeception\Configuration::projectDir() . 'src/includes/conf.php';
require_once \Codeception\Configuration::projectDir() . 'src/includes/config.php';
require_once \Codeception\Configuration::projectDir() . 'src/includes/setting.php';
$registry->set('conf', $conf);
$registry->set('setting', $setting);
$registry->set('https', PROTOCOL == 'https' ? true : false);
require_once \Codeception\Configuration::projectDir() . 'src/includes/permission.php';
$registry->set('groupPermisson', $groupPermisson);
require_once \Codeception\Configuration::projectDir() . 'src/includes/rewriterule.php';
require_once \Codeception\Configuration::projectDir() . 'src/includes/startup.php';
$this->registry = $registry;
$this->client = new \Codeception\Lib\Connector\LitpiConnectorHelper();
$this->client->setRegistry($this->registry);
}
示例9: setUp
public function setUp()
{
$this->dispatcher = new Symfony\Component\EventDispatcher\EventDispatcher();
$this->testcase = new \Codeception\TestCase\Cept();
$this->testcase->configDispatcher($this->dispatcher)->configName('mocked test')->configFile(\Codeception\Configuration::dataDir() . 'SimpleCept.php')->initConfig();
\Codeception\SuiteManager::$modules['EmulateModuleHelper']->assertions = 0;
}
示例10: _initialize
/**
* @inheritdoc
*/
public function _initialize()
{
// compute datbase info
$match = preg_match("/host=(.*);dbname=(.*)/", env("DB_DSN"), $matches);
if (!$match) {
return;
}
$host = $matches[1];
$name = $matches[2] . "_test";
$user = env("DB_USER");
$pass = env("DB_PASS");
// compute dump file
$dumpFile = $this->config['dump'] ?: "tests/_data/dump.sql";
$dumpFile = Configuration::projectDir() . $dumpFile;
if (!file_exists($dumpFile)) {
throw new ModuleException(__CLASS__, "Dump file does not exist [ {$dumpFile} ]");
}
// dump
$cmd = "mysql -h {$host} -u {$user} -p{$pass} {$name} < {$dumpFile}";
$start = microtime(true);
$output = shell_exec($cmd);
$end = microtime(true);
$diff = round(($end - $start) * 1000, 2);
// output debug info
$className = get_called_class();
codecept_debug("{$className} - Importing db [ {$name} ] [ {$diff} ms ]");
// check for error
if ($output) {
throw new ModuleException(__CLASS__, "Failed to import db [ {$cmd} ]");
}
}
示例11: testActions
public function testActions()
{
$modules = array('EmulateModuleHelper' => new \Codeception\Module\EmulateModuleHelper());
$actions = \Codeception\Configuration::actions($modules);
$this->assertArrayHasKey('seeEquals', $actions);
$this->assertEquals('EmulateModuleHelper', $actions['seeEquals']);
}
示例12: execute
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>");
}
示例13: testCreateInSubpath
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);
}
示例14: buildActorsForConfig
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.");
}
}
}
示例15: __construct
public function __construct()
{
$this->config = Configuration::config();
$this->logDir = Configuration::outputDir(); // prepare log dir
$this->phpUnitOverriders();
parent::__construct();
}