SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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)
 

Dernier

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Dernier (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

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