function __construct($_sFeaturePath, $_iPort = 16816) { openlog("cuke4php", LOG_PID, LOG_DAEMON); if (is_file($_sFeaturePath)) { $_sFeaturePath = dirname($_sFeaturePath); } if ($_iPort > 0) { $this->iPort = $_iPort; } else { $this->iPort = 16816; } foreach (self::rglob("*.php", 0, $_sFeaturePath . "/support") as $sFilename) { require_once $sFilename; } set_error_handler(array('PHPUnit_Util_ErrorHandler', 'handleError'), E_ALL | E_STRICT); require_once "Cucumber.php"; foreach (self::rglob("*.php", 0, $_sFeaturePath . "/step_definitions") as $sFilename) { require_once $sFilename; } $this->aStepClasses = CucumberSteps::getSubclasses(); foreach ($this->aStepClasses as $sClass) { $oReflection = new ReflectionClass($sClass); $aMethods = $oReflection->getMethods(); foreach ($aMethods as $oMethod) { $sComment = $oMethod->getDocComment(); $aMatches = array(); $aMethod = array(); $aMethod['method'] = $oMethod->name; $aMethod['class'] = $oMethod->class; $aMethod['filename'] = $oMethod->getFileName(); $aMethod['startline'] = $oMethod->getStartLine(); if (substr($oMethod->name, 0, 4) === "step") { preg_match("/(?:Given|When|Then) (.+)\$/im", $sComment, $aMatches); $aMethod['regexp'] = $aMatches[1]; $this->aWorld['steps'][] = $aMethod; continue; } preg_match("/(@.+)/im", $sComment, $aMatches); if (array_key_exists(1, $aMatches)) { $aMethod['tags'] = explode(" ", str_replace("@", "", $aMatches[1])); } else { $aMethod['tags'] = array(); } if (substr($oMethod->name, 0, 6) === "before") { $this->aWorld['before'][] = $aMethod; continue; } if (substr($oMethod->name, 0, 5) === "after") { $this->aWorld['after'][] = $aMethod; continue; } if (substr($oMethod->name, 0, 9) == "transform") { preg_match("/(?:Transform) (.+)\$/im", $sComment, $aMatches); $aMethod['regexp'] = $aMatches[1]; $this->aWorld['transform'][] = $aMethod; continue; } } } }
static function clearMocks() { self::$aMocks = array(); }
public function testShouldRunAfterHooksWithNoTags() { $this->oMockHook->expects(self::once())->method('afterWithNoTags'); CucumberSteps::setMock('TestSteps', $this->oMockHook); self::assertEquals(array('success'), $this->oScenario->invokeAfterHooks(array())); }
/** * @param $aTags * @return array * invoke all after hooks defined that either have no tags, or tags that match the tags of the current scenario */ function invokeAfterHooks($aTags) { if (is_null($aTags)) { $aTags = array(); } foreach ($this->aWorld['after'] as $aAfterHook) { if (array_key_exists('tags', $aAfterHook)) { if (count($aAfterHook['tags']) == 0 || count(array_intersect($aTags, $aAfterHook['tags'])) > 0) { $oStep = CucumberSteps::getInstance($aAfterHook['class'], $this->aGlobals); syslog(LOG_DEBUG, "Invoking After Hook \"{$aAfterHook['method']}\""); $oResult = $oStep->invoke($aAfterHook['method']); if ($oResult === false) { return array('failure'); } } } } return array('success'); }