The focus of the presentation is on organizing your PHP app build process, employing continuous testing, JS testing, automatic documentation, software metrics and other tools. The end result is expected to be a more stable, reliable, documented and healthy code base.
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
DEPLOY PHP APPLICATIONS SAFELY, EFFICIENTLY AND FREQUENTLY
1. HOW TO DEPLOY PHP APPLICATIONS
SAFELY, EFFICIENTLY, AND FREQUENTLY
WITHOUT LOOSING YOUR SANITY (COMPLETELY)
Created by Mihail Irintchev
Head of Software Development
SiteGround.com Web Hosting Co.
/m.irintchev@siteground.com @irintchev
2. ABOUT ME
Name: Mihail Irintchev (Mike)
From Sofia, Bulgaria
Web developer since 2003
Work @ SiteGround
Organizing @bgphp UG
Love beer
7. OVERVIEW OF BUILD ESSENTIALS:
Revision control system
Continuous testing
Continuous integration
Staging environment
Automatic documentation
Code health metrics
Deployment mechanism
... and you want all that plus more wrapped in ...
AN AUTOMATED BUILD PROCEDURE!
13. WHAT CAN THE VERSION CONTROL
DO FOR YOU?
(APART FROM STORING AND VERSIONING YOUR CODE)
pre-commit and post-commit hooks
14. WHAT IS PRE-COMMIT GOOD FOR?
PREVENT PEOPLE FROM COMMITTING BAD CODE
Run php lint (php -l) on the newly committed code
for i in `$SVNLOOK changed -t "$TXN" "$REPOS" | $AWK '{print $2}'`
do
if [[ $i =~ ".php$" ]]; then
# Run php lint to make sure no code with parse errors is committed
CHECK=`$SVNLOOK cat -t "$TXN" "$REPOS" $i | $PHP -d html_errors=off -l || echo $i`
RETURN=`echo $CHECK | $GREP "^No syntax" > /dev/null && echo TRUE || echo FALSE`
if [ $RETURN = 'FALSE' ]; then
echo $CHECK 1>&2;
exit 1
fi
fi
done
16. PREVENT SOME FOOLISH MISTAKES
... like dumping DB user and pass on your home page
... or embarass yourself by leaving some other
var_dump()/ print_r()/ var_export()behind
18. SO JUST ADD ANOTHER SECTION TO THE PRE-COMMIT HOOK
if [[ $i =~ ".php$" ]]; then
# ...
# Grep for var_dump/var_export/print_r (the last two without second param passed)
# to prevent code committed with debugging instructions to go into the repo
CHECK=`$SVNLOOK cat -t "$TXN" "$REPOS" $i |
$GREP -e "(var_dump[ t]*(|(var_export|print_r)[ t]*([^,)]+))" -m1 -c`
RETURN=`echo $CHECK | $GREP "1" > /dev/null && echo TRUE || echo FALSE`
if [ $RETURN = 'TRUE' ]; then
echo "var_dump/print_r/var_export found in $i" 1>&2;
exit 2
fi
# ...
fi
21. THERE ARE OTHER HOOKS AS WELL
SVN GIT
pre-lock
pre-unlock
post-lock
post-unlock
start-commit
pre-revprop-change
post-revprop-change
prepare-commit-msg
post-merge
pre-receive
post-receive
post-checkout
pre-applypatch
post-applypatch
23. WHAT DOES PHING STAND FOR?
PHing Is Not GNU make
“It's a PHP project build system or build tool
based on . You can do anything
with it that you could do with a traditional
build system like GNU make...”
Apache Ant
25. SERIOUSLY, WHY PHING?
Very flexible and robust build tool
Simple XML build file
Variety of built-in and optional tasks
Very easy to write your own custom task
Good and community
Platform independent
No required external dependencies
docs
26. VERY EASY INSTALLATION
Through PEAR:
$ pear channel-discover pear.phing.info
$ pear install [--alldeps] phing/phing
Through Composer:
{
"require-dev": {
"phing/phing": "2.*"
}
}
34. CODE METRICS TASKS
THE TOOLS?
phpmd
phpcpd
pdepend
phpcs
Guess what? There exist ready-made phing tasks for all of
them!
35. TASKS #5: PHPMD
Person behind: Manuel Pichler
<!-- ===================================================================== -->
<!-- Target: phpmd - a subtask that runs PHPMD on predefined dirs/files -->
<!-- and generates reports in the desired format -->
<!-- ===================================================================== -->
<target name="phpmd">
<phpmd rulesets="cleancode,design,unusedcode">
<fileset dir="${srcdir}">
<include name="classes/**/*.php" />
</fileset>
<formatter type="xml" outfile="${srcdir}/reports/pmd.xml"/>
</phpmd>
</target>
36. TASK #6: PHPCPD
Person behind: Sebastian Bergmann
<!-- ===================================================================== -->
<!-- Target: phpcpd - a subtask that runs PHPCPD on predefined dirs/files -->
<!-- and generates reports in the desired format -->
<!-- ===================================================================== -->
<target name="phpcpd">
<phpcpd>
<fileset dir="${srcdir}">
<include name="classes/**/*.php" />
</fileset>
<formatter type="pmd" outfile="${srcdir}/reports/pmd-cpd.xml"/>
</phpcpd>
</target>
37. TASK #7: PDEPEND
Person behind: Manuel Pichler
<!-- ===================================================================== -->
<!-- Target: pdepend - a subtask that runs pdepend on predefined dirs/files-->
<!-- and generates reports in the desired format -->
<!-- ===================================================================== -->
<target name="pdepend">
<phpdepend>
<fileset dir="${srcdir}">
<include name="classes/**/*.php" />
</fileset>
<logger type="jdepend-xml" outfile="${srcdir}/reports/pdepend.xml"/>
<logger type="jdepend-chart" outfile="${srcdir}/reports/pchart.svg"/>
<logger type="overview-pyramid" outfile="${srcdir}/reports/pyramid.svg"/>
<analyzer type="coderank-mode" value="method"/>
</phpdepend>
</target>
38. WHAT ELSE CAN YOU USE PHINGFOR?
Encrypting/obfuscating code before deployment
Generating static assets
Generate and deploy static sites with tools like sculpin
Execute post-deploy scripts
Pretty much anything useful around the build/deploy
39. TAKEAWAYS
There are a lot of things you can automate in a build
(strong emphasis on continuous testing & integration)
There are a lot of tools out there that can help you do that
phing is a very neat tool to organize your build process
40. CREDITS & REFERENCES
"Quality Assurance for PHP Projects" by Michelangelo van Dam
by Jordan Kasper"Browser Eyeballing != JavaScript Testing"
The PHP Quality Assurance Toolchain