SlideShare une entreprise Scribd logo
1  sur  47
Télécharger pour lire hors ligne
Introducing

PHPSpec
A BDD Framework
Marcello Duarte
          @_md


PHPSpec Lead Developer
Head of Training @
Agile guy
What is PHPSpec?
 BDD Framework

 Created by Pádraic Brady

 DSL based on RSpec
BDD?
Behaviour Driven Development
BDD?
Better way to explain TDD
TDD?
Write a failing test
TDD?
       Write a failing test

Make it fail for the right reasons
TDD?
      Write a failing test
Make it fail for the right reasons

   Make it pass (just about)
TDD?
      Write a failing test
Make it fail for the right reasons
  Make it pass (just about)

            Refactor
TDD?
      Write a failing test
Make it fail for the right reasons
  Make it pass (just about)
             Refactor

           Start again
Focus on behaviour
Test


Specify
class CalculatorTest


      becomes
class DescribeCalculator
Test Case


Context
class CalculatorTest extends
   SomeTestFramework_TestCase


          becomes
class DescribeCalculator extends
         PHPSpec_Context
Test Method


 Example
testAddWithNoArguments()


         becomes
itReturnsZeroWithNoArguments()
Assert


Expect
$this->assertEquals(0, $result);


         becomes
    $result->should->be(0);
Installing
PEAR (soon...)

# pear channel-discover pear.phpspec.net
Adding Channel "pear.phpspec.net" succeeded
Discovery of channel "pear.phpspec.net" succeeded
# pear install --alldeps phpspec/PHPSpec-beta

GITHUB

$ git clone git://github.com/phpspec/phpspec.git
PHPSpec DSL
# StringCalculatorSpec.php
<?php

class DescribeStringCalculator
  extends PHPSpec_Context {

    public function itReturnsZeroWithNoArguments()
    {
        $result = $this->spec(StringCalculator::add());
        $result->should->be(0);
    }
}
$result->should->be(0)
$result->shouldNot->be(42)
Loads of matchers...
be($match)
         equal($match)
       beEqualTo($match)
    beAnInstanceOf($match)
           beEmpty()
           beFalse()
     beGreaterThan($match)
beGreaterThanOrEqualTo($match)
And more matchers...
beInteger()
    beLessThan($match)
beLessThanOrEqualTo($match)
         beNull()
        beString()
         beTrue()

       coming soon:
  throwException($match)
Predicate Matcher

           $cell = $this->spec(new Cell);
           $cell->should->beAlive();

class Cell
{
    protected $alive = true;

    public function isAlive() {
        return $this->alive;
    }
    ...
}
Predicate Matcher

           $newNode = $this->spec(new Node);
           $newNode->shouldNot->haveChildren();

class Node
{
    protected $children = array();

    public function hasChildren() {
        return count($this->children) > 0;
    }
    ...
}
Lets run our specs
# StringCalculatorSpec.php
<?php

class DescribeStringCalculator
  extends PHPSpec_Context {

    public function itReturnsZeroWithNoArgument()
    {
        $this->spec(StringCalculator::add())->should->be(0);
    }
}
Lets run our specs
$ phpspec StringCalculatorSpec.php -c
.

Finished in 0.055689 seconds

1 examples, 0 failures
Pending examples

public function itReturnsZeroWithAnEmptyString()
{
    $this->pending();
}
$ phpspec StringCalculatorSpec.php -c
.P

Pending:

1)
'string calculator returns zero with an empty
string' PENDING
Incomplete

Finished in 0.056134 seconds

2 examples, 0 failures, 1 pending
$
Failing examples

public function itReturnsTheBareNumber()
{
    $result = $this->spec(StringCalculator::add("42"));
    $result->should->be(42);
}
$ phpspec StringCalculatorSpec.php -c
.PF

Failures:

1)
'string calculator returns the bare number' FAILED
expected 42, got 0 (using be())
/Users/md/BDDTalk/StringCalculatorSpec.php:28

Pending:
...
Finished in 0.056134 seconds

3 examples, 1 failure, 1 pending
$
Deliberate fail

public function itReturnsTheBareNumber()
{
    $this->fail("An optional message");
}
Hooks


 before()
  after()
beforeAll()
afterAll()
set initial state

public function before()
{
    $this->calculator = new StringCalculator();
}
Mocks

               Phake
 https://github.com/mlively/Phake


              Mockery
https://github.com/padraic/Mockery
BDD Outside in
    Gherkin
    Behat

   PHPSpec
Feature: Learners Feedback
  In order to improve the quality of training
  As an learner
  I want to provide feedback for a course

  Scenario: Missed selecting the course
    Given I am on the feedback page
    And I skip selecting the course
    When submit the feedback
    Then I should be warned the feedback was not submitted

  Scenario: Thank you page
    Given I am on the feedback page
    And I fill all fields required
    When submit the feedback
    Then I should see a thank you message
$ pwd
/path/to/my/app
$ ls
features    src   spec
$ behat
Goutte


        Screen scraping
  Web crawling library for PHP
Goutte does not start the browser
// Create a Goutte Client
use GoutteClient;

$client = new Client();
// Make requests which returns a Crawler
$crawler = $client->request('GET', 'http://feedbackpage');.

//Click on links:
$link = $crawler->selectLink('Course')->link();
$crawler = $client->click($link);

// Submit forms:
$form = $crawler->selectButton('Submit Feedback')->form();
$crawler = $client->submit($form, array(
    'trainer' => 'Marcello Duarte',
    'course' => 'Agile PHP Developer'));

// Parse results
$error = $crawler->filter('.errors');
The BDD Cycle

         1. Write your stories

       2. Use Gherkin/Behat to
 describe the behaviour of your apps

          3. Use PHPSpec to
describe the behaviour of your classes
Thank you!


    Marcello Duarte
        @_md




is hiring. Come talk to me.

Contenu connexe

Tendances

November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2Kacper Gunia
 
PHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better CodePHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better CodeSWIFTotter Solutions
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Michelangelo van Dam
 
TDC2016SP - Trilha Developing for Business
TDC2016SP - Trilha Developing for BusinessTDC2016SP - Trilha Developing for Business
TDC2016SP - Trilha Developing for Businesstdc-globalcode
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowKacper Gunia
 
UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013Michelangelo van Dam
 
Xenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practicesXenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practicesLucas Jellema
 
PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016Britta Alex
 
PHP security audits
PHP security auditsPHP security audits
PHP security auditsDamien Seguy
 
Dependency Injection Smells
Dependency Injection SmellsDependency Injection Smells
Dependency Injection SmellsMatthias Noback
 
Back to basics - PHP_Codesniffer
Back to basics - PHP_CodesnifferBack to basics - PHP_Codesniffer
Back to basics - PHP_CodesnifferSebastian Marek
 
Automated code audits
Automated code auditsAutomated code audits
Automated code auditsDamien Seguy
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using CodeceptionJeroen van Dijk
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitmfrost503
 
Modernising Legacy Code
Modernising Legacy CodeModernising Legacy Code
Modernising Legacy CodeSamThePHPDev
 
Oracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional CompilationOracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional CompilationScott Wesley
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 

Tendances (20)

November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2
 
PHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better CodePHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better Code
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
TDC2016SP - Trilha Developing for Business
TDC2016SP - Trilha Developing for BusinessTDC2016SP - Trilha Developing for Business
TDC2016SP - Trilha Developing for Business
 
Developing for Business
Developing for BusinessDeveloping for Business
Developing for Business
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
 
UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013
 
Xenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practicesXenogenetics for PL/SQL - infusing with Java best practices
Xenogenetics for PL/SQL - infusing with Java best practices
 
PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016
 
PHP security audits
PHP security auditsPHP security audits
PHP security audits
 
Dependency Injection Smells
Dependency Injection SmellsDependency Injection Smells
Dependency Injection Smells
 
Back to basics - PHP_Codesniffer
Back to basics - PHP_CodesnifferBack to basics - PHP_Codesniffer
Back to basics - PHP_Codesniffer
 
Automated code audits
Automated code auditsAutomated code audits
Automated code audits
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using Codeception
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnit
 
Modernising Legacy Code
Modernising Legacy CodeModernising Legacy Code
Modernising Legacy Code
 
Let's Talk Scope
Let's Talk ScopeLet's Talk Scope
Let's Talk Scope
 
Oracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional CompilationOracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional Compilation
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 

Similaire à Introducing PHPSpec - A BDD Framework for PHP

Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsJagat Kothari
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosDivante
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxMichelangelo van Dam
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11Michelangelo van Dam
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricksFilip Golonka
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastMichelangelo van Dam
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2markstory
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Michelangelo van Dam
 
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
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Shinya Ohyanagi
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Michelangelo van Dam
 

Similaire à Introducing PHPSpec - A BDD Framework for PHP (20)

Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 
PHPUnit testing to Zend_Test
PHPUnit testing to Zend_TestPHPUnit testing to Zend_Test
PHPUnit testing to Zend_Test
 
Fatc
FatcFatc
Fatc
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricks
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfast
 
My Development Story
My Development StoryMy Development Story
My Development Story
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Zend Framework
Zend FrameworkZend Framework
Zend Framework
 

Plus de Marcello Duarte

Functional Structures in PHP
Functional Structures in PHPFunctional Structures in PHP
Functional Structures in PHPMarcello Duarte
 
Introducing Eager Design
Introducing Eager DesignIntroducing Eager Design
Introducing Eager DesignMarcello Duarte
 
Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015Marcello Duarte
 
Understanding craftsmanship
Understanding craftsmanshipUnderstanding craftsmanship
Understanding craftsmanshipMarcello Duarte
 
The framework as an implementation detail
The framework as an implementation detailThe framework as an implementation detail
The framework as an implementation detailMarcello Duarte
 
PhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examplesPhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examplesMarcello Duarte
 
Emergent design with phpspec
Emergent design with phpspecEmergent design with phpspec
Emergent design with phpspecMarcello Duarte
 
Pair Programming, TDD and other impractical things
Pair Programming, TDD and other impractical thingsPair Programming, TDD and other impractical things
Pair Programming, TDD and other impractical thingsMarcello Duarte
 
BDD For Zend Framework With PHPSpec
BDD For Zend Framework With PHPSpecBDD For Zend Framework With PHPSpec
BDD For Zend Framework With PHPSpecMarcello Duarte
 

Plus de Marcello Duarte (15)

Functional Structures in PHP
Functional Structures in PHPFunctional Structures in PHP
Functional Structures in PHP
 
Empathy from Agility
Empathy from AgilityEmpathy from Agility
Empathy from Agility
 
Introducing Eager Design
Introducing Eager DesignIntroducing Eager Design
Introducing Eager Design
 
Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015
 
Barely Enough Design
Barely Enough DesignBarely Enough Design
Barely Enough Design
 
Transitioning to Agile
Transitioning to AgileTransitioning to Agile
Transitioning to Agile
 
Understanding craftsmanship
Understanding craftsmanshipUnderstanding craftsmanship
Understanding craftsmanship
 
Hexagonal symfony
Hexagonal symfonyHexagonal symfony
Hexagonal symfony
 
The framework as an implementation detail
The framework as an implementation detailThe framework as an implementation detail
The framework as an implementation detail
 
PhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examplesPhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examples
 
Emergent design with phpspec
Emergent design with phpspecEmergent design with phpspec
Emergent design with phpspec
 
Mocking Demystified
Mocking DemystifiedMocking Demystified
Mocking Demystified
 
Pair Programming, TDD and other impractical things
Pair Programming, TDD and other impractical thingsPair Programming, TDD and other impractical things
Pair Programming, TDD and other impractical things
 
Deliberate practice
Deliberate practiceDeliberate practice
Deliberate practice
 
BDD For Zend Framework With PHPSpec
BDD For Zend Framework With PHPSpecBDD For Zend Framework With PHPSpec
BDD For Zend Framework With PHPSpec
 

Dernier

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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
 
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
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
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
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
[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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Dernier (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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...
 
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
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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?
 
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
 
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...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
[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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Introducing PHPSpec - A BDD Framework for PHP

  • 2. Marcello Duarte @_md PHPSpec Lead Developer Head of Training @ Agile guy
  • 3. What is PHPSpec? BDD Framework Created by Pádraic Brady DSL based on RSpec
  • 5. BDD? Better way to explain TDD
  • 7. TDD? Write a failing test Make it fail for the right reasons
  • 8. TDD? Write a failing test Make it fail for the right reasons Make it pass (just about)
  • 9. TDD? Write a failing test Make it fail for the right reasons Make it pass (just about) Refactor
  • 10. TDD? Write a failing test Make it fail for the right reasons Make it pass (just about) Refactor Start again
  • 13. class CalculatorTest becomes class DescribeCalculator
  • 15. class CalculatorTest extends SomeTestFramework_TestCase becomes class DescribeCalculator extends PHPSpec_Context
  • 17. testAddWithNoArguments() becomes itReturnsZeroWithNoArguments()
  • 19. $this->assertEquals(0, $result); becomes $result->should->be(0);
  • 20. Installing PEAR (soon...) # pear channel-discover pear.phpspec.net Adding Channel "pear.phpspec.net" succeeded Discovery of channel "pear.phpspec.net" succeeded # pear install --alldeps phpspec/PHPSpec-beta GITHUB $ git clone git://github.com/phpspec/phpspec.git
  • 21. PHPSpec DSL # StringCalculatorSpec.php <?php class DescribeStringCalculator extends PHPSpec_Context { public function itReturnsZeroWithNoArguments() { $result = $this->spec(StringCalculator::add()); $result->should->be(0); } }
  • 24. be($match) equal($match) beEqualTo($match) beAnInstanceOf($match) beEmpty() beFalse() beGreaterThan($match) beGreaterThanOrEqualTo($match)
  • 26. beInteger() beLessThan($match) beLessThanOrEqualTo($match) beNull() beString() beTrue() coming soon: throwException($match)
  • 27. Predicate Matcher $cell = $this->spec(new Cell); $cell->should->beAlive(); class Cell { protected $alive = true; public function isAlive() { return $this->alive; } ... }
  • 28. Predicate Matcher $newNode = $this->spec(new Node); $newNode->shouldNot->haveChildren(); class Node { protected $children = array(); public function hasChildren() { return count($this->children) > 0; } ... }
  • 29. Lets run our specs # StringCalculatorSpec.php <?php class DescribeStringCalculator extends PHPSpec_Context { public function itReturnsZeroWithNoArgument() { $this->spec(StringCalculator::add())->should->be(0); } }
  • 30. Lets run our specs $ phpspec StringCalculatorSpec.php -c . Finished in 0.055689 seconds 1 examples, 0 failures
  • 31. Pending examples public function itReturnsZeroWithAnEmptyString() { $this->pending(); }
  • 32. $ phpspec StringCalculatorSpec.php -c .P Pending: 1) 'string calculator returns zero with an empty string' PENDING Incomplete Finished in 0.056134 seconds 2 examples, 0 failures, 1 pending $
  • 33. Failing examples public function itReturnsTheBareNumber() { $result = $this->spec(StringCalculator::add("42")); $result->should->be(42); }
  • 34. $ phpspec StringCalculatorSpec.php -c .PF Failures: 1) 'string calculator returns the bare number' FAILED expected 42, got 0 (using be()) /Users/md/BDDTalk/StringCalculatorSpec.php:28 Pending: ... Finished in 0.056134 seconds 3 examples, 1 failure, 1 pending $
  • 35. Deliberate fail public function itReturnsTheBareNumber() { $this->fail("An optional message"); }
  • 36. Hooks before() after() beforeAll() afterAll()
  • 37. set initial state public function before() { $this->calculator = new StringCalculator(); }
  • 38. Mocks Phake https://github.com/mlively/Phake Mockery https://github.com/padraic/Mockery
  • 39. BDD Outside in Gherkin Behat PHPSpec
  • 40. Feature: Learners Feedback In order to improve the quality of training As an learner I want to provide feedback for a course Scenario: Missed selecting the course Given I am on the feedback page And I skip selecting the course When submit the feedback Then I should be warned the feedback was not submitted Scenario: Thank you page Given I am on the feedback page And I fill all fields required When submit the feedback Then I should see a thank you message
  • 42.
  • 43.
  • 44. Goutte Screen scraping Web crawling library for PHP Goutte does not start the browser
  • 45. // Create a Goutte Client use GoutteClient; $client = new Client(); // Make requests which returns a Crawler $crawler = $client->request('GET', 'http://feedbackpage');. //Click on links: $link = $crawler->selectLink('Course')->link(); $crawler = $client->click($link); // Submit forms: $form = $crawler->selectButton('Submit Feedback')->form(); $crawler = $client->submit($form, array( 'trainer' => 'Marcello Duarte', 'course' => 'Agile PHP Developer')); // Parse results $error = $crawler->filter('.errors');
  • 46. The BDD Cycle 1. Write your stories 2. Use Gherkin/Behat to describe the behaviour of your apps 3. Use PHPSpec to describe the behaviour of your classes
  • 47. Thank you! Marcello Duarte @_md is hiring. Come talk to me.