Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducción a BDD PHPdayUY 2015

Introducción a BDD PHPdayUY 2015

Charla de introducción a BDD en el primer PHPdayUY

Ismael Ambrosi

August 10, 2015
Tweet

More Decks by Ismael Ambrosi

Other Decks in Programming

Transcript

  1. ¿Quién Soy? 2 Ismael Ambrosi @iambrosi Frontend Developer en VividCortex

    Co-organizador meetup PHPmvd Co-organizador PHPdayUY (Fanático de PHP)
  2. BDD Es un conjunto de herramientas que nos ayuda a

    eliminar la distancia que hay entre los requerimientos definidos por el cliente y lo que el desarrollador entiende que debe hacerse. 6
  3. How Projects Really Work (version 1.5) Create your own cartoon

    at www.projectcartoon.com How the customer explained it How the project leader understood it How the analyst designed it How the programmer wrote it What the beta testers received How the business consultant described it How the project was documented What operations installed How the customer was billed How it was supported What marketing advertised What the customer really needed http://projectcartoon.com/pdf.php?CartoonID=2&PaperSize=A4
  4. Por lo general, los programadores no entendemos bien lo que

    el negocio realmente necesita, y a su vez el cliente no comprende lo que los programadores son capaces de hacer. 10
  5. Claves • Establecer una meta • Mapeo de impacto •

    Análisis de complejidad y valor • Planeamiento basado en ejemplos • Lenguaje obicuo • Desarrollo a través de ejemplos • Loop BDD 12
  6. El mapeo de impacto es una técnica de análisis del

    comportamiento del usuario que ayuda de desarrollar las diferentes formas de alcanzar las meta establecida. 16
  7. Visualiza el porqué los features son importantes y necesarios, y

    el comportamiento requerido para lograr la meta. 17
  8. El análisis del valor nos ayuda a identificar los features

    de bajo costo pero de alto valor en una lista de requisitos. 19
  9. El análisis de complejidad nos ayuda a encontrar el camino

    correcto para el desarrollo y colaboración del proyecto completo. 20
  10. Por lo general, los programadores no entendemos bien lo que

    el negocio realmente necesita, y a su vez el cliente no comprende lo que los programadores son capaces de hacer. 22
  11. Es usado y desarrollado por todos los miembros del equipo

    para poder discutir sobre las características y crear ejemplos efectivos. 29
  12. Given: describe el contexto inicial del ejemplo. When: describe la

    acción ejecutada por el usuario en el sistema. Then: describe el resultado esperado luego de ejecutada la acción. 31
  13. E l d e s a r r o l

    l o b a s a d o e n l a automatización de escenarios no es suficiente. 38
  14. Posible escenario Dado que en mi cuenta tengo $1000, cuando

    retiro del cajero automático $800, entonces en mi cuenta quedan $200. 49
  15. Dado que en mi cuenta tengo $1000, cuando retiro del

    cajero automático $800, entonces en mi cuenta quedan $200. 50
  16. Dado que en mi cuenta tengo $1000, cuando retiro del

    cajero automático $800, entonces en mi cuenta quedan $200. 51
  17. Dado que en mi cuenta tengo $1000, cuando retiro del

    cajero automático $800, entonces en mi cuenta quedan $200. 52
  18. Feature: Managing my bank account
 
 In order to access

    and manage my bank account
 As a bank customer
 I should be able to withdraw and deposit money into my account
 
 Scenario: Successful fund withdraw
 Given there are $1000 on my bank account
 When I withdraw $800 from the account
 Then I should have $200 remaining 54
  19. Feature: Managing my bank account
 
 In order to access

    and manage my bank account
 As a bank customer
 I should be able to withdraw and deposit money into my account
 
 Scenario: Successful fund withdraw
 Given there are $1000 on my bank account
 When I withdraw $800 from the account
 Then I should have $200 remaining 55 Gherkin
  20. Feature: Managing my bank account
 
 In order to access

    and manage my bank account
 As a bank customer
 I should be able to withdraw and deposit money into my account
 
 Scenario: Successful fund withdraw
 Given there are $1000 on my bank account
 When I withdraw $800 from the account
 Then I should have $200 remaining 60
  21. use Behat\Behat\Context\Context;
 
 /**
 * Defines application features from the

    specific context.
 */
 class FeatureContext implements Context
 {
 /**
 * @Given /^there are (\$[\d]+) on my bank account$/
 */
 public function thereAreOnMyBankAccount($total)
 {
 // ...
 }
 
 /**
 * @When /^I withdraw (\$[\d]+) from the account$/
 */
 public function iWithdrawFromTheAccount($amount)
 {
 // ...
 }
 
 /**
 * @Then /^I should have (\$[\d]+) left$/
 */
 public function iShouldHaveLeft($remaining)
 {
 // ...
 }
 } 63
  22. /**
 * @Given /^there are (\$[\d]+) on my bank account$/


    * @param double $total
 */
 public function thereAreOnMyBankAccount($total)
 {
 $this->bankAccount->setTotal($total);
 } 65
  23. /**
 * @When /^I withdraw (\$[\d]+) from the account$/
 *

    @param double $amount
 */
 public function iWithdrawFromTheAccount($amount)
 {
 $this->bankAccount->withdraw($amount);
 } 66
  24. /**
 * @Then /^I should have (\$[\d]+) left$/
 * @param

    double $remaining
 */
 public function iShouldHaveLeft($remaining)
 {
 assertEquals($remaining, $this->bankAccount->getTotal());
 } 67
  25. $ ./vendor/bin/behat Feature: Managing my bank account In order to

    access and manage my bank account As a bank customer I should be able to withdraw and deposit money into my account Scenario: Successful fund withdraw # features/account.feature:7 Given there are $1000 on my bank account # FeatureContext::thereAreOnMyBankAccount() When I withdraw $800 from the account # FeatureContext::iWithdrawFromTheAccount() Then I should have $200 left # FeatureContext::iShouldHaveLeft() 1 scenario (1 passed) 3 steps (3 passed) 0m0.02s (11.21Mb) 68
  26. /**
 * @Given /^there are (\$[\d]+) on my bank account$/


    * @param double $total
 */
 public function thereAreOnMyBankAccount($total)
 {
 $this->bankAccount->setTotal($total);
 } 70
  27. /**
 * @When /^I withdraw (\$[\d]+) from the account$/
 *

    @param double $amount
 */
 public function iWithdrawFromTheAccount($amount)
 {
 $this->visit('/account/withdraw');
 
 $amountElement = $this->find('css', 'input#amount');
 $amountElement->setValue($amount);
 
 $button = $this->find('css', 'submit');
 $button->click();
 } 71
  28. /**
 * @Then /^I should have (\$[\d]+) left$/
 * @param

    double $remaining
 */
 public function iShouldHaveLeft($remaining)
 {
 $this->visit('/account');
 
 $this->assertElementContainsText('.balance .total', $remaining);
 } 72
  29. namespace spec;
 
 use PhpSpec\ObjectBehavior;
 use Prophecy\Argument;
 
 class MarkdownSpec

    extends ObjectBehavior
 {
 function it_is_initializable()
 {
 $this->shouldHaveType('Markdown');
 }
 } 79
  30. namespace spec;
 
 use PhpSpec\ObjectBehavior;
 
 class MarkdownSpec extends ObjectBehavior


    {
 function it_converts_plain_text_to_html_paragraphs()
 {
 $this->toHtml("Hi, there")->shouldReturn("<p>Hi, there</p>");
 }
 } 80
  31. $ bin/phpspec run > spec\Markdown ✔ it converts plain text

    to html paragraphs 1 examples (1 passed) 247ms 82