本文整理汇总了PHP中Codeception\Configuration::helpersDir方法的典型用法代码示例。如果您正苦于以下问题:PHP Configuration::helpersDir方法的具体用法?PHP Configuration::helpersDir怎么用?PHP Configuration::helpersDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Codeception\Configuration
的用法示例。
在下文中一共展示了Configuration::helpersDir方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
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");
}
示例2: 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>");
}
示例3: updateHelpers
protected function updateHelpers()
{
$helpers = Finder::create()->files()->name('*Helper.php')->in(\Codeception\Configuration::helpersDir());
foreach ($helpers as $helper_file) {
$helper_body = file_get_contents($helper_file);
$helper_body = preg_replace('~namespace Codeception\\\\Module;~', "namespace {$this->namespace}\\Codeception\\Module;", $helper_body);
$this->save($helper_file, $helper_body, true);
}
}
示例4: testGuyWithSuffix
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('HobbitHelper', $conf['modules']['enabled']);
$helper = $this->log[1];
$this->assertEquals(\Codeception\Configuration::helpersDir() . 'HobbitHelper.php', $helper['filename']);
$this->assertContains('class HobbitHelper extends \\Codeception\\Module', $helper['content']);
}
示例5: execute
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>");
}
}
示例6: testBasic
public function testBasic()
{
$this->execute(array('namespace' => 'MiddleEarth', '--force' => true));
$this->assertContains('adds namespaces to your Helper and Guy classes and Cepts', $this->output);
$config = $this->log[0];
$this->assertContains('Config file updated', $this->output);
$this->assertContains('namespace: MiddleEarth', $config['content']);
$this->assertEquals(\Codeception\Configuration::projectDir() . 'codeception.yml', (string) $config['filename']);
$helper = $this->log[1];
$this->assertContains('namespace MiddleEarth\\Codeception\\Module', $helper['content']);
$this->assertRegExp('~' . \Codeception\Configuration::helpersDir() . '.*?Helper~', (string) $helper['filename']);
// log[2] is helper, log[3] ... are helpers too
$cept = $this->log[7];
$this->assertRegExp('~<?php use MiddleEarth\\\\.*Guy~', $cept['content']);
$this->assertIsValidPhp($cept['content']);
}
示例7: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$suite = lcfirst($input->getArgument('suite'));
$actor = $input->getArgument('actor');
$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)) {
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.");
}
$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 for 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()
);
$conf = array(
'class_name' => $actorName.$config['actor'],
'modules' => array(
'enabled' => array($actorName . 'Helper')
),
);
$this->save($dir . $suite . '.suite.yml', Yaml::dump($conf, 2));
$output->writeln("<info>Suite $suite generated</info>");
}
示例8: autoloadHelpers
protected static function autoloadHelpers()
{
Autoload::registerSuffix('Helper', \Codeception\Configuration::helpersDir());
}