Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created April 24, 2020 15:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter279k/e8ef7a1d412c7024b0cabf1da2d73a86 to your computer and use it in GitHub Desktop.
Save peter279k/e8ef7a1d412c7024b0cabf1da2d73a86 to your computer and use it in GitHub Desktop.
This is let PHPUnit fixtures convert to correct prefix methods.
#!/bin/bash
file_path=$1
if [[ ${file_path} == '' ]]; then
echo 'Please inut file_path'
exit 1;
fi;
if [[ -d $file_path ]]; then
echo ''
else
echo "${file_path} directory is not found..."
exit 1;
fi;
if [[ -d ${file_path}/tests/ ]]; then
echo ''
else
echo "${file_path}/tests directory is not found..."
exit 1;
fi;
echo "Start scanning ${file_path}/tests/...."
cd $file_path
setup_prefix='public function setUp()'
replaced_setup_prefix='protected function setUp()'
tear_down_prefix='public function tearDown()'
replaced_tear_down_prefix='protected function tearDown()'
setup_prefix_lists=$(grep -r "${setup_prefix}" ./tests/ | awk '{print $1}' | sed -e 's/://g')
tear_down_prefix_lists=$(grep -r "${tear_down_prefix}" ./tests/ | awk '{print $1}' | sed -e 's/://g')
for php_file_path in $setup_prefix_lists;
do
sed -i -e "s/${setup_prefix}/${replaced_setup_prefix}/g" $php_file_path
done;
for php_file_path in $tear_down_prefix_lists;
do
sed -i -e "s/${setup_prefix}/${replaced_tear_down_prefix}/g" $php_file_path
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment