Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.phar
vendor
package/codecept.phar
package/codecept.phar
composer.lock
6 changes: 4 additions & 2 deletions App/Config/codeception.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

'sites' => array(

'Webception' => dirname(__FILE__) .'/../../codeception.yml',

//'cm5 staff' => dirname(__FILE__) .'\..\..\..\2picrm/modules\staff\codeception.yml',
'Webception' => dirname(__FILE__) .'/../../codeception.yml'

),

/*
Expand Down Expand Up @@ -63,6 +64,7 @@
'CodeGuy.php',
'_bootstrap.php',
'.DS_Store',
'_steps',
),

/*
Expand Down
85 changes: 71 additions & 14 deletions App/Lib/Codeception.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ public function loadConfig($path, $file)
realpath($path . $test_path) : $path . $test_path;
}

$config['env'] = array();

if (isset($this->config['tests'])) {
foreach ($this->config['tests'] as $type => $active) {

if (! $active)
break;

if ($suite = \Symfony\Component\Yaml\Yaml::parse($config['paths']['tests'] . "/$type.suite.yml")) {
if (isset($suite['env'])) {
$config['env'][$type] = array_keys($suite['env']);
}
}
}
}

return $config;
}

Expand All @@ -130,16 +146,29 @@ public function loadTests()
if (! $active)
break;

$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator("{$this->config['paths']['tests']}/{$type}/", \FilesystemIterator::SKIP_DOTS),
$testdir = $this->config['paths']['tests'].DIRECTORY_SEPARATOR.$type.DIRECTORY_SEPARATOR;

if (!is_dir($testdir)) {
// If no directory exists for the test type, continue
continue;
}

$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($testdir, \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::SELF_FIRST
);

// Iterate through all the files, and filter out
// any files that are in the ignore list.

foreach ($files as $file) {

if (! in_array($file->getFilename(), $this->config['ignore'])
$pathMatch=false;
foreach($this->config['ignore'] as $k=>$ignorePattern) {
if (strpos($file->getPathname(),$ignorePattern)!==false) {
$pathMatch=true;
}
}
if (!$pathMatch && !in_array($file->getFilename(), $this->config['ignore'])
&& $file->isFile())
{
// Declare a new test and add it to the list.
Expand Down Expand Up @@ -209,8 +238,10 @@ public function getTestTally()
*/
public function run(Test $test)
{
$env = $this->getEnvironments($test->getType());

// Get the full command path to run the test.
$command = $this->getCommandPath($test->getType(), $test->getFilename());
$command = $this->getCommandPath($test->getType(), $test->getFilename(), $env);

// Attempt to set the correct writes to Codeceptions Log path.
@chmod($this->getLogPath(), 0777);
Expand All @@ -225,6 +256,26 @@ public function run(Test $test)
return $test;
}

public function getEnvironments($type)
{
$env = array();
if (isset($_GET['env'])) {

foreach(explode(' ', $_GET['env']) as $value){
if ($value) {

$value = str_replace($type . '_', '', $value);
if (isset($this->config['env'][$type]) && in_array($value, $this->config['env'][$type])) {
$env[] = '--env=' . $value;
}

}
}
}

return $env;
}

/**
* Get the Codeception log path
*
Expand All @@ -242,17 +293,22 @@ public function getLogPath()
* @param string $filename Name of the Test
* @return string Full command to execute Codeception with requred parameters.
*/
public function getCommandPath($type, $filename)
public function getCommandPath($type, $filename, $env)
{
// Build all the different parameters as part of the console command
$params = array(
$this->config['executable'], // Codeception Executable
"run", // Command to Codeception
"--no-colors", // Forcing Codeception to not use colors, if enabled in codeception.yml
"--config=\"{$this->site->getConfig()}\"", // Full path & file of Codeception
$type, // Test Type (Acceptance, Unit, Functional)
$filename, // Filename of the Codeception test
"2>&1" // Added to force output of running executable to be streamed out
$params = array_merge(
array(
$this->config['executable'], // Codeception Executable
"run", // Command to Codeception
"--no-colors", // Forcing Codeception to not use colors, if enabled in codeception.yml
"--config=\"{$this->site->getConfig()}\"", // Full path & file of Codeception
),
$env,
array(
$type, // Test Type (Acceptance, Unit, Functional)
$filename, // Filename of the Codeception test
"2>&1" // Added to force output of running executable to be streamed out
)
);

// Build the command to be run.
Expand Down Expand Up @@ -295,6 +351,7 @@ public function getRunResponse($type, $hash)
$response['passed'] = $test->passed();
$response['state'] = $test->getState();
$response['title'] = $test->getTitle();
$response['outputurl'] = "<a href='#' >".$test->getTitle()."</a>";
}

return $response;
Expand Down
2 changes: 1 addition & 1 deletion App/Lib/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function __construct()
public function init($type, $file)
{
$filename = $this->filterFileName($file->getFileName());
$posTypePath = strpos($file->getPathname(), "/{$type}/") + strlen("/{$type}/");
$posTypePath = strpos($file->getPathname(), DIRECTORY_SEPARATOR.$type.DIRECTORY_SEPARATOR) + strlen(DIRECTORY_SEPARATOR.$type.DIRECTORY_SEPARATOR);

$this->hash = $this->makeHash($type . $filename);
$this->title = $this->filterTitle($filename);
Expand Down
Loading