SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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)
 

Kürzlich hochgeladen

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - 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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Kürzlich hochgeladen (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - 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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

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