From ea3fc4ef177fc48fde885301692e31a120278145 Mon Sep 17 00:00:00 2001 From: Bastien Date: Thu, 27 Mar 2014 16:15:37 +0100 Subject: [PATCH] should keyword for PHPUnit --- src/sbp/sbp.php | 65 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/src/sbp/sbp.php b/src/sbp/sbp.php index c5655e7..33543ca 100644 --- a/src/sbp/sbp.php +++ b/src/sbp/sbp.php @@ -286,15 +286,56 @@ static public function includeOnceFile($file) return include_once($phpFile); } + static protected function replace($content, $replace) + { + foreach($replace as $search => $replace) + { + $content = (is_callable($replace) ? + preg_replace_callback($search, $replace, $content) : + (substr($search, 0, 1) === '#' ? + preg_replace($search, $replace, $content) : + str_replace($search, $replace, $content) + ) + ); + } + return $content; + } + static public function parse($content) { $GLOBALS['replaceStrings'] = array(); $GLOBALS['commentStrings'] = array(); - $content = str_replace(self::SUBST, self::SUBST.self::SUBST, $content); - $content = preg_replace('#<\?(?!php)#', ' self::SUBST.self::SUBST, + '#<\?(?!php)#' => ' function ($match) + { + list($all, $spaces, $before, $after) = $match; + return $spaces . '>assertFalse(' . $before . preg_replace('#(? function ($match) + { + list($all, $spaces, $before, $after) = $match; + return $spaces . '>assertTrue(' . $before . preg_replace('#(?.*<\?php#sU', array(get_class(), 'replaceString'), $content); //$validsubst = self::validSubst(); + $validComments = self::validSubst('(?:'.implode('|', $GLOBALS['commentStrings']).')'); + $__file = is_null(static::$lastParsedFile) ? null : realpath(static::$lastParsedFile); if($__file === false) { @@ -303,12 +344,13 @@ static public function parse($content) $__dir = is_null($__file) ? null : dirname($__file); $__file = var_export($__file, true); $__dir = var_export($__dir, true); - $validComments = self::validSubst('(?:'.implode('|', $GLOBALS['commentStrings']).')'); + if(!$count) { $content = ''.$content; } - foreach(array( + + $content = static::replace($content, array( /*********/ /* Class */ /*********/ @@ -357,10 +399,10 @@ static public function parse($content) /************************/ /* Constantes spéciales */ /************************/ - '#(?!<[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff$]|::|->)__FILE(?![a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff])#' + '#(?)__FILE(?![a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff])#' => $__file, - '#(?!<[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff$]|::|->)__DIR(?![a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff])#' + '#(?)__DIR(?![a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff])#' => $__dir, @@ -497,16 +539,7 @@ static public function parse($content) '#\sgt\s#' => " > " - ) as $search => $replace) - { - $content = (is_array($replace) ? - preg_replace_callback($search, $replace, $content) : - (substr($search, 0, 1) === '#' ? - preg_replace($search, $replace, $content) : - str_replace($search, $replace, $content) - ) - ); - } + )); $content = explode("\n", $content); $curind = array(); $previousRead = '';