5. What
is
quality
assurance?
• safeguarding
source
code
• applica$on
behaves
as
expected
• bugs
discovered
before
becoming
an
issue
• tracking
progress
of
a
project
-‐ development
of
features
-‐ health
of
the
codebase
5
6. Why
invest
in
QA?
• improving
development
code
• improving
development
team
• saving
$me
in
aJer
sales
maintenance
• con$nuous
repor$ng
• ready
to
deploy
code
(“builds”)
6
9. PHP
Lint
TIP:
pre-‐commit
hook
• checks
the
syntax
of
code
• build
in
PHP
core
• is
used
per
file
-‐ pre-‐commit
hook
for
version
control
system
-‐ batch
processing
of
files
• can
provide
reports
-‐ but
if
something
fails
-‐>
the
build
fails
9
14. PHPUnit
• tes$ng
framework
for
PHP
projects
• port
of
xUnit
unit
test
frameworks
-‐ compa$ble
with
JUnit,
NUnit,
etc...
• produces
generic
test
results
-‐ compa$ble
with
the
other
xUnit
frameworks
• produces
code
coverage
reports
-‐ to
indicate
what
part
of
code
is
tested
14
21. PHP_CodeSniffer
• checks
source
code
on
coding
standards
• reports
viola$ons
on
a
given
standard
• ensures
a
consistent
way
code
is
wriPen
-‐ as
though
one
developer
wrote
all
the
code
21
22. Report
types
• full:
all
details
of
viola$ons
• summary:
total
of
errors
and
warnings
• source:
targeted
sources
with
viola$ons
• xml:
a
full
report
in
XML
format
• checkstyle:
XML
report
on
style
viola$ons
• csv:
a
full
report
in
CSV
format
• emacs:
a
full
report
in
EMACS
format
• blame:
a
list
of
responsible
viola$ng
devs
22
23. Example
Full
report
FILE: /path/to/file.php
-------------------------------------------------------------------------------
FOUND 2 ERROR(S) AND 4 WARNING(S) AFFECTING 4 LINE(S)
-------------------------------------------------------------------------------
111 | ERROR | Arguments with default values must be at the end of the
| | argument list
111 | WARNING | Line exceeds 80 characters; contains 88 characters
118 | WARNING | Line exceeds 80 characters; contains 89 characters
121 | WARNING | Line exceeds 80 characters; contains 84 characters
130 | WARNING | Line exceeds 80 characters; contains 94 characters
176 | ERROR | Spaces must be used to indent lines; tabs are not allowed
-------------------------------------------------------------------------------
23
24. Example
Summary
report
PHP CODE SNIFFER REPORT SUMMARY
--------------------------------------------------------------------------------
FILE ERRORS WARNINGS
--------------------------------------------------------------------------------
/path/to/file.php 1 4
--------------------------------------------------------------------------------
A TOTAL OF 1 ERROR(S) AND 4 WARNING(S) WERE FOUND IN 1 FILE(S)
--------------------------------------------------------------------------------
24
25. Example
Source
report
PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
--------------------------------------------------------------------------------
STANDARD CATEGORY SNIFF COUNT
--------------------------------------------------------------------------------
Generic Files Line length too long 4
PEAR Functions Valid default value not at end 1
--------------------------------------------------------------------------------
A TOTAL OF 5 SNIFF VIOLATION(S) WERE FOUND IN 2 SOURCE(S)
--------------------------------------------------------------------------------
Although specified Zend as coding standard, there’s a relation to
underlying standards like PEAR and the General coding standards
25
26. Example
XML
report
<?xml version="1.0" encoding="UTF-8"?>
<phpcs version="1.3.0">
<file name="/path/to/file.php" errors="1" warnings="4">
<error line="111" column="83"
source="PEAR.Functions.ValidDefaultValue.NotAtEnd" s
everity="5">Arguments with default values must be at the end of the argument
list</error>
<warning line="111" column="89"
source="Generic.Files.LineLength.TooLong"
severity="5">Line exceeds 80 characters; contains 88 characters</warning>
<warning line="118" column="90"
source="Generic.Files.LineLength.TooLong"
severity="5">Line exceeds 80 characters; contains 89 characters</warning>
<warning line="121" column="85"
source="Generic.Files.LineLength.TooLong"
severity="5">Line exceeds 80 characters; contains 84 characters</warning>
<warning line="130" column="95"
source="Generic.Files.LineLength.TooLong"
severity="5">Line exceeds 80 characters; contains 94 characters</warning>
</file>
</phpcs>
26
27. Example
CheckStyle
report
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="1.3.0">
<file name="/path/to/file.php">
<error line="111" column="83" severity="error"
message="Arguments with default values must be at the end of the argument list"
source="PEAR.Functions.ValidDefaultValue.NotAtEnd"/>
<error line="111" column="89" severity="warning"
message="Line exceeds 80 characters; contains 88 characters"
source="Generic.Files.LineLength.TooLong"/>
<error line="118" column="90" severity="warning"
message="Line exceeds 80 characters; contains 89 characters"
source="Generic.Files.LineLength.TooLong"/>
<error line="121" column="85" severity="warning"
message="Line exceeds 80 characters; contains 84 characters"
source="Generic.Files.LineLength.TooLong"/>
<error line="130" column="95" severity="warning"
message="Line exceeds 80 characters; contains 94 characters"
source="Generic.Files.LineLength.TooLong"/>
</file>
</checkstyle>
27
28. Example
CSV
report
File,Line,Column,Type,Message,Source,Severity
"/path/to/file.php",111,83,error,"Arguments with default values must be at the end
of the argument list",PEAR.Functions.ValidDefaultValue.NotAtEnd,5
"/path/to/file.php",111,89,warning,"Line exceeds 80 characters; contains 88
characters",Generic.Files.LineLength.TooLong,5
"/path/to/file.php",118,90,warning,"Line exceeds 80 characters; contains 89
characters",Generic.Files.LineLength.TooLong,5
"/path/to/file.php",121,85,warning,"Line exceeds 80 characters; contains 84
characters",Generic.Files.LineLength.TooLong,5
"/path/to/file.php",130,95,warning,"Line exceeds 80 characters; contains 94
characters",Generic.Files.LineLength.TooLong,5
28
29. Example
Blame
report
PHP CODE SNIFFER SVN BLAME SUMMARY
--------------------------------------------------------------------------------
AUTHOR (Author %) (Overall %) COUNT
--------------------------------------------------------------------------------
michelangelo (2.26) (100) 5
--------------------------------------------------------------------------------
A TOTAL OF 5 SNIFF VIOLATION(S) WERE COMMITTED BY 1 AUTHOR(S)
--------------------------------------------------------------------------------
29
37. • CYCLO:
Cycloma$c
Complexity
• LOC:
Lines
of
Code
• NOM:
Number
of
Methods
• NOC:
Number
of
Classes
• NOP:
Number
of
Packages
• AHH:
Average
Hierarchy
Height
• ANDC:
Average
Number
of
Derived
Classes
• FANOUT:
Number
of
Called
Classes
• CALLS:
Number
of
Opera$on
Calls
37
38. Cycloma$c
Complexity
• metric
calcula$on
• execu$on
paths
• independent
control
structures
-‐ if,
else,
for,
foreach,
switch
case,
while,
do,
…
• within
a
single
method
or
func$on
• more
info
-‐ hPp://en.wikipedia.org/wiki/Cycloma$c_complexity
38
52. Lines
of
Code
• calculates
the
size
of
a
project
-‐ gives
a
brief
detail
on
quality
of
source
code
-‐ comparable
to
sumaries
of
‣ phpcs
‣ phpmd
‣ pdepend
52
56. Phing’s
purpose
• build
tool
wriPen
in
PHP
-‐ comparable
to
Ant
or
make
• used
to
automate
build
process
-‐ build
=
all
steps
to
produce
reports
• provides
targets
and
variable
proper$es
-‐ for
targeted
execu$on
of
tools
(e.g.
only
unit
tes$ng)
56
58. Loca$on
of
build
reports
/path/to/project
/application
/library
/public
/tests
/build
/api -> location for API documentation
/cache -> used by CI for caching
/code-browser -> browsable source code
/coverage -> unit test code coverage
/logs -> location for all report logs
/junit.xml
/jdepend.xml
/pmd.xml
/pmd-cpd.xml
/phploc.csv
/checkstyle.xml
/pdepend -> dependency graphics and pyramid
58
60. Ini$al
Phing
build
script
<?xml version=”1.0” encoding=”UTF-8”?>
<!--
$Id: jenkins.xml 123 2011-06-08 07:00:00Z michelangelo $
-->
<project name=”My Project” default=”build”>
<!--
a property file (key/value) to store project specific data
like paths, property values and passwords
-->
<property file=”jenkins.properties” />
<!--
list of targets, each with their own php tool
-->
</project>
60
75. phing
usage
• developers
can
run
at
call
-‐ all
targets
-‐ specific
targets
(like
unit
tests,
style
checking,
…)
• unified
way
of
execu$ng
processes
75
78. Con$nuous
Integra$on?
• automated
process
• tools
for
code
-‐ test
-‐ document
-‐ validate
-‐ package
• triggered
-‐ by
code
change
in
version
control
system
-‐ on
fixed
intervals
(e.g.
every
weekday
at
1am)
78
113. With
CI
• con$nuous
inspec$on
of
code
-‐ errors
are
detected
early
-‐ warnings
are
reported
-‐ areas
of
improvement
are
pointed
out
113
114. CI
&
PHP
• all
the
tools
-‐ to
improve
development
skills
-‐ to
deliver
quality
code
-‐ to
detect
issues
early
-‐ to
document
and
analyze
code
base
114