diff --git a/App/Lib/Codeception.php b/App/Lib/Codeception.php index 811f0af..29e8854 100644 --- a/App/Lib/Codeception.php +++ b/App/Lib/Codeception.php @@ -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']); } @@ -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); + } } } diff --git a/App/Lib/Test.php b/App/Lib/Test.php index d53a289..2e66d83 100644 --- a/App/Lib/Test.php +++ b/App/Lib/Test.php @@ -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 * @@ -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; + } } diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index 6ab0955..9cbeec4 --- a/composer.json +++ b/composer.json @@ -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": {