8. THAT'S A GOOD THING!
Unit testing got "normal" in PHP
Even people that don't really know PHP or even the CLI know that they
should write unit tests.
10. CURRENT STATE
Version: 3.6.12
Over 60 contributors since 3.6.0
Deep into the 3.6 Bugfix cycle, no new features will be added. Those
go into .next
French docs thanks to @poum and still current Japanese docs thanks
to @m-takagi!
If you want to help out:
https://github.com/sebastianbergmann/phpunit/#contributing
11. PHPUNIT.NEXT
Next up: 3.7
15+ features
10+ issues fixed
Details later
13. BC FREE-ISH
We are trying really hard to not introduce any BC breaks.
Test listeners trigger one autoload call
cwd gets restored after test case
parameter cloning behavior
Removed deprecated OutputTestCase
and that's it
15. BDD
Use Behat, It's great!
We're not going to remove the BDD stuff in PHPUnit but It's not being
worked on.
16. WEB INTERFACE?
Not sure why you'd want that but someone solved that for you
https://github.com/NSinopoli/VisualPHPUnit
17. MOCKING IS UGLY!
Real world problems and solutions:
http://stackoverflow.com/search?tab=votes&q=[phpunit] mock
18. MOCKERY
Try it! It's great.
Afraid it might be hard to set up and use?
Look into https://github.com/etsy/phpunit-extensions/wiki/Mockery
Works with strict mode, leaves the old API intact and is as easy as
writing a comment:
casMTs etnsPPntEtnin_okr_etae{
ls yet xed HUi_xesosMceyTsCs
/*@okr Fo*
* mcey o /
poetd$o;
rtce fo
}
19. LOTS OF LEGACY CODE?
Or whatever "hard to test" is called these days.
https://github.com/lapistano/proxy-object
One of the main purpose of this library is to expose invisible (private or
protected) methods and properties to the SUT.
20. TESTING WEB SERVICES
Unit and Integration test web services with the same code?
Try wsUnit https://github.com/lapistano/wsunit
21. IDE SUPPORT
Netbeans support improved and they adopted the skeleton-
generator
Honestly I have no clue about eclipse
PHPStorm has really beautiful coverage support by now
vim user? : p p n t - c v r g - e t
!hui -oeaetx
23. TRAVIS CI
Awesome for GitHub and collaboration
has the way to run their tests documented by now
No really CI but a very cool test runner
Use --coverage-text if you want to show off :)
24. COMPOSER
Last week:
When someone does the work it it will happen
This week:
Someone did.
Current status at
https://github.com/sebastianbergmann/phpunit/issues/522
25.
26. PHAR
The PHP tool format
We still have issues with process-isolation and figuring out the nicest
way to maintain and build the phars.
Hopefully the 3.7 alpha will also feature a 3.6 & 3.7 phar.
27. PHPUNIT-SELENIUM
Now maintained by @giorgiosironi
Code coverage support
If you ask me: Don't drive your web tests with phpunit.
Use Behat or something non php.
29. @ BLOCK
When using process-isolation PHPUnit won't die silently when
unserializing of the test result fails.
30. CLI ARGUMENT PARSING
ppntTsATsAppTsBTsBpp
hui et et.h et et.h
This only executed TestA. Now it gives you an error message that you
are doing it wrong.
31. HEY, LISTEN!
Test listeners now trigger one autoload call instead of being silently
ignored when the class was not loaded.
32. EXCEPTIONAL
Improved reporting of exceptions...
pbi fnto tsNseEcpin(
ulc ucin etetdxetos)
{
$3=nwEcpin'he';
e e xeto(Tre)
$2=nwIvldruetxeto(To,0 $3;
e e naiAgmnEcpin'w' , e)
$1=nwEcpin'n' 0 $2;
e e xeto(Oe, , e)
trw$1
ho e;
}
because it only told you...
EcpintcTs:tsNseEcpin
xetoSaket:etetdxetos
Ecpin Oe
xeto: n
[rc]
tae
but now...
33. EXCEPTIONAL
...we are printing out the previous exception names, messages and
traces.
EcpintcTs:tsNseEcpin
xetoSaket:etetdxetos
Ecpin Oe
xeto: n
[rc]
tae
Cue b
asd y
Ivldruetxeto:To
naiAgmnEcpin w
[rc]
tae
Cue b
asd y
Ecpin Tre
xeto: he
[rc]
tae
36. ONE MORE THING
Ftlerr Ucuh ecpin'HUi_rmwr_xeto'wt msae'e
aa ro: nagt xeto PPntFaeokEcpin ih esg Ni
te "et.h"nr"et.h"cudb oee. i ..
hr tsspp o tsspp ol e pnd' n .
That one is still alive. Sorry ;)
It just means that PHPUnit can't find any tests.
41. PROCESS ISOLATION FOR EVERYONE
Process Isolation did not work when PHPUnit is invoked through
Apache Ant, for instance, due to PHP binary detection issues.
43. BINARY MESS
Before it broke your terminal and BEEPed at you
1 Foet:eto
) oTs:tsFo
Fie asrigta tosrnsaeeul
ald setn ht w tig r qa.
--Epce
- xetd
++Ata
+ cul
@ @
@ @
-
+☺♥☻♦
+♀
♂
+☼◄‼§↨↓←↔▼
♫►↕¶▬↑→∟▲
Now it shows a hex dump:
Bnr Srn:0000000.....
iay tig x012345....
45. COUNTING ON IT
Now working with Countable and Iterator Interfaces:
assertCount()
assertAttributeCount()
assertNotCount()
assertAttributeNotCount()
assertSameSize()
assertNotSameSize()
46. FLUENT INTERFACES
A little mock improvement:
-wl(ti-rtrSl()
>il$hs>eunef);
51. LESS MAGIC NUMBERS
@expectedException* now works with constants:
/*
*
*@xetdxeto Cas
epceEcpin ls
*@xetdxetoCd @ls:TAO_ISN
epceEcpinoe Cas:EPTMSIG
*@xetdxetoMsae@ls:TAO_ISN_ESG
epceEcpinesg Cas:EPTMSIGMSAE
*/
Reduce copy paste testing.
52. *TEST.PHP IS TOO MAINSTREAM
Added --test-suffix that allows specifying which filename suffixes are
recognised by PHPUnit.
Helps out some projects with their CI.
I don't see a general use case.
53. {"JSON": "YES PLEASE"}
We added assertJson* functions that work like the existing assertXml*
functions.
asrJoFlEulJoFl(
setsnieqassnie)
asrJoSrnEulJoFl(
setsntigqassnie)
asrJoSrnEulJoSrn(
setsntigqassntig)
54. CALLBACK MATCHER
Helps with complex assertions on mocks
pbi fnto sn(msae EdonCni $ofg
ulc ucin ed$esg, npitofg cni)
It's not pretty but it might solve that one annoying problem:
$o-epcs$hs>ne)
fo>xet(ti-oc()
-mto(sn'
>ehd'ed)
-wt(
>ih
$hs>qaT(sn)
ti-eulo'y',
$hs>alak
ti-clbc(
fnto (cni){
ucin $ofg
$r =$ofg>eUl)
ul cni-gtr(;
i($r){trwnwEcpin'..) }
f!ul ho e xeto(..';
rtr $r-gtot)=='tp/eapecm;
eun ul>eHs( = ht:/xml.o'
}
)
);
61. LISTS AND COLLECTIONS
pbi fnto tsAsrCnanOlIsacsf)
ulc ucin etsetotisnyntneO(
{
$irr =ary
lbay ra(
nwBo(,
e ok)
nwBo(
e ok)
);
$hs>setotisnyntneO(
ti-asrCnanOlIsacsf
'ok,
Bo'
$irr
lbay
);
}
Helper for checking Collection objects and arrays.
Descriptive assertion and error message.
62. FAILED @EXPECTEDEXCEPTION ANNOTATIONS
Before:
Fie asrigta ecpino tp "roEcpin mthsepce ecp
ald setn ht xeto f ye Errxeto" ace xetd xe
to "yxeto"
in MEcpin.
Now:
Fie asrigta ecpino tp "roEcpin mthsepce ecp
ald setn ht xeto f ye Errxeto" ace xetd xe
to "yxeto"
in MEcpin.
Msaefo "roEcpin ws"neie vral $ts.
esg rm Errxeto" a udfnd aibe hi"
63. LESS REQUIRES, LESS CRASHES
<htls adnoeeFlsrmhtls=tu"
wieit dUcvrdieFoWieit"re>
People seem to constantly run into issues with code coverage
<htls poesnoeeFlsrmhtls=tu"
wieit rcsUcvrdieFoWieit"re>
When enabled, uncovered whitelisted files are processed to properly
calculate the number of executable lines.
If not we take a quite ok guess to get the number of ELOC.
64. MORE USEFUL GROUPS
$ppnt-gopFayet
hui -ru lkTss
<hui>
ppnt
<rus
gop>
<xld>
ecue
<ru>lkTss/ru>
gopFayet<gop
<ecue
/xld>
<gop>
/rus
<etuts../
tssie . >
<ppnt
/hui>
Now works as expected
69. SMALL HINTS
Use the xml configuration for pretty much everything
Separate unit and integration tests
Your unit test folders should mirror your applications folder
structure
To only execute specific tests use phpunit --filter or phpunit
tests/unit/module1
Use the strict mode from the get go and never turn it off.
Imho: Don't have a test namespace. Nicer to read and shows
production usage.
70. DISCUSSION
Issues?
Feature requests?
Anything I missed?