the state of phpunit

72
THE STATE OF PHPUNIT Volker Dusch / @_ _edorian

Upload: edorian

Post on 08-May-2015

2.059 views

Category:

Education


0 download

TRANSCRIPT

Page 1: The state of PHPUnit

THE STATE OF PHPUNIT

Volker Dusch _ _edorian

ABOUT MEPHP since 10 yearsCICleanCodeDevOpsTDDShipping

INSTEAD OF ME

WORKING FOR

ResearchGate gives science back to the people who make it happen

We help researchers build reputation and accelerate scientificprogress

On their terms

GET IN TOUCHstackoverflow

Twitter __edorianXing G+ Volker DuschIRC edorianMail phpwallbashcom

LETS GO

Unit testing in PHP got mainstream

THATS A GOOD THINGUnit testing got normal in PHP

Even people that dont really know PHP or even the CLI know that theyshould write unit tests

AGENDACurrent StateThe EcoSystemPHPUnit 37Annoying things we got rid ofFeatures you might have missedShiny new thingsTest suite organizationDiscussion

CURRENT STATEVersions 3612 and hot from the presses githubs 375Over 70 contributors since 360One last 36 release to help with dependencies37 is early in the bugfix cycle no new features will be added Thosego into nextFrench docs thanks to poum and still current Japanese docs thanksto m-takagiIf you want to help outhttpsgithubcomsebastianbergmannphpunitcontributing

THE ECOSYSTEMhttpphpqatoolsorg amp friends

BDDUse Behat Its great

Were not going to remove the BDD stuff in PHPUnit but Its not beingworked on

WEB INTERFACENot sure why youd want that but someone solved that for you

httpsgithubcomNSinopoliVisualPHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 2: The state of PHPUnit

ABOUT MEPHP since 10 yearsCICleanCodeDevOpsTDDShipping

INSTEAD OF ME

WORKING FOR

ResearchGate gives science back to the people who make it happen

We help researchers build reputation and accelerate scientificprogress

On their terms

GET IN TOUCHstackoverflow

Twitter __edorianXing G+ Volker DuschIRC edorianMail phpwallbashcom

LETS GO

Unit testing in PHP got mainstream

THATS A GOOD THINGUnit testing got normal in PHP

Even people that dont really know PHP or even the CLI know that theyshould write unit tests

AGENDACurrent StateThe EcoSystemPHPUnit 37Annoying things we got rid ofFeatures you might have missedShiny new thingsTest suite organizationDiscussion

CURRENT STATEVersions 3612 and hot from the presses githubs 375Over 70 contributors since 360One last 36 release to help with dependencies37 is early in the bugfix cycle no new features will be added Thosego into nextFrench docs thanks to poum and still current Japanese docs thanksto m-takagiIf you want to help outhttpsgithubcomsebastianbergmannphpunitcontributing

THE ECOSYSTEMhttpphpqatoolsorg amp friends

BDDUse Behat Its great

Were not going to remove the BDD stuff in PHPUnit but Its not beingworked on

WEB INTERFACENot sure why youd want that but someone solved that for you

httpsgithubcomNSinopoliVisualPHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 3: The state of PHPUnit

INSTEAD OF ME

WORKING FOR

ResearchGate gives science back to the people who make it happen

We help researchers build reputation and accelerate scientificprogress

On their terms

GET IN TOUCHstackoverflow

Twitter __edorianXing G+ Volker DuschIRC edorianMail phpwallbashcom

LETS GO

Unit testing in PHP got mainstream

THATS A GOOD THINGUnit testing got normal in PHP

Even people that dont really know PHP or even the CLI know that theyshould write unit tests

AGENDACurrent StateThe EcoSystemPHPUnit 37Annoying things we got rid ofFeatures you might have missedShiny new thingsTest suite organizationDiscussion

CURRENT STATEVersions 3612 and hot from the presses githubs 375Over 70 contributors since 360One last 36 release to help with dependencies37 is early in the bugfix cycle no new features will be added Thosego into nextFrench docs thanks to poum and still current Japanese docs thanksto m-takagiIf you want to help outhttpsgithubcomsebastianbergmannphpunitcontributing

THE ECOSYSTEMhttpphpqatoolsorg amp friends

BDDUse Behat Its great

Were not going to remove the BDD stuff in PHPUnit but Its not beingworked on

WEB INTERFACENot sure why youd want that but someone solved that for you

httpsgithubcomNSinopoliVisualPHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 4: The state of PHPUnit

WORKING FOR

ResearchGate gives science back to the people who make it happen

We help researchers build reputation and accelerate scientificprogress

On their terms

GET IN TOUCHstackoverflow

Twitter __edorianXing G+ Volker DuschIRC edorianMail phpwallbashcom

LETS GO

Unit testing in PHP got mainstream

THATS A GOOD THINGUnit testing got normal in PHP

Even people that dont really know PHP or even the CLI know that theyshould write unit tests

AGENDACurrent StateThe EcoSystemPHPUnit 37Annoying things we got rid ofFeatures you might have missedShiny new thingsTest suite organizationDiscussion

CURRENT STATEVersions 3612 and hot from the presses githubs 375Over 70 contributors since 360One last 36 release to help with dependencies37 is early in the bugfix cycle no new features will be added Thosego into nextFrench docs thanks to poum and still current Japanese docs thanksto m-takagiIf you want to help outhttpsgithubcomsebastianbergmannphpunitcontributing

THE ECOSYSTEMhttpphpqatoolsorg amp friends

BDDUse Behat Its great

Were not going to remove the BDD stuff in PHPUnit but Its not beingworked on

WEB INTERFACENot sure why youd want that but someone solved that for you

httpsgithubcomNSinopoliVisualPHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 5: The state of PHPUnit

GET IN TOUCHstackoverflow

Twitter __edorianXing G+ Volker DuschIRC edorianMail phpwallbashcom

LETS GO

Unit testing in PHP got mainstream

THATS A GOOD THINGUnit testing got normal in PHP

Even people that dont really know PHP or even the CLI know that theyshould write unit tests

AGENDACurrent StateThe EcoSystemPHPUnit 37Annoying things we got rid ofFeatures you might have missedShiny new thingsTest suite organizationDiscussion

CURRENT STATEVersions 3612 and hot from the presses githubs 375Over 70 contributors since 360One last 36 release to help with dependencies37 is early in the bugfix cycle no new features will be added Thosego into nextFrench docs thanks to poum and still current Japanese docs thanksto m-takagiIf you want to help outhttpsgithubcomsebastianbergmannphpunitcontributing

THE ECOSYSTEMhttpphpqatoolsorg amp friends

BDDUse Behat Its great

Were not going to remove the BDD stuff in PHPUnit but Its not beingworked on

WEB INTERFACENot sure why youd want that but someone solved that for you

httpsgithubcomNSinopoliVisualPHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 6: The state of PHPUnit

LETS GO

Unit testing in PHP got mainstream

THATS A GOOD THINGUnit testing got normal in PHP

Even people that dont really know PHP or even the CLI know that theyshould write unit tests

AGENDACurrent StateThe EcoSystemPHPUnit 37Annoying things we got rid ofFeatures you might have missedShiny new thingsTest suite organizationDiscussion

CURRENT STATEVersions 3612 and hot from the presses githubs 375Over 70 contributors since 360One last 36 release to help with dependencies37 is early in the bugfix cycle no new features will be added Thosego into nextFrench docs thanks to poum and still current Japanese docs thanksto m-takagiIf you want to help outhttpsgithubcomsebastianbergmannphpunitcontributing

THE ECOSYSTEMhttpphpqatoolsorg amp friends

BDDUse Behat Its great

Were not going to remove the BDD stuff in PHPUnit but Its not beingworked on

WEB INTERFACENot sure why youd want that but someone solved that for you

httpsgithubcomNSinopoliVisualPHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 7: The state of PHPUnit

Unit testing in PHP got mainstream

THATS A GOOD THINGUnit testing got normal in PHP

Even people that dont really know PHP or even the CLI know that theyshould write unit tests

AGENDACurrent StateThe EcoSystemPHPUnit 37Annoying things we got rid ofFeatures you might have missedShiny new thingsTest suite organizationDiscussion

CURRENT STATEVersions 3612 and hot from the presses githubs 375Over 70 contributors since 360One last 36 release to help with dependencies37 is early in the bugfix cycle no new features will be added Thosego into nextFrench docs thanks to poum and still current Japanese docs thanksto m-takagiIf you want to help outhttpsgithubcomsebastianbergmannphpunitcontributing

THE ECOSYSTEMhttpphpqatoolsorg amp friends

BDDUse Behat Its great

Were not going to remove the BDD stuff in PHPUnit but Its not beingworked on

WEB INTERFACENot sure why youd want that but someone solved that for you

httpsgithubcomNSinopoliVisualPHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 8: The state of PHPUnit

THATS A GOOD THINGUnit testing got normal in PHP

Even people that dont really know PHP or even the CLI know that theyshould write unit tests

AGENDACurrent StateThe EcoSystemPHPUnit 37Annoying things we got rid ofFeatures you might have missedShiny new thingsTest suite organizationDiscussion

CURRENT STATEVersions 3612 and hot from the presses githubs 375Over 70 contributors since 360One last 36 release to help with dependencies37 is early in the bugfix cycle no new features will be added Thosego into nextFrench docs thanks to poum and still current Japanese docs thanksto m-takagiIf you want to help outhttpsgithubcomsebastianbergmannphpunitcontributing

THE ECOSYSTEMhttpphpqatoolsorg amp friends

BDDUse Behat Its great

Were not going to remove the BDD stuff in PHPUnit but Its not beingworked on

WEB INTERFACENot sure why youd want that but someone solved that for you

httpsgithubcomNSinopoliVisualPHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 9: The state of PHPUnit

AGENDACurrent StateThe EcoSystemPHPUnit 37Annoying things we got rid ofFeatures you might have missedShiny new thingsTest suite organizationDiscussion

CURRENT STATEVersions 3612 and hot from the presses githubs 375Over 70 contributors since 360One last 36 release to help with dependencies37 is early in the bugfix cycle no new features will be added Thosego into nextFrench docs thanks to poum and still current Japanese docs thanksto m-takagiIf you want to help outhttpsgithubcomsebastianbergmannphpunitcontributing

THE ECOSYSTEMhttpphpqatoolsorg amp friends

BDDUse Behat Its great

Were not going to remove the BDD stuff in PHPUnit but Its not beingworked on

WEB INTERFACENot sure why youd want that but someone solved that for you

httpsgithubcomNSinopoliVisualPHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 10: The state of PHPUnit

CURRENT STATEVersions 3612 and hot from the presses githubs 375Over 70 contributors since 360One last 36 release to help with dependencies37 is early in the bugfix cycle no new features will be added Thosego into nextFrench docs thanks to poum and still current Japanese docs thanksto m-takagiIf you want to help outhttpsgithubcomsebastianbergmannphpunitcontributing

THE ECOSYSTEMhttpphpqatoolsorg amp friends

BDDUse Behat Its great

Were not going to remove the BDD stuff in PHPUnit but Its not beingworked on

WEB INTERFACENot sure why youd want that but someone solved that for you

httpsgithubcomNSinopoliVisualPHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 11: The state of PHPUnit

THE ECOSYSTEMhttpphpqatoolsorg amp friends

BDDUse Behat Its great

Were not going to remove the BDD stuff in PHPUnit but Its not beingworked on

WEB INTERFACENot sure why youd want that but someone solved that for you

httpsgithubcomNSinopoliVisualPHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 12: The state of PHPUnit

BDDUse Behat Its great

Were not going to remove the BDD stuff in PHPUnit but Its not beingworked on

WEB INTERFACENot sure why youd want that but someone solved that for you

httpsgithubcomNSinopoliVisualPHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 13: The state of PHPUnit

WEB INTERFACENot sure why youd want that but someone solved that for you

httpsgithubcomNSinopoliVisualPHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 14: The state of PHPUnit

MOCKING IS UGLYReal world problems and solutions

httpstackoverflowcomsearchtab=votesampq=[phpunit] mock

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 15: The state of PHPUnit

MOCKERYTry it Its great

Afraid it might be hard to set up and use

Look into httpsgithubcometsyphpunit-extensionswikiMockery

Works with strict mode leaves the old API intact and is as easy aswriting a comment

class MyTest extends PHPUnit_Extensions_Mockery_TestCase

mockery Foo protected $foo

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 16: The state of PHPUnit

LOTS OF LEGACY CODEOr whatever hard to test is called these days

httpsgithubcomlapistanoproxy-object

One of the main purpose of this library is to expose invisible (private orprotected) methods and properties to the SUT

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 17: The state of PHPUnit

TESTING WEB SERVICESUnit and Integration test web services with the same code

Try wsUnit httpsgithubcomlapistanowsunit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 18: The state of PHPUnit

IDE SUPPORTNetbeans support improved and they adopted the skeleton-generatorHonestly I have no clue about eclipsePHPStorm has really beautiful coverage support by nowvim user phpunit --coverage-text

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 19: The state of PHPUnit

JENKINSJenkins template jenkins-phporgclover php plugin

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 20: The state of PHPUnit

TRAVIS CIAwesome for GitHub and collaborationEveryone 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 )

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 21: The state of PHPUnit

PHPUNIT 3715+ features20+ issues fixedDetails later

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 22: The state of PHPUnit

COMPOSER

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 23: The state of PHPUnit

COMPOSERFor a long timeWhen someone does the work it it will happen

A couple of weeks agoclaylo came along and did the work Tweet him a thanks

YesterdayStill some issues Wait for 372 and try again It might take a fewiterations but Jordi ( Seldaek ) is helping out too so well get thereeventually )

TodayPHPUnit 375 was released and it works

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 24: The state of PHPUnit

PHAR - THE PHP TOOL FORMATIssues with process isolationTimeMaintanceTooling

Yesterday Sebastian published something that works for us Please testit

Have a look at

httpsebastian-bergmanndearchives924-Using-PHPUnit-from-a-PHP-Archive-PHARhtml

wget httppearphpunitdegetphpunit-375pharchmod +x phpunit-375pharphpunit-375phar

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 25: The state of PHPUnit

PHPUNIT-SELENIUMNow maintained by giorgiosironiCode coverage support

If you ask me Dont drive your web tests with phpunit

Use Behat or something non php

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 26: The state of PHPUnit

BCDid you like upgrading to PHPUnit 36

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 27: The state of PHPUnit

BC FREE-ISHWe are trying really hard to not introduce any BC breaks

cwd gets restored after test caseparameter cloning behaviorRemoved deprecated OutputTestCaseaddUncoveredFilesFromWhitelist changed intoprocessUncoveredFilesFromWhitelistCodeCoverage includes more files by defaultTest listeners trigger one autoload calland thats itIve written it all down for youhttpwwwphpunitdemanualcurrenteninstallationhtmlinstallingupgrading

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 28: The state of PHPUnit

ANNOYING THINGS WE GOTRID OF

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 29: The state of PHPUnit

BLOCKWhen using process-isolation PHPUnit wont die silently when

unserializing of the test result fails

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 30: The state of PHPUnit

HEY LISTENTest listeners now trigger one autoload call instead of being silently

ignored when the class was not loaded

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 31: The state of PHPUnit

EXCEPTIONALImproved reporting of exceptions

because it only told you

but now

public function testNestedExceptions() $e3 = new Exception(Three) $e2 = new InvalidArgumentException(Two 0 $e3) $e1 = new Exception(One 0 $e2) throw $e1

ExceptionStackTesttestNestedExceptionsException One

[trace]

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 32: The state of PHPUnit

EXCEPTIONALwe are printing out the previous exception names messages and

traces

ExceptionStackTesttestNestedExceptionsException One

[trace]

Caused byInvalidArgumentException Two

[trace]

Caused byException Three

[trace]

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 33: The state of PHPUnit

Fixed an annoying crash when using --process-isolation with PHP 53

and detect_unicode=on

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 34: The state of PHPUnit

EVEN MORE EXCEPTIONAL

Works again

expectedException Exception

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 35: The state of PHPUnit

ONE MORE THING

That one is still alive Sorry )

It just means that PHPUnit cant find any tests

Fatal error Uncaught exception PHPUnit_Framework_Exception with message Neither testsphp nor testsphp could be opened in

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 36: The state of PHPUnit

FEATURES YOU MIGHT HAVEMISSED

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 37: The state of PHPUnit

LINE ENDINGS MISMATCHIssue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 38: The state of PHPUnit

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 arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 39: The state of PHPUnit

BOOTSTRAP ORDERBootstrap script should be loaded before trying to load

testSuiteLoaderClass

PROCESS ISOLATION FOR EVERYONEProcess Isolation did not work when PHPUnit is invoked through arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 40: The state of PHPUnit

PROCESS ISOLATION FOR EVERYONEProcess Isolation did not work when PHPUnit is invoked through arunner like Ant Phing Bash or Make due to PHP binary detection

issues

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 41: The state of PHPUnit

EXPECTEDEXCEPTIONCODENow can be 0 or a string

Useful for PDO

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 42: The state of PHPUnit

BINARY MESSBefore it broke your terminal and BEEPed at you

Now it shows a hex dump

1) FooTesttestFooFailed asserting that two strings are equal--- Expected+++ Actual -+ heartsdiams++parasectuarrdarrrarrlarr∟harr

Binary String 0x000102030405

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 43: The state of PHPUnit

ONE LINE ANNOTATIONSYou can use

or

expectedException FubarException

covers MyClass

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 44: The state of PHPUnit

COUNTING ON ITNow working with Countable and Iterator Interfaces

assertCount()assertAttributeCount()assertNotCount()assertAttributeNotCount()assertSameSize()assertNotSameSize()

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 45: The state of PHPUnit

FLUENT INTERFACESA little mock improvement

-gtwill($this-gtreturnSelf())

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 46: The state of PHPUnit

REQUIRES requires PHP 54 public function testTrait()

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 47: The state of PHPUnit

REQUIRESlttestsuitegt ltfile phpVersion=540 phpVersionOperator=gt=gt testsunitMyTraitTestphp ltfilegtlttestsuitegt

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 48: The state of PHPUnit

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

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 49: The state of PHPUnit

PERFORMANCEsetUpBeforeClass() and tearDownAfterClass() are no longer invoked

when all tests of the class are skipped

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 50: The state of PHPUnit

SHINY NEW THINGS

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 51: The state of PHPUnit

LESS MAGIC NUMBERSexpectedException now works with constants

Reduce copy paste testing

expectedException Class expectedExceptionCode ClassTEAPOT_MISSING expectedExceptionMessage ClassTEAPOT_MISSING_MESSAGE

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 52: The state of PHPUnit

TESTPHP 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 PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 53: The state of PHPUnit

JSON YES PLEASEWe added assertJson functions that work like the existing assertXml

functions

assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString()

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 54: The state of PHPUnit

CALLBACK MATCHERHelps with complex assertions on mocks

Its not pretty but it might solve that one annoying problem

public function send($message EndpointConfig $config)

$foo-gtexpects($this-gtonce()) -gtmethod(send) -gtwith( $this-gtequalTo(syn) $this-gtcallback( function ($config) $url = $config-gtgetUrl() if($url) throw new Exception() return $url-gtgetHost() === httpexamplecom ) )

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 55: The state of PHPUnit

OO-ARRAYS

Now work with objects that implement ArrayAccess

assertArrayHasKey()assertArrayNotHasKey()

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 56: The state of PHPUnit

PHPUNITXSDPHPUnit now provides a configurationxsd schema file

httpschemaphpunitdeconfigurationxsd

Useful to validate your phpunitxml and phpunitxmldist configurationfiles

ltxml version=10 encoding=UTF-8gtltphpunit xmlnsxsi=httpwwww3org2001XMLSchema-instance xsinoNamespaceSchemaLocation =httpschemaphpunitdeconfigurationxsd []gt

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 57: The state of PHPUnit

MORE REQUIRES

Require functions methods and extensionsMerges Class amp Method doc blocksPHP amp PHPUnit version get override

requires PHP 54-dev requires PHPUnit 37-dev requires function someFunc requires function Classfoo requires extension apc requires extension mysqli

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 58: The state of PHPUnit

PHPT IMPROVEMENTS--TEST--

GH-503 assertEquals() Line Ending Differences Are Obscure

--FILE--ltphp

$_SERVER[argv][1] = --no-configuration$_SERVER[argv][2] = Issue503Test$_SERVER[argv][3] = __DIR__)503Issue503Testphp

require_once __DIR__ PHPUnitAutoloadphpPHPUnit_TextUI_Commandmain()gt--EXPECTF--[]

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 59: The state of PHPUnit

PHPT IMPROVEMENTS--EXPECTF--PHPUnit s by Sebastian BergmannFTime i s Memory sMb

There was 1 failure

1) Issue503TesttestCompareDifferentLineEndingsFailed asserting that two strings are identical--- Expected+++ Actual Warning Strings contain different line endings foo

FAILURESTests 1 Assertions 1 Failures 1

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 60: The state of PHPUnit

PHPT IMPROVEMENTSBefore 37 diffs where really hard to read

Now the diff will be processed line by line

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 61: The state of PHPUnit

LISTS AND COLLECTIONS

Helper for checking Collection objects and arrays

Descriptive assertion and error message

public function testAssertContainsOnlyInstancesOf() $library = array( new Book() new Book() ) $this-gtassertContainsOnlyInstancesOf( Book $library )

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 62: The state of PHPUnit

FAILED EXPECTEDEXCEPTION ANNOTATIONSBefore

Now

Failed asserting that exception of type ErrorException matches expected exception MyException

Failed asserting that exception of type ErrorException matches expected exception MyException Message from ErrorException was undefined variable $htis

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 63: The state of PHPUnit

LESS REQUIRES LESS CRASHES

People seem to constantly run into issues with code coverage

When enabled uncovered whitelisted files are processed to properlycalculate the number of executable lines

If not we take a quite ok guess to get the number of ELOC

ltwhitelist addUncoveredFilesFromWhitelist=truegt

ltwhitelist processUncoveredFilesFromWhitelist=truegt

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 64: The state of PHPUnit

MORE USEFUL GROUPS

Now works as expected

$ phpunit --group FlakyTests

ltphpunitgt ltgroupsgt ltexcludegt ltgroupgtFlakyTestsltgroupgt ltexcludegt ltgroupsgt lttestsuites gtltphpunitgt

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 65: The state of PHPUnit

TEST SUITE ORGANIZATION

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 66: The state of PHPUnit

FOLDER LAYOUTproject phpunitxmldist src tests bootstrapphp unit integation functional (or system) helpers

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 67: The state of PHPUnit

TEST DISTRIBUTIONhttpelblinkininfo201203goldilocks-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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 68: The state of PHPUnit

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 phpunittestsunitmodule1Use the strict mode from the get go and never turn it offImho Dont have a test namespace Nicer to read and showsproduction usage

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 69: The state of PHPUnit

DISCUSSIONIssues

Feature requests

Anything I missed

THANK YOU

Page 70: The state of PHPUnit

THANK YOU

Page 71: The state of PHPUnit