SlideShare una empresa de Scribd logo
1 de 26
Descargar para leer sin conexión
RICARDO MELO

PHPUnit your bug
exterminator
Follow this topic:
@rjsmelo, #phpunit
PHPLX – 07 December 2013
RICARDO MELO

CTO @ DRI
● PHP, Mysql, Linux and lots of other
OSS
● ZCE, RHCE, LPI 3, ITIL, etc
● +10 years building (and breaking)
things
●

@rjsmelo

2
About

14 Year old academic spin-off
● Pragmatic OSS Orientation
● PHP, Mysql, SugarCRM, Drupal,
JavaScript, Linux, etc.
● Crafters, Integrators
●

●

Always looking for software developers
–

Yes, right now!

@rjsmelo

3
Outline

Testing Methodologies
● Testing Tools Ecosystem
● What's PHPUnit
● The "Hello World" test
● How to run your tests
● Other assertions
● Other PHPUnit topics
● The bug hunting work flow
●

1999 - 2013 DRI. Some Rights Reserved
.

4
Testing and Development Methodologies

Unit, Integration, System and
Acceptance Testing
● CMMI/Waterfall, Agile and XP
● TDD and BDD
●

1999 - 2013 DRI. Some Rights Reserved
.

5
Testing Tools Ecosystem

PHPUnit
● Behat
● Selenium
● Codeception
● And many more
●

1999 - 2013 DRI. Some Rights Reserved
.

6
What's PHPUnit

xUnit family for PHP
● Uses assertions to check the behavior
of the unit
● But it can handle other tests like
integration and system
●

1999 - 2013 DRI. Some Rights Reserved
.

7
Installing PHPUnit
●

Pear
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit
phpunit --version

1999 - 2013 DRI. Some Rights Reserved
.

8
Installing PHPUnit
●

Composer
{
"require-dev": {
"phpunit/phpunit": "3.7.*"
}
}
composer install
./vendor/bin/phpunit --version

1999 - 2013 DRI. Some Rights Reserved
.

9
The "Hello World" test
<?php
namespace Phplx;
class HelloWorld {
public function say(){
return "Hello World";
}
}

1999 - 2013 DRI. Some Rights Reserved
.

10
The "Hello World" test
<?php
namespace PhplxTestsHelloWorld;
use PHPUnit_Framework_TestCase
use PhplxHelloWorld;
class HelloWorldTest extends PHPUnit_Framework_TestCase
{
public function testHelloWorld(){
$obj = new HelloWorld();
$this->assertEquals("Hello World", $obj->say());
}
}

1999 - 2013 DRI. Some Rights Reserved
.

11
How to run your tests
# using PEAR / PHAR
phpunit --bootstrap vendor/autoload.php tests/
# using composer
./vendor/bin/phpunit tests/

1999 - 2013 DRI. Some Rights Reserved
.

12
How to run your tests – bootstrap.php
<?php
use PhplxApp;
require_once dirname(__DIR__) . "/vendor/autoload.php";
$app = new App();
$app->initHelloWorldApplication();

1999 - 2013 DRI. Some Rights Reserved
.

13
How to run your tests – phpunit.xml
<phpunit

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xs
d"
bootstrap="tests/bootstrap.php"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
>
<testsuites>
<testsuite name="Hello World Test Suite">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
</phpunit>

1999 - 2013 DRI. Some Rights Reserved
.

14
How to run your tests – phpunit
$ ./vendor/bin/phpunit
PHPUnit 3.7.28 by Sebastian Bergmann.
Configuration read from /home/rjsmelo/phplx/phpunit.xml
...
Time: 42 ms, Memory: 3.25Mb
OK (3 tests, 3 assertions)

1999 - 2013 DRI. Some Rights Reserved
.

15
Other assertions
●

There is a HUGE list of assertions

1999 - 2013 DRI. Some Rights Reserved
.

16
Use specific assertions - assertInstanceOf
<?php
use PhplxHelloWorld;
class InstanceOfTest extends PHPUnit_Framework_TestCase
{
public function testTrue(){
$obj = new stdClass();
$this->assertTrue(
$obj instanceof PhplxHelloWorld);
}
public function testInstanceOf(){
$obj = new stdClass();
$this->assertInstanceOf(
'PhplxHelloWorld', $obj);
}
}
1999 - 2013 DRI. Some Rights Reserved
.

17
Use specific assertions - assertInstanceOf
PHPUnit 3.7.28 by Sebastian Bergmann.
[...]
1) InstanceOfTest::testTrue
Failed asserting that false is true.
2) InstanceOfTest::testInstanceOf
Failed asserting that stdClass Object () is an instance of class
"PhplxHelloWorld".

1999 - 2013 DRI. Some Rights Reserved
.

18
Use specific assertions - JsonString
<?php
use PhplxObject;
class JsonStringTest extends PHPUnit_Framework_TestCase
{
protected $jsonString =
'{"someKey":"some thing","otherKey":"other thing"}';
public function testEquals(){
$obj = new Object();
$this->assertEquals(
$this->jsonString, $obj->myPreciousJson());
}
public function testJsonString(){
$obj = new Object();
$this->assertJsonStringEqualsJsonString(
$this->jsonString, $obj->myPreciousJson());
}
}
1999 - 2013 DRI. Some Rights Reserved
.

19
Use specific assertions - JsonString
PHPUnit 3.7.28 by Sebastian Bergmann.
[...]
1) JsonStringTest::testEquals
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'{"someKey":"some thing","otherKey":"other thing"}'
+'{"someKey":"some value","otherKey":"other thing"}'
2) JsonStringTest::testJsonString
Failed asserting that two objects are equal.
--- Expected
+++ Actual
@@ @@
stdClass Object (
'someKey' => 'some thing'
+
'someKey' => 'some value'
'otherKey' => 'other thing'
)
1999 - 2013 DRI. Some Rights Reserved
.

20
Other PHPUnit topics

Setup / Teardown
● Data providers
● Test doubles
●

1999 - 2013 DRI. Some Rights Reserved
.

21
The bug hunting work flow

Gather information on the problem
● Reproduce the problem
● Capture that as a test
● Fix it (ok... this sometimes is hard)
● All green... mission accomplished
●

1999 - 2013 DRI. Some Rights Reserved
.

22
The community challenge

Go to your favorite PHP project
● Or go to
https://github.com/trending?l=php
and pick one
● Fix Some Bugs!
●

1999 - 2013 DRI. Some Rights Reserved
.

23
Thank you
QA
Follow this topic:
@rjsmelo, #phpunit

Code: https://github.com/rjsmelo/talk-phpunit
Feedback: https://joind.in/talk/view/10305
www.dri-global.com
@rjsmelo
ricardo.melo@dri-global.com

Más contenido relacionado

La actualidad más candente

Metaprogramming in .NET
Metaprogramming in .NETMetaprogramming in .NET
Metaprogramming in .NETjasonbock
 
exception handling in cpp
exception handling in cppexception handling in cpp
exception handling in cppgourav kottawar
 
Typescript tips & tricks
Typescript tips & tricksTypescript tips & tricks
Typescript tips & tricksOri Calvo
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyAndres Almiray
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingAndres Almiray
 
How to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using ValgrindHow to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using ValgrindRapidValue
 
Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsMarcin Grzejszczak
 
関西アンカンファレンス PHP ではじめるテストコード
関西アンカンファレンス PHP ではじめるテストコード関西アンカンファレンス PHP ではじめるテストコード
関西アンカンファレンス PHP ではじめるテストコードShinya Ohyanagi
 
One definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим житьOne definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим житьPlatonov Sergey
 
Groovy and Grails intro
Groovy and Grails introGroovy and Grails intro
Groovy and Grails introMiguel Pastor
 
Groovy AST Transformations
Groovy AST TransformationsGroovy AST Transformations
Groovy AST Transformationshendersk
 
10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript TipsTroy Miles
 
Groovy Grails DevJam Jam Session
Groovy Grails DevJam Jam SessionGroovy Grails DevJam Jam Session
Groovy Grails DevJam Jam SessionMike Hugo
 
Pokročilé techniky v Reactu
Pokročilé techniky v ReactuPokročilé techniky v Reactu
Pokročilé techniky v ReactuVojtěch Přikryl
 

La actualidad más candente (20)

Metaprogramming in .NET
Metaprogramming in .NETMetaprogramming in .NET
Metaprogramming in .NET
 
exception handling in cpp
exception handling in cppexception handling in cpp
exception handling in cpp
 
Typescript tips & tricks
Typescript tips & tricksTypescript tips & tricks
Typescript tips & tricks
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
Presentation about ClosureScript fraemework
Presentation about ClosureScript fraemeworkPresentation about ClosureScript fraemework
Presentation about ClosureScript fraemework
 
groovy & grails - lecture 5
groovy & grails - lecture 5groovy & grails - lecture 5
groovy & grails - lecture 5
 
How to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using ValgrindHow to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using Valgrind
 
Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transforms
 
C&cpu
C&cpuC&cpu
C&cpu
 
関西アンカンファレンス PHP ではじめるテストコード
関西アンカンファレンス PHP ではじめるテストコード関西アンカンファレンス PHP ではじめるテストコード
関西アンカンファレンス PHP ではじめるテストコード
 
Jason parsing
Jason parsingJason parsing
Jason parsing
 
Ast transformation
Ast transformationAst transformation
Ast transformation
 
One definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим житьOne definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим жить
 
Groovy and Grails intro
Groovy and Grails introGroovy and Grails intro
Groovy and Grails intro
 
Groovy AST Transformations
Groovy AST TransformationsGroovy AST Transformations
Groovy AST Transformations
 
10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips
 
Groovy Grails DevJam Jam Session
Groovy Grails DevJam Jam SessionGroovy Grails DevJam Jam Session
Groovy Grails DevJam Jam Session
 
Pokročilé techniky v Reactu
Pokročilé techniky v ReactuPokročilé techniky v Reactu
Pokročilé techniky v Reactu
 
groovy & grails - lecture 6
groovy & grails - lecture 6groovy & grails - lecture 6
groovy & grails - lecture 6
 

Destacado

PHP QA Tools
PHP QA ToolsPHP QA Tools
PHP QA Toolsrjsmelo
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationrjsmelo
 
OWASP TOP 10 for PHP Programmers
OWASP TOP 10 for PHP ProgrammersOWASP TOP 10 for PHP Programmers
OWASP TOP 10 for PHP Programmersrjsmelo
 
Docker & PHP - Practical use case
Docker & PHP - Practical use caseDocker & PHP - Practical use case
Docker & PHP - Practical use caserjsmelo
 
Docker and Running multiple versions of PHP @ CareerZoo Dublin
Docker and Running multiple versions of PHP @ CareerZoo DublinDocker and Running multiple versions of PHP @ CareerZoo Dublin
Docker and Running multiple versions of PHP @ CareerZoo Dublinrjsmelo
 
Crash Course in Cloud Computing
Crash Course in Cloud ComputingCrash Course in Cloud Computing
Crash Course in Cloud ComputingAll Things Open
 

Destacado (6)

PHP QA Tools
PHP QA ToolsPHP QA Tools
PHP QA Tools
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
 
OWASP TOP 10 for PHP Programmers
OWASP TOP 10 for PHP ProgrammersOWASP TOP 10 for PHP Programmers
OWASP TOP 10 for PHP Programmers
 
Docker & PHP - Practical use case
Docker & PHP - Practical use caseDocker & PHP - Practical use case
Docker & PHP - Practical use case
 
Docker and Running multiple versions of PHP @ CareerZoo Dublin
Docker and Running multiple versions of PHP @ CareerZoo DublinDocker and Running multiple versions of PHP @ CareerZoo Dublin
Docker and Running multiple versions of PHP @ CareerZoo Dublin
 
Crash Course in Cloud Computing
Crash Course in Cloud ComputingCrash Course in Cloud Computing
Crash Course in Cloud Computing
 

Similar a PHPUnit your bug exterminator

EPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur PurnamaEPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur PurnamaEnterprise PHP Center
 
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013Michelangelo van Dam
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in YiiIlPeach
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Eric Hogue
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest UpdatesIftekhar Eather
 
2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps2010 07-28-testing-zf-apps
2010 07-28-testing-zf-appsVenkata Ramana
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09Michelangelo van Dam
 
Silex and Twig (PHP Dorset talk)
Silex and Twig (PHP Dorset talk)Silex and Twig (PHP Dorset talk)
Silex and Twig (PHP Dorset talk)Dave Hulbert
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitMichelangelo van Dam
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentationThanh Robi
 
Real world cross-platform testing
Real world cross-platform testingReal world cross-platform testing
Real world cross-platform testingPeter Edwards
 
Unlock The Mystery Of PHPUnit (Wave PHP 2018)
Unlock The Mystery Of PHPUnit (Wave PHP 2018)Unlock The Mystery Of PHPUnit (Wave PHP 2018)
Unlock The Mystery Of PHPUnit (Wave PHP 2018)ENDelt260
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityGeorgePeterBanyard
 
13 PHPUnit #burningkeyboards
13 PHPUnit #burningkeyboards13 PHPUnit #burningkeyboards
13 PHPUnit #burningkeyboardsDenis Ristic
 

Similar a PHPUnit your bug exterminator (20)

EPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur PurnamaEPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
 
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in Yii
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps
 
PHPUnit testing to Zend_Test
PHPUnit testing to Zend_TestPHPUnit testing to Zend_Test
PHPUnit testing to Zend_Test
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
Silex and Twig (PHP Dorset talk)
Silex and Twig (PHP Dorset talk)Silex and Twig (PHP Dorset talk)
Silex and Twig (PHP Dorset talk)
 
Unit testing
Unit testingUnit testing
Unit testing
 
Phpunit testing
Phpunit testingPhpunit testing
Phpunit testing
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 
Real world cross-platform testing
Real world cross-platform testingReal world cross-platform testing
Real world cross-platform testing
 
PHP7 Presentation
PHP7 PresentationPHP7 Presentation
PHP7 Presentation
 
Unlock The Mystery Of PHPUnit (Wave PHP 2018)
Unlock The Mystery Of PHPUnit (Wave PHP 2018)Unlock The Mystery Of PHPUnit (Wave PHP 2018)
Unlock The Mystery Of PHPUnit (Wave PHP 2018)
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
 
13 PHPUnit #burningkeyboards
13 PHPUnit #burningkeyboards13 PHPUnit #burningkeyboards
13 PHPUnit #burningkeyboards
 
Php unit (eng)
Php unit (eng)Php unit (eng)
Php unit (eng)
 

Último

Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Último (20)

Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

PHPUnit your bug exterminator

  • 1. RICARDO MELO PHPUnit your bug exterminator Follow this topic: @rjsmelo, #phpunit PHPLX – 07 December 2013
  • 2. RICARDO MELO CTO @ DRI ● PHP, Mysql, Linux and lots of other OSS ● ZCE, RHCE, LPI 3, ITIL, etc ● +10 years building (and breaking) things ● @rjsmelo 2
  • 3. About 14 Year old academic spin-off ● Pragmatic OSS Orientation ● PHP, Mysql, SugarCRM, Drupal, JavaScript, Linux, etc. ● Crafters, Integrators ● ● Always looking for software developers – Yes, right now! @rjsmelo 3
  • 4. Outline Testing Methodologies ● Testing Tools Ecosystem ● What's PHPUnit ● The "Hello World" test ● How to run your tests ● Other assertions ● Other PHPUnit topics ● The bug hunting work flow ● 1999 - 2013 DRI. Some Rights Reserved . 4
  • 5. Testing and Development Methodologies Unit, Integration, System and Acceptance Testing ● CMMI/Waterfall, Agile and XP ● TDD and BDD ● 1999 - 2013 DRI. Some Rights Reserved . 5
  • 6. Testing Tools Ecosystem PHPUnit ● Behat ● Selenium ● Codeception ● And many more ● 1999 - 2013 DRI. Some Rights Reserved . 6
  • 7. What's PHPUnit xUnit family for PHP ● Uses assertions to check the behavior of the unit ● But it can handle other tests like integration and system ● 1999 - 2013 DRI. Some Rights Reserved . 7
  • 8. Installing PHPUnit ● Pear pear config-set auto_discover 1 pear install pear.phpunit.de/PHPUnit phpunit --version 1999 - 2013 DRI. Some Rights Reserved . 8
  • 9. Installing PHPUnit ● Composer { "require-dev": { "phpunit/phpunit": "3.7.*" } } composer install ./vendor/bin/phpunit --version 1999 - 2013 DRI. Some Rights Reserved . 9
  • 10. The "Hello World" test <?php namespace Phplx; class HelloWorld { public function say(){ return "Hello World"; } } 1999 - 2013 DRI. Some Rights Reserved . 10
  • 11. The "Hello World" test <?php namespace PhplxTestsHelloWorld; use PHPUnit_Framework_TestCase use PhplxHelloWorld; class HelloWorldTest extends PHPUnit_Framework_TestCase { public function testHelloWorld(){ $obj = new HelloWorld(); $this->assertEquals("Hello World", $obj->say()); } } 1999 - 2013 DRI. Some Rights Reserved . 11
  • 12. How to run your tests # using PEAR / PHAR phpunit --bootstrap vendor/autoload.php tests/ # using composer ./vendor/bin/phpunit tests/ 1999 - 2013 DRI. Some Rights Reserved . 12
  • 13. How to run your tests – bootstrap.php <?php use PhplxApp; require_once dirname(__DIR__) . "/vendor/autoload.php"; $app = new App(); $app->initHelloWorldApplication(); 1999 - 2013 DRI. Some Rights Reserved . 13
  • 14. How to run your tests – phpunit.xml <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xs d" bootstrap="tests/bootstrap.php" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" > <testsuites> <testsuite name="Hello World Test Suite"> <directory suffix="Test.php">tests</directory> </testsuite> </testsuites> </phpunit> 1999 - 2013 DRI. Some Rights Reserved . 14
  • 15. How to run your tests – phpunit $ ./vendor/bin/phpunit PHPUnit 3.7.28 by Sebastian Bergmann. Configuration read from /home/rjsmelo/phplx/phpunit.xml ... Time: 42 ms, Memory: 3.25Mb OK (3 tests, 3 assertions) 1999 - 2013 DRI. Some Rights Reserved . 15
  • 16. Other assertions ● There is a HUGE list of assertions 1999 - 2013 DRI. Some Rights Reserved . 16
  • 17. Use specific assertions - assertInstanceOf <?php use PhplxHelloWorld; class InstanceOfTest extends PHPUnit_Framework_TestCase { public function testTrue(){ $obj = new stdClass(); $this->assertTrue( $obj instanceof PhplxHelloWorld); } public function testInstanceOf(){ $obj = new stdClass(); $this->assertInstanceOf( 'PhplxHelloWorld', $obj); } } 1999 - 2013 DRI. Some Rights Reserved . 17
  • 18. Use specific assertions - assertInstanceOf PHPUnit 3.7.28 by Sebastian Bergmann. [...] 1) InstanceOfTest::testTrue Failed asserting that false is true. 2) InstanceOfTest::testInstanceOf Failed asserting that stdClass Object () is an instance of class "PhplxHelloWorld". 1999 - 2013 DRI. Some Rights Reserved . 18
  • 19. Use specific assertions - JsonString <?php use PhplxObject; class JsonStringTest extends PHPUnit_Framework_TestCase { protected $jsonString = '{"someKey":"some thing","otherKey":"other thing"}'; public function testEquals(){ $obj = new Object(); $this->assertEquals( $this->jsonString, $obj->myPreciousJson()); } public function testJsonString(){ $obj = new Object(); $this->assertJsonStringEqualsJsonString( $this->jsonString, $obj->myPreciousJson()); } } 1999 - 2013 DRI. Some Rights Reserved . 19
  • 20. Use specific assertions - JsonString PHPUnit 3.7.28 by Sebastian Bergmann. [...] 1) JsonStringTest::testEquals Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'{"someKey":"some thing","otherKey":"other thing"}' +'{"someKey":"some value","otherKey":"other thing"}' 2) JsonStringTest::testJsonString Failed asserting that two objects are equal. --- Expected +++ Actual @@ @@ stdClass Object ( 'someKey' => 'some thing' + 'someKey' => 'some value' 'otherKey' => 'other thing' ) 1999 - 2013 DRI. Some Rights Reserved . 20
  • 21. Other PHPUnit topics Setup / Teardown ● Data providers ● Test doubles ● 1999 - 2013 DRI. Some Rights Reserved . 21
  • 22. The bug hunting work flow Gather information on the problem ● Reproduce the problem ● Capture that as a test ● Fix it (ok... this sometimes is hard) ● All green... mission accomplished ● 1999 - 2013 DRI. Some Rights Reserved . 22
  • 23. The community challenge Go to your favorite PHP project ● Or go to https://github.com/trending?l=php and pick one ● Fix Some Bugs! ● 1999 - 2013 DRI. Some Rights Reserved . 23
  • 25. QA Follow this topic: @rjsmelo, #phpunit Code: https://github.com/rjsmelo/talk-phpunit Feedback: https://joind.in/talk/view/10305