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
20 changes: 15 additions & 5 deletions App/Lib/Codeception.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function loadConfig($path, $file)
if (! $active)
break;

if ($suite = \Symfony\Component\Yaml\Yaml::parse($config['paths']['tests'] . "/$type.suite.yml")) {
if ($suite = \Symfony\Component\Yaml\Yaml::parse(file_get_contents($config['paths']['tests'] . "/$type.suite.yml"))) {
if (isset($suite['env'])) {
$config['env'][$type] = array_keys($suite['env']);
}
Expand Down Expand Up @@ -162,10 +162,20 @@ public function loadTests()
&& $file->isFile())
{
// Declare a new test and add it to the list.
$test = new Test();
$test->init($type, $file);
$this->addTest($test);
unset($test);
if (preg_match('/Cest.php/', $file->getFilename())) {
$tests = Test::getAllTests($file);
foreach ($tests as $tcInfo) {
$test = new Test();
$test->cestInit($type, $file, $tcInfo);
$this->addTest($test);
unset($test);
}
} else {
$test = new Test();
$test->init($type, $file);
$this->addTest($test);
unset($test);
}
}

}
Expand Down
36 changes: 36 additions & 0 deletions App/Lib/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ public function init($type, $file)
$this->state = self::STATE_READY; // Not used yet.
}

public function cestInit($type, $file, $test)
{
$testName = $this->filterFileName($test['testName']);
$posTypePath = strpos($file->getPathname(), DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR)
+ strlen(DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR);

$this->hash = $this->makeHash($type . $testName);
$this->title = $this->filterTitle($testName);
$this->filename = substr($file->getPathname(), $posTypePath).':'.$test['methodName'];
$this->file = $file;
$this->type = $type;
$this->state = self::STATE_READY; // Not used yet.
}

/**
* Filter out content from a title any to improve readability of the test name
*
Expand Down Expand Up @@ -354,4 +368,26 @@ public function reset()
$this->log = array();
$this->passed = FALSE;
}

public static function getAllTests($file)
{
$dump = file_get_contents($file->getPathname());

$functionFinderRegex = '/public.+[\s\n]([^_]\S+)[\s\n]*\(/';
$functionArray = array();
$tests = array();

preg_match_all($functionFinderRegex, $dump , $functionArray);

if( count( $functionArray ) > 1 ) {
$functionArray = $functionArray[1];
}

foreach ($functionArray as $function) {
$test['methodName'] = $function;
$test['testName'] = $file->getFileName().":".camel_to_sentance($function);
$tests [] = $test;
}
return $tests;
}
}
2 changes: 1 addition & 1 deletion composer.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"slim/views": "0.1.*",
"twig/twig": "~1.13",
"codeception/codeception": "2.*",
"symfony/yaml": "2.5.x-dev"
"monolog/monolog": "*"
},
"autoload": {
"psr-0": {
Expand Down