Skip to content

Commit

Permalink
should keyword for PHPUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien committed Mar 27, 2014
1 parent 5ddce0c commit ea3fc4e
Showing 1 changed file with 49 additions and 16 deletions.
65 changes: 49 additions & 16 deletions src/sbp/sbp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)#', '<?php', $content);
$content = static::replace($content, array(
self::SUBST => self::SUBST.self::SUBST,
'#<\?(?!php)#' => '<?php',
));

$content = preg_replace('#^(\s*<\?php)(\s)#', '$1 '.self::COMMENT.(is_null(static::$lastParsedFile) ? '' : '/*:'.static::$lastParsedFile.':*/').'$2', $content, 1, $count);

$content = static::replace($content, array(

/***********/
/* PHPUnit */
/***********/
'#^(\s*)(.+\s)?should\s+not\s(.+);\s*$#m'
=> function ($match)
{
list($all, $spaces, $before, $after) = $match;
return $spaces . '>assertFalse(' . $before . preg_replace('#(?<![a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff$])be(?![a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff])#', 'is', $after) . ', ' . var_export(trim($all), true) . ');';
},

'#^(\s*)(.+\s)?should\s(.+);\s*$#m'
=> function ($match)
{
list($all, $spaces, $before, $after) = $match;
return $spaces . '>assertTrue(' . $before . preg_replace('#(?<![a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff$])be(?![a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff])#', 'is', $after) . ', ' . var_export(trim($all), true) . ');';
},
));

$content = preg_replace_callback('#'.self::COMMENTS.'|'.self::stringRegex().'|\?'.'>.*<\?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)
{
Expand All @@ -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 = '<?php '.self::COMMENT.' ?>'.$content;
}
foreach(array(

$content = static::replace($content, array(
/*********/
/* Class */
/*********/
Expand Down Expand Up @@ -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])#'
'#(?<![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])#'
'#(?<![a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff$]|::|->)__DIR(?![a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff])#'
=> $__dir,


Expand Down Expand Up @@ -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 = '';
Expand Down

0 comments on commit ea3fc4e

Please sign in to comment.