• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
The State of PHPUnit
 

The State of PHPUnit

on

  • 1,152 views

 

Statistics

Views

Total Views
1,152
Views on SlideShare
1,149
Embed Views
3

Actions

Likes
2
Downloads
4
Comments
0

2 Embeds 3

https://si0.twimg.com 2
http://www.techgig.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    The State of PHPUnit The State of PHPUnit Presentation Transcript

    • THE STATE OF PHPUNIT Volker Dusch / @__edorian
    • ABOUT MEPHP since 10 yearsCICleanCodeDevOpsTDDShipping
    • GET IN TOUCHstackoverflow:Twitter: @__edorianXing / G+: Volker DuschIRC: edorianMail: php@wallbash.com
    • LETS GO
    • Unit testing in PHP got mainstream
    • THATS A GOOD THING! Unit testing got "normal" in PHPEven people that dont really know PHP or even the CLI know that they should write unit tests.
    • AGENDACurrent StatePHPUnit.nextThe EcoSystemAnnoying things we got rid ofFeatures you might have missedUpcoming stuffTest suite organizationDiscussion
    • CURRENT STATEVersion: 3.6.12Over 60 contributors since 3.6.0Deep into the 3.6 Bugfix cycle, no new features will be added. Thosego into .nextFrench docs thanks to @poum and still current Japanese docs thanksto @m-takagi!If you want to help out:https://github.com/sebastianbergmann/phpunit/#contributing
    • PHPUNIT.NEXT Next up: 3.7 15+ features 10+ issues fixed Details later
    • BCDid you like upgrading to PHPUnit 3.6?
    • BC FREE-ISHWe 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 thats it
    • THE ECOSYSTEM http://phpqatools.org/ & friends
    • BDD Use Behat, Its great!Were not going to remove the BDD stuff in PHPUnit but Its not being worked on.
    • WEB INTERFACE?Not sure why youd want that but someone solved that for you https://github.com/NSinopoli/VisualPHPUnit
    • MOCKING IS UGLY! Real world problems and solutions:http://stackoverflow.com/search?tab=votes&q=[phpunit] mock
    • MOCKERY Try it! Its 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 }
    • LOTS OF LEGACY CODE? Or whatever "hard to test" is called these days. https://github.com/lapistano/proxy-objectOne of the main purpose of this library is to expose invisible (private or protected) methods and properties to the SUT.
    • TESTING WEB SERVICESUnit and Integration test web services with the same code? Try wsUnit https://github.com/lapistano/wsunit
    • IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user? : p p n t - c v r g - e t !hui -oeaetx
    • JENKINSJenkins template: jenkins-php.orgclover php plugin
    • TRAVIS CIAwesome for GitHub and collaboration has the way to run their tests documented by nowNo really CI but a very cool test runnerUse --coverage-text if you want to show off :)
    • COMPOSER Last week: When someone does the work it it will happen This week: Someone did. Current status athttps://github.com/sebastianbergmann/phpunit/issues/522
    • PHAR The PHP tool formatWe 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.
    • PHPUNIT-SELENIUM Now maintained by @giorgiosironi Code coverage supportIf you ask me: Dont drive your web tests with phpunit. Use Behat or something non php.
    • ANNOYING THINGS WE GOT RID OF
    • @ BLOCKWhen using process-isolation PHPUnit wont die silently when unserializing of the test result fails.
    • CLI ARGUMENT PARSING ppntTsATsAppTsBTsBpp hui et et.h et et.hThis only executed TestA. Now it gives you an error message that you are doing it wrong.
    • HEY, LISTEN!Test listeners now trigger one autoload call instead of being silently ignored when the class was not loaded.
    • EXCEPTIONAL Improved reporting of exceptions...pbi fnto tsNseEcpin( ulc ucin etetdxetos){ $3=nwEcpinhe; e e xeto(Tre) $2=nwIvldruetxeto(To,0 $3; e e naiAgmnEcpinw , e) $1=nwEcpinn 0 $2; e e xeto(Oe, , e) trw$1 ho e;} because it only told you...EcpintcTs:tsNseEcpin xetoSaket:etetdxetosEcpin Oe xeto: n[rc] tae but now...
    • 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
    • ?????????????????Fixed an annoying crash when using --process-isolation with PHP 5.3 and detect_unicode=on.
    • EVEN MORE EXCEPTIONAL@xetdxeto xeto epceEcpin Ecpin Works again!
    • ONE MORE THINGFtlerr Ucuh ecpinHUi_rmwr_xetowt msaee aa ro: nagt xeto PPntFaeokEcpin ih esg Nite "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 cant find any tests.
    • FEATURES YOU MIGHT HAVE MISSED
    • LINE ENDINGS MISMATCHIse0Ts:tsCmaeifrnLnEdns su53et:etoprDfeetienigFie asrigta tosrnsaeietcl ald setn ht w tig r dnia.--Epce - xetd++Ata + cul@ @ @ @ #ann:Srnscnandfeetln edns Wrig tig oti ifrn ie nig! fo o
    • IMPROVED THE JSON LOGIf tests produce output it is now properly included in the log.
    • BOOTSTRAP ORDERBootstrap script should be loaded before trying to load testSuiteLoaderClass.
    • PROCESS ISOLATION FOR EVERYONEProcess Isolation did not work when PHPUnit is invoked through Apache Ant, for instance, due to PHP binary detection issues.
    • @EXPECTEDEXCEPTIONCODE Now can be 0 or a string. Useful for PDO
    • BINARY MESS Before it broke your terminal and BEEPed at you1 Foet:eto ) oTs:tsFoFie 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....
    • ONE LINE ANNOTATIONS You can use:/*@xetdxeto uaEcpin* * epceEcpin Fbrxeto /
    • COUNTING ON ITNow working with Countable and Iterator Interfaces: assertCount() assertAttributeCount() assertNotCount() assertAttributeNotCount() assertSameSize() assertNotSameSize()
    • FLUENT INTERFACES A little mock improvement:-wl(ti-rtrSl() >il$hs>eunef);
    • @REQUIRES/* * *@eursPP54 rqie H . */pbi fnto tsTat) ulc ucin etri({}
    • MAGIC SUPPORTassertEquals() now looks for (and invokes) a __toString() method when an object and string are compared.
    • PERFORMANCEsetUpBeforeClass() and tearDownAfterClass() are no longer invoked when all tests of the class are skipped
    • UPCOMING STUFF
    • 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.
    • *TEST.PHP IS TOO MAINSTREAMAdded --test-suffix that allows specifying which filename suffixes are recognised by PHPUnit. Helps out some projects with their CI. I dont see a general use case.
    • {"JSON": "YES PLEASE"}We added assertJson* functions that work like the existing assertXml* functions. asrJoFlEulJoFl( setsnieqassnie) asrJoSrnEulJoFl( setsntigqassnie) asrJoSrnEulJoSrn( setsntigqassntig)
    • CALLBACK MATCHER Helps with complex assertions on mockspbi fnto sn(msae EdonCni $ofg ulc ucin ed$esg, npitofg cni) Its not pretty but it might solve that one annoying problem:$o-epcs$hs>ne) fo>xet(ti-oc() -mto(sn >ehded) -wt( >ih $hs>qaT(sn) ti-euloy, $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 } ) );
    • OO-ARRAYSasrAryaKy) setraHse(asrAryoHse( setraNtaKy) Now work with objects that implement ArrayAccess.
    • PHPUNIT.XSD PHPUnit now provides a configuration.xsd schema file. http://schema.phpunit.de/configuration.xsdUseful to validate your phpunit.xml and phpunit.xml.dist configuration files. <xlvrin"."ecdn=UF8? ?m eso=10 noig"T-"> <hui ppnt xlsxi"tp/www.r/01XLceaisac" mn:s=ht:/w.3og20/MShm-ntne xinNmsaeceaoain s:oaepcShmLcto =ht:/ceappntd/ofgrto.s" "tp/shm.hui.ecniuainxd [.] .. >
    • MORE @REQUIRES/* * *@eursPP54dv rqie H .-e *@eursPPnt37dv rqie HUi .-e *@eursfnto smFn rqie ucin oeuc *@eursfnto Cas:o rqie ucin ls:fo *@eursetninac rqie xeso p *@eursetninmsl rqie xeso yqi */ Require functions, methods and extensions Merges Class & Method doc blocks PHP & PHPUnit version get override
    • .PHPT IMPROVEMENTS-TS- -ET-G-0:asrEul( Ln Edn DfeecsAeOsue H53 setqas) ie nig ifrne r bcr-FL- -IE-<pp ?h$SRE[ag[]=-ocniuain; _EVRrv]1 -n-ofgrto$SRE[ag[]=su53et; _EVRrv]2 Ise0Ts$SRE[ag[]=_DR_./0/su53etpp; _EVRrv]3 _I_)53Ise0Ts.hrqieoc _DR_../../HUi/uoodpp; eur_ne _I_ /../.PPntAtla.hPPntTxU_omn:mi(; HUi_etICmad:an)?>
    • .PHPT IMPROVEMENTS-EPCF- -XET-PPnt% b SbsinBrmn. HUi s y eata eganFTm:% %,Mmr:%M ie i s eoy sbTeews1fiue hr a alr:1 Ise0Ts:tsCmaeifrnLnEdns ) su53et:etoprDfeetienigFie asrigta tosrnsaeietcl ald setn ht w tig r dnia.--Epce - xetd++Ata + cul@ @ @ @ #ann:Srnscnandfeetln edns Wrig tig oti ifrn ie nig! fo o%:i s%FIUE! ALRSTss 1 Asrin:1 Fiue:1 et: , setos , alrs .
    • .PHPT IMPROVEMENTSBefore 3.7 diffs where really hard to read.Now the diff will be processed line by line.
    • LISTS AND COLLECTIONSpbi 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.
    • FAILED @EXPECTEDEXCEPTION ANNOTATIONS Before:Fie asrigta ecpino tp "roEcpin mthsepce ecp ald setn ht xeto f ye Errxeto" ace xetd xeto "yxeto" in MEcpin. Now:Fie asrigta ecpino tp "roEcpin mthsepce ecp ald setn ht xeto f ye Errxeto" ace xetd xeto "yxeto" in MEcpin.Msaefo "roEcpin ws"neie vral $ts. esg rm Errxeto" a udfnd aibe hi"
    • 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.
    • 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
    • TEST SUITE ORGANIZATION
    • FOLDER LAYOUT?poet rjc/ ppntxlds hui.m.it sc r/ tss et/ bosrppp otta.h ui/ nt itgto/ neain fntoa/(rsse/ ucinl o ytm) hles epr/
    • TEST DISTRIBUTIONhttp://elblinkin.info/2012/03/goldilocks-on-test-sizes/
    • SMALL HINTSUse the xml configuration for pretty much everythingSeparate unit and integration testsYour unit test folders should mirror your applications folderstructureTo only execute specific tests use phpunit --filter or phpunittests/unit/module1Use the strict mode from the get go and never turn it off.Imho: Dont have a test namespace. Nicer to read and showsproduction usage.
    • DISCUSSION Issues? Feature requests? Anything I missed?
    • THANK YOU