Created
August 12, 2015 19:52
-
-
Save raharper/ee431e851b1b8bb6ba1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cleanup() { | |
rm -f $TESTPHP | |
rm -f $CLASSPHP | |
} | |
trap cleanup EXIT INT HUP TERM | |
echo "Generating php5 test-case..." | |
TESTPHP=`mktemp /tmp/test_phpinsteadof_XXXX.php` | |
CLASSPHP=`mktemp /tmp/test_phpinsteadof_XXXX.php` | |
# manual testing shows 12 or more to be the trigger | |
NR_TRAITS=${1-12} | |
cat > $TESTPHP << EOF | |
#!/usr/bin/php -q | |
<?php | |
\$i = ${NR_TRAITS}; | |
while (\$i--) { | |
eval('class c' . \$i . ' {}'); | |
} | |
require_once("$CLASSPHP"); | |
die("End\n"); | |
EOF | |
TRAIT_DEFS="" | |
for ((x=0; x<$NR_TRAITS; x++)); do | |
TRAIT="trait trait${x} { public function methodName() {} }\n" | |
TRAIT_DEFS="${TRAIT_DEFS}${TRAIT}" | |
done | |
TRAIT_DEFS=`echo -e $TRAIT_DEFS`; | |
TRAITS="" | |
INSTEAD_OF="" | |
for ((x=1; x<$NR_TRAITS; x++)); do | |
TRAIT=" trait${x}" | |
INSTEAD=" trait0::methodName insteadof trait${x};\n" | |
if (($x + 1 == $NR_TRAITS)); then | |
TRAITS="${TRAITS}${TRAIT}\n" | |
else | |
TRAITS="${TRAITS}${TRAIT},\n" | |
fi | |
INSTEAD_OF="${INSTEAD_OF}${INSTEAD}" | |
done | |
TRAITS=`echo -e $TRAITS`; | |
INSTEAD_OF=`echo -e $INSTEAD_OF` | |
cat > $CLASSPHP << EOF | |
<?php | |
namespace SPACE; | |
${TRAIT_DEFS} | |
class c { | |
use trait0, | |
${TRAITS} | |
{ | |
${INSTEAD_OF} | |
} | |
} | |
EOF | |
chmod +x $TESTPHP | |
echo "Running php5 insteadof test-case..." | |
exec $TESTPHP | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment