SlideShare una empresa de Scribd logo
Desarrollo guiado por comportamiento (BDD)
       con Symfony2, Behat y Mink – Carlos Granados




Carlos Granados
Desarrollo guiado por comportamiento (BDD)
con Symfony2, Behat y Mink – Carlos Granados
Desarrollo guiado por comportamiento (BDD)
con Symfony2, Behat y Mink – Carlos Granados
Desarrollo guiado por comportamiento (BDD)
con Symfony2, Behat y Mink – Carlos Granados
Desarrollo guiado por comportamiento (BDD)
                     con Symfony2, Behat y Mink – Carlos Granados




¿Qué es BDD?

•   Desarrollo basado en comportamiento
                           funcionalidad
•   Pasar tests != funcionalidad conseguida
•   Historias en lenguaje natural y compartido
•   Lenguaje definido y automatizable
•   Las historias dirigen nuestro desarrollo
•   Podemos comprobar la funcionalidad
Desarrollo guiado por comportamiento (BDD)
                      con Symfony2, Behat y Mink – Carlos Granados




Historias (Stories)

•   Características (Features)
•   As a [role] I want [feature] so that [benefit]
•   Escenarios (Scenarios) y pasos (Steps)
•   Precondiciones (Given …)
•   Acciones (When…)
•   Resultados (Then…)
Desarrollo guiado por comportamiento (BDD)
                        con Symfony2, Behat y Mink – Carlos Granados



Feature: Account Holder withdraws cash
As an Account Holder
I want to withdraw cash from an ATM
So that I can get money when the bank is closed

Scenario 1: Account has sufficient funds
Given the account balance is 100€
  And the card is valid
  And the machine contains enough money
 When the Account Holder inserts the card
  And the Account Holder requests 20€
 Then the ATM should dispense 20€
  And the account balance should be 80€
  And the card should be returned

Scenario 2: ...
Desarrollo guiado por comportamiento (BDD)
                    con Symfony2, Behat y Mink – Carlos Granados




Gherkin

•   El lenguaje de cucumber
•   Lenguaje natural y comprensible
•   Lenguaje específico y definido
•   Lenguaje automatizable
•   Similar a YAML
•   Ficheros .feature
Desarrollo guiado por comportamiento (BDD)
                    con Symfony2, Behat y Mink – Carlos Granados




Behat

•   BDD para php
•   Inspirado por cucumber
•   Herramienta de línea de comandos
•   Disponible en varios idiomas
•   Más información en http://behat.org
Desarrollo guiado por comportamiento (BDD)
                          con Symfony2, Behat y Mink – Carlos Granados



#features/atm.feature
Feature: Account Holder withdraws cash
As an Account Holder
I want to withdraw cash from an ATM
So that I can get money when the bank is closed

Scenario:   Account has sufficient funds
Given the   account balance is 100€
  And the   card is valid
  And the   machine contains enough money
 When the   Account Holder inserts the card
  And the   Account Holder requests 20€
 Then the   ATM should dispense 20€
  And the   account balance should be 80€
  And the   card should be returned

Scenario: ...
Desarrollo guiado por comportamiento (BDD)
                                   con Symfony2, Behat y Mink – Carlos Granados



$ behat
Feature: Account Holder withdraws cash
As an Account Holder
I want to withdraw cash from an ATM
So that I can get money when the bank is closed

Scenario 1: Account has sufficient funds #features/atm.feature:7
Given the account balance is 100€
 ...
1 scenario ( 1 undefined)
8 steps (8 undefined)
You can implement undefined steps with these code snippets:

/**
 * @Given /^the account balance is (d+)€$/
 */
public function theAccountBalanceIs($argument1)
{
    throw new PendingException();
}
...
Desarrollo guiado por comportamiento (BDD)
                               con Symfony2, Behat y Mink – Carlos Granados




// features/bootstrap/FeatureContext.php
<?php

use BehatBehatContextBehatContext,
    BehatBehatExceptionPendingException;

class FeatureContext extends BehatContext
{
    /**
     * @Given /^the account balance is (d+)€$/
     */
    public function theAccountBalanceIs ($argument1)
    {
        throw new PendingException ();
    }
}
Desarrollo guiado por comportamiento (BDD)
                               con Symfony2, Behat y Mink – Carlos Granados




// features/bootstrap/FeatureContext.php
<?php

use BehatBehatContextBehatContext,
    BehatBehatExceptionPendingException;

class FeatureContext extends BehatContext
{
    /**
     * @Given /^(?:|the )account balance is (d+)€$/
     */
    public function setAccountBalance ($balance)
    {
        $user = $this->getContainer()->getUser();
        $account = $user->getAccount();
        $account->setBalance($balance);
    }
}
Desarrollo guiado por comportamiento (BDD)
                                     con Symfony2, Behat y Mink – Carlos Granados



$ behat
Feature: Account Holder withdraws cash
As an Account Holder
I want to withdraw cash from an ATM
So that I can get money when the bank is closed

Scenario 1: Account has sufficient funds #features/atm.feature:7
Given the account balance is 100€        #featureContext::setAccountBalance()
...
1 scenario (1 pased)
8 steps (8 passed)
Desarrollo guiado por comportamiento (BDD)
                               con Symfony2, Behat y Mink – Carlos Granados




/**
 * @Then /^(?:|The )account balance should be (d+)€$/
 */
public function checkAccountBalance ($balance)
{
    $user = $this->getContainer()->getUser();

    $account = $user->getAccount();

    if ($account->getBalance()!=$balance) {
        throw new Exception(
            'Actual balance is '.$account->getBalance().
            '€ instead of '.$balance.'€';
        );
    }
}
Desarrollo guiado por comportamiento (BDD)
                                       con Symfony2, Behat y Mink – Carlos Granados



$ behat
Feature: Account Holder withdraws cash
As an Account Holder
I want to withdraw cash from an ATM
So that I can get money when the bank is closed

Scenario 1: Account has sufficient funds #features/atm.feature:7
...
And the account balance should be 80€    #featureContext::checkAccountBalance()
    Actual balance is 100€ instead of 80€
And the card should be returned           #featureContext::isCardReturned()
...
1 scenario (1 pased)
8 steps (6 passed, 1 skipped, 1 failed)
Desarrollo guiado por comportamiento (BDD)
                               con Symfony2, Behat y Mink – Carlos Granados




require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';

...

/**
 * @Then /^(?:|the )account balance should be (d+)€$/
 */
public function checkAccountBalance ($balance)
{
    $user = $this->getContainer()->getUser();
    $account = $user->getAccount();
    assertEquals($account->getBalance(), $balance);
}
Desarrollo guiado por comportamiento (BDD)
                          con Symfony2, Behat y Mink – Carlos Granados



...

Scenario:   Account has insufficient funds
Given the   account balance is 10€
  And the   card is valid
  And the   machine contains enough money
 When the   Account Holder inserts the card
  And the   Account Holder requests 20€
 Then the   ATM should not dispense any money
  And the   ATM should print "Insuficient funds"
  And the   account balance should be 10€
  And the   card should be returned

Scenario: ...
Desarrollo guiado por comportamiento (BDD)
                               con Symfony2, Behat y Mink – Carlos Granados




Then the account balance should be 20€
/**
 * @Then /^the account balance should be (d+)€$/
 */


Then the ATM should print "Insuficient funds"
/**
 * @Then /^the ATM should print "([^"]*)"$/
 */
Desarrollo guiado por comportamiento (BDD)
                               con Symfony2, Behat y Mink – Carlos Granados




Scenario: ...
Given the following users exist:
    | name | email            | phone      |
    | Aslak | aslak@email.com | 123        |
    | Joe   | joe@email.com   | 234        |
    | Bryan | bryan@email.org | 456        |

/**
* @Given /the following users exist:/
*/
public function insertUsers(TableNode $table)
{
    $hash = $table->getHash();
    foreach ($hash as $row) {
        $user = new User($row['name'], $row['email'], $row['phone']);
        $this->database->insert($user);
    }
}
Desarrollo guiado por comportamiento (BDD)
                        con Symfony2, Behat y Mink – Carlos Granados



Scenario: Eat 5 out of 12
  Given there are 12 cucumbers
   When I eat 5 cucumbers
   Then I should have 7 cucumbers

Scenario: Eat 5 out of 20
  Given there are 20 cucumbers
   When I eat 5 cucumbers
   Then I should have 15 cucumbers

Scenario: Eat 5 out of 5
  Given there are 5 cucumbers
   When I eat 5 cucumbers
   Then I should have 0 cucumbers
Desarrollo guiado por comportamiento (BDD)
                         con Symfony2, Behat y Mink – Carlos Granados



Scenario Outline: Eat cucumbers
  Given there are <start> cucumbers
   When I eat <eat> cucumbers
   Then I should have <left> cucumbers

 Examples:
   | start   | eat | left |
   | 12      | 5 |     7 |
   | 20      | 5 | 15 |
   |   5     | 5 |     0 |
Desarrollo guiado por comportamiento (BDD)
                              con Symfony2, Behat y Mink – Carlos Granados



Background:
Given the following users exist:
    | name | email            | phone              |
    | Aslak | aslak@email.com | 123                |
    | Joe   | joe@email.com   | 234                |
    | Bryan | bryan@email.org | 456                |

Scenario:...

Scenario:...



Hooks: http://docs.behat.org/guides/3.hooks.html
Desarrollo guiado por comportamiento (BDD)
                               con Symfony2, Behat y Mink – Carlos Granados



/**
 * @Then /^there should be no money in the account$/
 */
public function checkEmptyAccount ()
{
    return new Then('the account balance should be 0€');
}


/**
 * @When /^the user eats and sleeps$/
 */
public function userEatsAndSleeps ()
{
    return array(
        new When("the user eats"),
        new When("the user sleeps"),
    );
}
Desarrollo guiado por comportamiento (BDD)
                          con Symfony2, Behat y Mink – Carlos Granados




Behat en Symfony2: BehatBundle

//deps
[gherkin]
    git=https://github.com/Behat/Gherkin.git
    target=/behat/gherkin

[behat]
    git=https://github.com/Behat/Behat.git
    target=/behat/behat

[BehatBundle]
    git=https://github.com/Behat/BehatBundle.git
    target=/bundles/Behat/BehatBundle
Desarrollo guiado por comportamiento (BDD)
                                con Symfony2, Behat y Mink – Carlos Granados



//app/autoload.php
$loader->registerNamespaces(array(
    // ..

      'BehatGherkin'     => __DIR__.'/../vendor/behat/gherkin/src',
      'BehatBehat'       => __DIR__.'/../vendor/behat/behat/src',
      'BehatBehatBundle' => __DIR__.'/../vendor/bundles',
));

//app/AppKernel.php
public function registerBundles()
{
    // ..

      if ('test' === $this->getEnvironment()) {
          $bundles[] = new BehatBehatBundleBehatBundle();
      }
}
Desarrollo guiado por comportamiento (BDD)
                            con Symfony2, Behat y Mink – Carlos Granados




$ app/console -e=test behat --init @AcmeDemoBundle

+Acme
    +DemoBundle
        +...
        +Features
            +Context
                -FeatureContext.php
       +...
Desarrollo guiado por comportamiento (BDD)
                              con Symfony2, Behat y Mink – Carlos Granados



//Acme/DemoBundle/Features/Context/FeatureContext.php
<?php
namespace AcmeDemoBundleFeaturesContext;

use BehatBehatBundleContextBehatContext;

class FeatureContext extends BehatContext
{
    /**
     * @Given /I have a product "([^"]*)"/
     */
    public function insertProduct($name)
    {
        $em = $this->getContainer()->get('doctrine')
              ->getEntityManager();
        $product = new AcmeDemoBundleEntityProduct();
        $product->setName($name);
        $em->persist($product);
        $em->flush();
    }
}
Desarrollo guiado por comportamiento (BDD)
                          con Symfony2, Behat y Mink – Carlos Granados




BDD en Symfony2: ejecutar tests

$ app/console –e=test behat @AcmeDemoBundle
Desarrollo guiado por comportamiento (BDD)
                    con Symfony2, Behat y Mink – Carlos Granados




Pruebas de funcionalidad web: Mink

•   Librería php integrada con behat
•   Permite usar distintos Browser emulators
•   Controlar el Navegador
•   Recorrer la Página
•   Manipular la Página
•   Simular la interacción del Usuario
•   Interface común para todos los emuladores
Desarrollo guiado por comportamiento (BDD)
                   con Symfony2, Behat y Mink – Carlos Granados




Tipos de Browser emulators:
• Emuladores Headless Browsers
  • Symfony Web Client
  • Goutte
• Emuladores Browser controllers
  • Selenium
  • Sahi
• Mixtos: Zombie.js
Desarrollo guiado por comportamiento (BDD)
                              con Symfony2, Behat y Mink – Carlos Granados




Controlar el Navegador
// iniciar driver:
$driver = new BehatMinkDriverGoutteDriver();

// iniciar sesión:
$session = new BehatMinkSession($driver);

// arrancar sesión:
$session->start();

// abrir una página en el navegador:
$session->visit('http://my_project.com/some_page.php');

// obtener el código de respuesta:
echo $session->getStatusCode();

// obtener el contenido de la página:
echo $session->getPage()->getContent();
Desarrollo guiado por comportamiento (BDD)
                              con Symfony2, Behat y Mink – Carlos Granados



// utilizar la historia del navegador:
$session->reload();
$session->back();
$session->forward();

// evaluar expresión Javascript:
echo $session->evaluateScript(
    "(function(){ return 'something from browser'; })()"
);

// obtener los headers:
print_r($session->getResponseHeaders());

// guardar cookie:
$session->setCookie('cookie name', 'value');

// obtener cookie:
echo $session->getCookie('cookie name');
Desarrollo guiado por comportamiento (BDD)
                              con Symfony2, Behat y Mink – Carlos Granados




Recorrer la Página: selectors
//xpath selector
$handler = new BehatMinkSelectorSelectorsHandler();
$xpath = $handler->selectorToXpath('xpath', '//html');

//css selector
$selector = new BehatMinkSelectorCssSelector();
$xpath = $selector->translateToXPath('#ID');

//named selectors
$selector = new BehatMinkSelectorNamedSelector();
$xpath = $selector->translateToXPath(
    array('field', 'id|name|value|label')
);

//named selectors: link, button, content, select, checkbox
//radio, file, optgroup, option, table
Desarrollo guiado por comportamiento (BDD)
                               con Symfony2, Behat y Mink – Carlos Granados




Recorrer la Página: obtener elementos
//obtengo la página
$page = $session->getPage();

//encuentro un elemento
$element = $page->find('xpath', '//body');

//encuentro todos los elementos
$elementsByCss = $page->findAll('css', '.classname');

//encuentro un elemento por su Id
$element = $page->findById('ID');

//encuentro elementos con named selectors
$link = $page->findLink('href');
$button = $page->findButton('name');
$field = $page->findField('id');
Desarrollo guiado por comportamiento (BDD)
                                con Symfony2, Behat y Mink – Carlos Granados




Manipular la Página: Node Elements
//obtengo un elemento
$el = $page->find('css', '.something');

// obtengo el nombre del tag:
echo $el->getTagName();

// compruebo si tiene un atributo:
$el->hasAttribute('href');

// obtengo un atributo:
echo $el->getAttribute('href');

//obtengo el texto
$plainText = $el->getText();

//obtengo el html
$html = $el->getHtml();
Desarrollo guiado por comportamiento (BDD)
                                con Symfony2, Behat y Mink – Carlos Granados




Manipular la Página: Form fields
// marcar/desmarcar checkbox:
if ($el->isChecked()) {
    $el->uncheck();
}
$el->check();

// elegir option en select:
$el->selectOption('optin value');

// añadir un fichero:
$el->attachFile('/path/to/file');

// obtener el valor:
echo $el->getValue();

// poner un valor:
$el->setValue('some val');
Desarrollo guiado por comportamiento (BDD)
                      con Symfony2, Behat y Mink – Carlos Granados




Simular la interacción del Usuario
// pulsar un botón:
$el->press();

//simular el ratón
$el->click();
$el->doubleClick();
$el->rightClick();
$el->mouseOver();
$el->focus();
$el->blur();

//Hacer drag'n'drop
$el1->dragTo($el2);
Desarrollo guiado por comportamiento (BDD)
                              con Symfony2, Behat y Mink – Carlos Granados




Integración con Behat: MinkContext
// features/bootstrap/FeatureContext.php

use BehatMinkBehatContextMinkContext;

class FeatureContext extends MinkContext
{
    /**
     * @Then /^I press the submit button$/
     */
    public function PressSubmitButton()
    {
        $page = $this->getSession()->getPage();
        $button = $page->findButton('submit');
        $button->press();
    }
}
Desarrollo guiado por comportamiento (BDD)
                              con Symfony2, Behat y Mink – Carlos Granados




Steps predefinidos: Given/When
Given   I   am on "URL"
 When   I   go to "url"
 When   I   reload the page
 When   I   move backward one page
 When   I   move forward one page
 When   I   press "button"
 When   I   follow "link"
 When   I   fill in "field" with "value"
 When   I   fill in "value" for "field"
 When   I   fill in the following:
 When   I   select "option" from "select"
 When   I   additionally select "option" from "select"
 When   I   check "option"
 When   I   uncheck "option"
 When   I   attach the file "path" to "field"
Desarrollo guiado por comportamiento (BDD)
                            con Symfony2, Behat y Mink – Carlos Granados




Steps predefinidos: Then
Then   I should be on "page"
Then   the url should match "pattern"
Then   the response status code should be "code"
Then   the response status code should not be "code"
Then   I should see "text"
Then   I should not see "text"
Then   I should see "text" in the "element" element
Then   the "element" element should contain "value"
Then   I should see an "element" element
Then   I should not see an "element" element
Then   the "field" field should contain "value"
Then   the "field" field should not contain "value"
Then   the "checkbox" checkbox should be checked
Then   the "checkbox" checkbox should not be checked
Then   I should see "num" "element" elements
Then   print last response
Desarrollo guiado por comportamiento (BDD)
                             con Symfony2, Behat y Mink – Carlos Granados



# features/search.feature
Feature: Search
  In order to see a word definition
  As a website user
  I need to be able to search for a word

 Scenario:   Searching for a page that does exist
   Given I   am on "/wiki/Main_Page"
    When I   fill in "search" with "Behavior Driven Development"
     And I   press "searchButton"
    Then I   should see "agile software development"

 Scenario:   Searching for a page that does NOT exist
   Given I   am on "/wiki/Main_Page"
    When I   fill in "search" with "Glory Driven Development"
     And I   press "searchButton"
    Then I   should see “No results found"
Desarrollo guiado por comportamiento (BDD)
                              con Symfony2, Behat y Mink – Carlos Granados




/**
 * @Given /^I am on the main page$/
 */
public function goToMainPage()
{
    return new Given('I am on "/wiki/Main_Page"');
}


/**
 * @Then /^I press the search button$/
 */
public function pressSearchButton()
{
    return new Then('I press "searchButton"');
}
Desarrollo guiado por comportamiento (BDD)
                          con Symfony2, Behat y Mink – Carlos Granados




Mink en Symfony2: MinkBundle

//deps
[mink]
    git=https://github.com/Behat/Mink.git
    target=/behat/mink

[MinkBundle]
    git=https://github.com/Behat/MinkBundle.git
    target=/bundles/Behat/MinkBundle
Desarrollo guiado por comportamiento (BDD)
                                con Symfony2, Behat y Mink – Carlos Granados



//app/autoload.php
$loader->registerNamespaces(array(
    // ..

      'BehatMink'       => __DIR__.'/../vendor/behat/mink/src',
      'BehatMinkBundle' => __DIR__.'/../vendor/bundles',
));


//app/AppKernel.php
public function registerBundles()
{
    // ..

      if ('test' === $this->getEnvironment()) {
          $bundles[] = new BehatBehatBundleBehatBundle();
          $bundles[] = new BehatMinkBundleMinkBundle();
      }
}
Desarrollo guiado por comportamiento (BDD)
                              con Symfony2, Behat y Mink – Carlos Granados



#app/config/config_test.yml
mink:
    base_url:   http://localhost/app_test.php
    browser_name: chrome
    goutte:     ~
    sahi:       ~
    zombie:     ~
Desarrollo guiado por comportamiento (BDD)
                              con Symfony2, Behat y Mink – Carlos Granados



//web/app_test.php
if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
    '127.0.0.1',
    '::1',
))) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check
'.basename(__FILE__).' for more information.');
}

require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';

use SymfonyComponentHttpFoundationRequest;

$kernel = new AppKernel('test', true);
$kernel->loadClassCache();
$kernel->handle(Request::createFromGlobals())->send();
Desarrollo guiado por comportamiento (BDD)
                              con Symfony2, Behat y Mink – Carlos Granados


namespace AcmeDemoBundleFeaturesContext;

use BehatMinkBundleContextMinkContext;

class FeatureContext extends MinkContext
{
    /**
     * @When /^I go to the user account page$/
     */
    public function showUserAccount()
    {
        $user = $this->getContainer()->get('security.context')
               ->getToken()->getUser();
        $session = $this->getSession();
        $session->visit('/account/'. $user->getSlug());
    }
}
Desarrollo guiado por comportamiento (BDD)
                             con Symfony2, Behat y Mink – Carlos Granados




 Qué Driver usar

# symfony driver (default)
@mink:symfony
Scenario: ...

# goutte driver
@mink:goutte
Scenario: ...

# sahi driver
@mink:sahi o @javascript
Scenario: ...

# zombie.js driver
@mink:zombie
Scenario: ...
Desarrollo guiado por comportamiento (BDD)
                                con Symfony2, Behat y Mink – Carlos Granados




Trucos: Salida de Behat
app/console -e=test behat -f pretty,junit --out ,. @AcmeDemoBundle
Desarrollo guiado por comportamiento (BDD)
                                con Symfony2, Behat y Mink – Carlos Granados




Trucos: repetir Tests
app/console -e=test behat --rerun="re.run" @AcmeDemoBundle
Desarrollo guiado por comportamiento (BDD)
                  con Symfony2, Behat y Mink – Carlos Granados




BDD vs TDD

• BDD es TDD

BDD vs UnitTesting
• Unit testing comprueba unidades
• BDD comprueba funcionalidad
Desarrollo guiado por comportamiento (BDD)
                    con Symfony2, Behat y Mink – Carlos Granados




Stop Press!!! Behat 2.4

• BehatBundle y MinkBundle deprecated
• Usar MinkExtension y Symfony2Extension
• Más info en http://behat.org
Desarrollo guiado por comportamiento (BDD)
                          con Symfony2, Behat y Mink – Carlos Granados




//deps
[mink]
    git=https://github.com/Behat/Mink.git
    target=/behat/mink
    version=v1.3.3

[gherkin]
    git=https://github.com/Behat/Gherkin.git
    target=/behat/gherkin
    version=v2.1.1

[behat]
    git=https://github.com/Behat/Behat.git
    target=/behat/behat
    version=v2.3.5
Desarrollo guiado por comportamiento (BDD)
                    con Symfony2, Behat y Mink – Carlos Granados




          ¡¡Gracias!!
                ¿Preguntas?

• carlos@planetapluton.com
• @carlos_granados
• http://es.linkedin.com/in/carlosgranados

Más contenido relacionado

Último

CODIGO FISCAL DE LA FEDERACION 2024 ACTUALIZADO
CODIGO FISCAL DE LA FEDERACION 2024 ACTUALIZADOCODIGO FISCAL DE LA FEDERACION 2024 ACTUALIZADO
CODIGO FISCAL DE LA FEDERACION 2024 ACTUALIZADO
ARACELYMUOZ14
 
TRABAJO DE EXPOSICIÓN CASO URUBO GUENDAA
TRABAJO DE EXPOSICIÓN CASO URUBO GUENDAATRABAJO DE EXPOSICIÓN CASO URUBO GUENDAA
TRABAJO DE EXPOSICIÓN CASO URUBO GUENDAA
AnglicaDuranRueda
 
anualidades anticipadas y diferidas .pptx
anualidades anticipadas y diferidas .pptxanualidades anticipadas y diferidas .pptx
anualidades anticipadas y diferidas .pptx
J. ALFREDO TORRES G
 
Planificación de Ecuador y sus respectivas zonas
Planificación de Ecuador y sus respectivas zonasPlanificación de Ecuador y sus respectivas zonas
Planificación de Ecuador y sus respectivas zonas
MarioBenedetti13
 
ANALISIS-FINANCIERO.ppt xxxxxxxxxxxxxxxxx
ANALISIS-FINANCIERO.ppt xxxxxxxxxxxxxxxxxANALISIS-FINANCIERO.ppt xxxxxxxxxxxxxxxxx
ANALISIS-FINANCIERO.ppt xxxxxxxxxxxxxxxxx
jesus ruben Cueto Sequeira
 
normas de informacion financiera nif b-8 y nif b-7
normas de informacion financiera nif b-8 y nif b-7normas de informacion financiera nif b-8 y nif b-7
normas de informacion financiera nif b-8 y nif b-7
AARONULISES1
 
BBSC® Impuesto Sustitutivo 2024 Ley de Emergencia
BBSC® Impuesto Sustitutivo 2024 Ley de EmergenciaBBSC® Impuesto Sustitutivo 2024 Ley de Emergencia
BBSC® Impuesto Sustitutivo 2024 Ley de Emergencia
Claudia Valdés Muñoz
 
Teoria de la produccion, conceptos generales
Teoria de la produccion, conceptos generalesTeoria de la produccion, conceptos generales
Teoria de la produccion, conceptos generales
JimenaRamirez69
 
EL MERCADO LABORAL EN EL SEMESTRE EUROPEO. COMPARATIVA.
EL MERCADO LABORAL EN EL SEMESTRE EUROPEO. COMPARATIVA.EL MERCADO LABORAL EN EL SEMESTRE EUROPEO. COMPARATIVA.
EL MERCADO LABORAL EN EL SEMESTRE EUROPEO. COMPARATIVA.
ManfredNolte
 
Documentación comercial y contable para contadores
Documentación comercial y contable para contadoresDocumentación comercial y contable para contadores
Documentación comercial y contable para contadores
JeanpaulFredyChavezM
 
FUNDAMENTOS DE FINANZAS EMPRESARIALES. CLASE 1.pdf
FUNDAMENTOS DE FINANZAS EMPRESARIALES. CLASE 1.pdfFUNDAMENTOS DE FINANZAS EMPRESARIALES. CLASE 1.pdf
FUNDAMENTOS DE FINANZAS EMPRESARIALES. CLASE 1.pdf
javierturo
 
Análisis de negocios internacionales aplicado a moda y estilo
Análisis de negocios internacionales aplicado a moda y estiloAnálisis de negocios internacionales aplicado a moda y estilo
Análisis de negocios internacionales aplicado a moda y estilo
SebastinFloresAyquip
 
CIRCULACIÓN DE LOS TÍTULOS DE CRÉDITO.pptx
CIRCULACIÓN DE LOS TÍTULOS DE CRÉDITO.pptxCIRCULACIÓN DE LOS TÍTULOS DE CRÉDITO.pptx
CIRCULACIÓN DE LOS TÍTULOS DE CRÉDITO.pptx
NatyOrtiz16
 
Tiens internacional corporativo V-MOMENT.pptx
Tiens internacional corporativo V-MOMENT.pptxTiens internacional corporativo V-MOMENT.pptx
Tiens internacional corporativo V-MOMENT.pptx
AlexanderLlanos10
 
Economía Informal en el Perú:Situación actual y perspectivas .pdf
Economía Informal en el Perú:Situación actual y perspectivas .pdfEconomía Informal en el Perú:Situación actual y perspectivas .pdf
Economía Informal en el Perú:Situación actual y perspectivas .pdf
nelllalita3
 
SINU-153_Material de reforzamiento U5.docx
SINU-153_Material de reforzamiento U5.docxSINU-153_Material de reforzamiento U5.docx
SINU-153_Material de reforzamiento U5.docx
SamyrAntonioTafurRoj
 
Unidad I Generalidades de la Contabilidad.pdf
Unidad I Generalidades de la Contabilidad.pdfUnidad I Generalidades de la Contabilidad.pdf
Unidad I Generalidades de la Contabilidad.pdf
TatianaPoveda12
 
cuadro comparativo de la Venezuela productiva
cuadro comparativo de la Venezuela productivacuadro comparativo de la Venezuela productiva
cuadro comparativo de la Venezuela productiva
tomas191089
 
Conceptos básicos del gasto de gobierno en Bolivia
Conceptos básicos del gasto de gobierno en BoliviaConceptos básicos del gasto de gobierno en Bolivia
Conceptos básicos del gasto de gobierno en Bolivia
Claudia Quisbert
 

Último (19)

CODIGO FISCAL DE LA FEDERACION 2024 ACTUALIZADO
CODIGO FISCAL DE LA FEDERACION 2024 ACTUALIZADOCODIGO FISCAL DE LA FEDERACION 2024 ACTUALIZADO
CODIGO FISCAL DE LA FEDERACION 2024 ACTUALIZADO
 
TRABAJO DE EXPOSICIÓN CASO URUBO GUENDAA
TRABAJO DE EXPOSICIÓN CASO URUBO GUENDAATRABAJO DE EXPOSICIÓN CASO URUBO GUENDAA
TRABAJO DE EXPOSICIÓN CASO URUBO GUENDAA
 
anualidades anticipadas y diferidas .pptx
anualidades anticipadas y diferidas .pptxanualidades anticipadas y diferidas .pptx
anualidades anticipadas y diferidas .pptx
 
Planificación de Ecuador y sus respectivas zonas
Planificación de Ecuador y sus respectivas zonasPlanificación de Ecuador y sus respectivas zonas
Planificación de Ecuador y sus respectivas zonas
 
ANALISIS-FINANCIERO.ppt xxxxxxxxxxxxxxxxx
ANALISIS-FINANCIERO.ppt xxxxxxxxxxxxxxxxxANALISIS-FINANCIERO.ppt xxxxxxxxxxxxxxxxx
ANALISIS-FINANCIERO.ppt xxxxxxxxxxxxxxxxx
 
normas de informacion financiera nif b-8 y nif b-7
normas de informacion financiera nif b-8 y nif b-7normas de informacion financiera nif b-8 y nif b-7
normas de informacion financiera nif b-8 y nif b-7
 
BBSC® Impuesto Sustitutivo 2024 Ley de Emergencia
BBSC® Impuesto Sustitutivo 2024 Ley de EmergenciaBBSC® Impuesto Sustitutivo 2024 Ley de Emergencia
BBSC® Impuesto Sustitutivo 2024 Ley de Emergencia
 
Teoria de la produccion, conceptos generales
Teoria de la produccion, conceptos generalesTeoria de la produccion, conceptos generales
Teoria de la produccion, conceptos generales
 
EL MERCADO LABORAL EN EL SEMESTRE EUROPEO. COMPARATIVA.
EL MERCADO LABORAL EN EL SEMESTRE EUROPEO. COMPARATIVA.EL MERCADO LABORAL EN EL SEMESTRE EUROPEO. COMPARATIVA.
EL MERCADO LABORAL EN EL SEMESTRE EUROPEO. COMPARATIVA.
 
Documentación comercial y contable para contadores
Documentación comercial y contable para contadoresDocumentación comercial y contable para contadores
Documentación comercial y contable para contadores
 
FUNDAMENTOS DE FINANZAS EMPRESARIALES. CLASE 1.pdf
FUNDAMENTOS DE FINANZAS EMPRESARIALES. CLASE 1.pdfFUNDAMENTOS DE FINANZAS EMPRESARIALES. CLASE 1.pdf
FUNDAMENTOS DE FINANZAS EMPRESARIALES. CLASE 1.pdf
 
Análisis de negocios internacionales aplicado a moda y estilo
Análisis de negocios internacionales aplicado a moda y estiloAnálisis de negocios internacionales aplicado a moda y estilo
Análisis de negocios internacionales aplicado a moda y estilo
 
CIRCULACIÓN DE LOS TÍTULOS DE CRÉDITO.pptx
CIRCULACIÓN DE LOS TÍTULOS DE CRÉDITO.pptxCIRCULACIÓN DE LOS TÍTULOS DE CRÉDITO.pptx
CIRCULACIÓN DE LOS TÍTULOS DE CRÉDITO.pptx
 
Tiens internacional corporativo V-MOMENT.pptx
Tiens internacional corporativo V-MOMENT.pptxTiens internacional corporativo V-MOMENT.pptx
Tiens internacional corporativo V-MOMENT.pptx
 
Economía Informal en el Perú:Situación actual y perspectivas .pdf
Economía Informal en el Perú:Situación actual y perspectivas .pdfEconomía Informal en el Perú:Situación actual y perspectivas .pdf
Economía Informal en el Perú:Situación actual y perspectivas .pdf
 
SINU-153_Material de reforzamiento U5.docx
SINU-153_Material de reforzamiento U5.docxSINU-153_Material de reforzamiento U5.docx
SINU-153_Material de reforzamiento U5.docx
 
Unidad I Generalidades de la Contabilidad.pdf
Unidad I Generalidades de la Contabilidad.pdfUnidad I Generalidades de la Contabilidad.pdf
Unidad I Generalidades de la Contabilidad.pdf
 
cuadro comparativo de la Venezuela productiva
cuadro comparativo de la Venezuela productivacuadro comparativo de la Venezuela productiva
cuadro comparativo de la Venezuela productiva
 
Conceptos básicos del gasto de gobierno en Bolivia
Conceptos básicos del gasto de gobierno en BoliviaConceptos básicos del gasto de gobierno en Bolivia
Conceptos básicos del gasto de gobierno en Bolivia
 

Destacado

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
 

Destacado (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

BDD con Behat y Mink en Symfony2

  • 1.
  • 2.
  • 3. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Carlos Granados
  • 4. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados
  • 5. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados
  • 6. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados
  • 7. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados ¿Qué es BDD? • Desarrollo basado en comportamiento funcionalidad • Pasar tests != funcionalidad conseguida • Historias en lenguaje natural y compartido • Lenguaje definido y automatizable • Las historias dirigen nuestro desarrollo • Podemos comprobar la funcionalidad
  • 8. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Historias (Stories) • Características (Features) • As a [role] I want [feature] so that [benefit] • Escenarios (Scenarios) y pasos (Steps) • Precondiciones (Given …) • Acciones (When…) • Resultados (Then…)
  • 9. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Feature: Account Holder withdraws cash As an Account Holder I want to withdraw cash from an ATM So that I can get money when the bank is closed Scenario 1: Account has sufficient funds Given the account balance is 100€ And the card is valid And the machine contains enough money When the Account Holder inserts the card And the Account Holder requests 20€ Then the ATM should dispense 20€ And the account balance should be 80€ And the card should be returned Scenario 2: ...
  • 10. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Gherkin • El lenguaje de cucumber • Lenguaje natural y comprensible • Lenguaje específico y definido • Lenguaje automatizable • Similar a YAML • Ficheros .feature
  • 11. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Behat • BDD para php • Inspirado por cucumber • Herramienta de línea de comandos • Disponible en varios idiomas • Más información en http://behat.org
  • 12. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados #features/atm.feature Feature: Account Holder withdraws cash As an Account Holder I want to withdraw cash from an ATM So that I can get money when the bank is closed Scenario: Account has sufficient funds Given the account balance is 100€ And the card is valid And the machine contains enough money When the Account Holder inserts the card And the Account Holder requests 20€ Then the ATM should dispense 20€ And the account balance should be 80€ And the card should be returned Scenario: ...
  • 13. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados $ behat Feature: Account Holder withdraws cash As an Account Holder I want to withdraw cash from an ATM So that I can get money when the bank is closed Scenario 1: Account has sufficient funds #features/atm.feature:7 Given the account balance is 100€ ... 1 scenario ( 1 undefined) 8 steps (8 undefined) You can implement undefined steps with these code snippets: /** * @Given /^the account balance is (d+)€$/ */ public function theAccountBalanceIs($argument1) { throw new PendingException(); } ...
  • 14. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados // features/bootstrap/FeatureContext.php <?php use BehatBehatContextBehatContext, BehatBehatExceptionPendingException; class FeatureContext extends BehatContext { /** * @Given /^the account balance is (d+)€$/ */ public function theAccountBalanceIs ($argument1) { throw new PendingException (); } }
  • 15. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados // features/bootstrap/FeatureContext.php <?php use BehatBehatContextBehatContext, BehatBehatExceptionPendingException; class FeatureContext extends BehatContext { /** * @Given /^(?:|the )account balance is (d+)€$/ */ public function setAccountBalance ($balance) { $user = $this->getContainer()->getUser(); $account = $user->getAccount(); $account->setBalance($balance); } }
  • 16. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados $ behat Feature: Account Holder withdraws cash As an Account Holder I want to withdraw cash from an ATM So that I can get money when the bank is closed Scenario 1: Account has sufficient funds #features/atm.feature:7 Given the account balance is 100€ #featureContext::setAccountBalance() ... 1 scenario (1 pased) 8 steps (8 passed)
  • 17. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados /** * @Then /^(?:|The )account balance should be (d+)€$/ */ public function checkAccountBalance ($balance) { $user = $this->getContainer()->getUser(); $account = $user->getAccount(); if ($account->getBalance()!=$balance) { throw new Exception( 'Actual balance is '.$account->getBalance(). '€ instead of '.$balance.'€'; ); } }
  • 18. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados $ behat Feature: Account Holder withdraws cash As an Account Holder I want to withdraw cash from an ATM So that I can get money when the bank is closed Scenario 1: Account has sufficient funds #features/atm.feature:7 ... And the account balance should be 80€ #featureContext::checkAccountBalance() Actual balance is 100€ instead of 80€ And the card should be returned #featureContext::isCardReturned() ... 1 scenario (1 pased) 8 steps (6 passed, 1 skipped, 1 failed)
  • 19. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados require_once 'PHPUnit/Autoload.php'; require_once 'PHPUnit/Framework/Assert/Functions.php'; ... /** * @Then /^(?:|the )account balance should be (d+)€$/ */ public function checkAccountBalance ($balance) { $user = $this->getContainer()->getUser(); $account = $user->getAccount(); assertEquals($account->getBalance(), $balance); }
  • 20. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados ... Scenario: Account has insufficient funds Given the account balance is 10€ And the card is valid And the machine contains enough money When the Account Holder inserts the card And the Account Holder requests 20€ Then the ATM should not dispense any money And the ATM should print "Insuficient funds" And the account balance should be 10€ And the card should be returned Scenario: ...
  • 21. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Then the account balance should be 20€ /** * @Then /^the account balance should be (d+)€$/ */ Then the ATM should print "Insuficient funds" /** * @Then /^the ATM should print "([^"]*)"$/ */
  • 22. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Scenario: ... Given the following users exist: | name | email | phone | | Aslak | aslak@email.com | 123 | | Joe | joe@email.com | 234 | | Bryan | bryan@email.org | 456 | /** * @Given /the following users exist:/ */ public function insertUsers(TableNode $table) { $hash = $table->getHash(); foreach ($hash as $row) { $user = new User($row['name'], $row['email'], $row['phone']); $this->database->insert($user); } }
  • 23. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Scenario: Eat 5 out of 12 Given there are 12 cucumbers When I eat 5 cucumbers Then I should have 7 cucumbers Scenario: Eat 5 out of 20 Given there are 20 cucumbers When I eat 5 cucumbers Then I should have 15 cucumbers Scenario: Eat 5 out of 5 Given there are 5 cucumbers When I eat 5 cucumbers Then I should have 0 cucumbers
  • 24. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Scenario Outline: Eat cucumbers Given there are <start> cucumbers When I eat <eat> cucumbers Then I should have <left> cucumbers Examples: | start | eat | left | | 12 | 5 | 7 | | 20 | 5 | 15 | | 5 | 5 | 0 |
  • 25. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Background: Given the following users exist: | name | email | phone | | Aslak | aslak@email.com | 123 | | Joe | joe@email.com | 234 | | Bryan | bryan@email.org | 456 | Scenario:... Scenario:... Hooks: http://docs.behat.org/guides/3.hooks.html
  • 26. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados /** * @Then /^there should be no money in the account$/ */ public function checkEmptyAccount () { return new Then('the account balance should be 0€'); } /** * @When /^the user eats and sleeps$/ */ public function userEatsAndSleeps () { return array( new When("the user eats"), new When("the user sleeps"), ); }
  • 27. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Behat en Symfony2: BehatBundle //deps [gherkin] git=https://github.com/Behat/Gherkin.git target=/behat/gherkin [behat] git=https://github.com/Behat/Behat.git target=/behat/behat [BehatBundle] git=https://github.com/Behat/BehatBundle.git target=/bundles/Behat/BehatBundle
  • 28. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados //app/autoload.php $loader->registerNamespaces(array( // .. 'BehatGherkin' => __DIR__.'/../vendor/behat/gherkin/src', 'BehatBehat' => __DIR__.'/../vendor/behat/behat/src', 'BehatBehatBundle' => __DIR__.'/../vendor/bundles', )); //app/AppKernel.php public function registerBundles() { // .. if ('test' === $this->getEnvironment()) { $bundles[] = new BehatBehatBundleBehatBundle(); } }
  • 29. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados $ app/console -e=test behat --init @AcmeDemoBundle +Acme +DemoBundle +... +Features +Context -FeatureContext.php +...
  • 30. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados //Acme/DemoBundle/Features/Context/FeatureContext.php <?php namespace AcmeDemoBundleFeaturesContext; use BehatBehatBundleContextBehatContext; class FeatureContext extends BehatContext { /** * @Given /I have a product "([^"]*)"/ */ public function insertProduct($name) { $em = $this->getContainer()->get('doctrine') ->getEntityManager(); $product = new AcmeDemoBundleEntityProduct(); $product->setName($name); $em->persist($product); $em->flush(); } }
  • 31. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados BDD en Symfony2: ejecutar tests $ app/console –e=test behat @AcmeDemoBundle
  • 32. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Pruebas de funcionalidad web: Mink • Librería php integrada con behat • Permite usar distintos Browser emulators • Controlar el Navegador • Recorrer la Página • Manipular la Página • Simular la interacción del Usuario • Interface común para todos los emuladores
  • 33. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Tipos de Browser emulators: • Emuladores Headless Browsers • Symfony Web Client • Goutte • Emuladores Browser controllers • Selenium • Sahi • Mixtos: Zombie.js
  • 34. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Controlar el Navegador // iniciar driver: $driver = new BehatMinkDriverGoutteDriver(); // iniciar sesión: $session = new BehatMinkSession($driver); // arrancar sesión: $session->start(); // abrir una página en el navegador: $session->visit('http://my_project.com/some_page.php'); // obtener el código de respuesta: echo $session->getStatusCode(); // obtener el contenido de la página: echo $session->getPage()->getContent();
  • 35. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados // utilizar la historia del navegador: $session->reload(); $session->back(); $session->forward(); // evaluar expresión Javascript: echo $session->evaluateScript( "(function(){ return 'something from browser'; })()" ); // obtener los headers: print_r($session->getResponseHeaders()); // guardar cookie: $session->setCookie('cookie name', 'value'); // obtener cookie: echo $session->getCookie('cookie name');
  • 36. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Recorrer la Página: selectors //xpath selector $handler = new BehatMinkSelectorSelectorsHandler(); $xpath = $handler->selectorToXpath('xpath', '//html'); //css selector $selector = new BehatMinkSelectorCssSelector(); $xpath = $selector->translateToXPath('#ID'); //named selectors $selector = new BehatMinkSelectorNamedSelector(); $xpath = $selector->translateToXPath( array('field', 'id|name|value|label') ); //named selectors: link, button, content, select, checkbox //radio, file, optgroup, option, table
  • 37. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Recorrer la Página: obtener elementos //obtengo la página $page = $session->getPage(); //encuentro un elemento $element = $page->find('xpath', '//body'); //encuentro todos los elementos $elementsByCss = $page->findAll('css', '.classname'); //encuentro un elemento por su Id $element = $page->findById('ID'); //encuentro elementos con named selectors $link = $page->findLink('href'); $button = $page->findButton('name'); $field = $page->findField('id');
  • 38. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Manipular la Página: Node Elements //obtengo un elemento $el = $page->find('css', '.something'); // obtengo el nombre del tag: echo $el->getTagName(); // compruebo si tiene un atributo: $el->hasAttribute('href'); // obtengo un atributo: echo $el->getAttribute('href'); //obtengo el texto $plainText = $el->getText(); //obtengo el html $html = $el->getHtml();
  • 39. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Manipular la Página: Form fields // marcar/desmarcar checkbox: if ($el->isChecked()) { $el->uncheck(); } $el->check(); // elegir option en select: $el->selectOption('optin value'); // añadir un fichero: $el->attachFile('/path/to/file'); // obtener el valor: echo $el->getValue(); // poner un valor: $el->setValue('some val');
  • 40. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Simular la interacción del Usuario // pulsar un botón: $el->press(); //simular el ratón $el->click(); $el->doubleClick(); $el->rightClick(); $el->mouseOver(); $el->focus(); $el->blur(); //Hacer drag'n'drop $el1->dragTo($el2);
  • 41. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Integración con Behat: MinkContext // features/bootstrap/FeatureContext.php use BehatMinkBehatContextMinkContext; class FeatureContext extends MinkContext { /** * @Then /^I press the submit button$/ */ public function PressSubmitButton() { $page = $this->getSession()->getPage(); $button = $page->findButton('submit'); $button->press(); } }
  • 42. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Steps predefinidos: Given/When Given I am on "URL" When I go to "url" When I reload the page When I move backward one page When I move forward one page When I press "button" When I follow "link" When I fill in "field" with "value" When I fill in "value" for "field" When I fill in the following: When I select "option" from "select" When I additionally select "option" from "select" When I check "option" When I uncheck "option" When I attach the file "path" to "field"
  • 43. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Steps predefinidos: Then Then I should be on "page" Then the url should match "pattern" Then the response status code should be "code" Then the response status code should not be "code" Then I should see "text" Then I should not see "text" Then I should see "text" in the "element" element Then the "element" element should contain "value" Then I should see an "element" element Then I should not see an "element" element Then the "field" field should contain "value" Then the "field" field should not contain "value" Then the "checkbox" checkbox should be checked Then the "checkbox" checkbox should not be checked Then I should see "num" "element" elements Then print last response
  • 44. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados # features/search.feature Feature: Search In order to see a word definition As a website user I need to be able to search for a word Scenario: Searching for a page that does exist Given I am on "/wiki/Main_Page" When I fill in "search" with "Behavior Driven Development" And I press "searchButton" Then I should see "agile software development" Scenario: Searching for a page that does NOT exist Given I am on "/wiki/Main_Page" When I fill in "search" with "Glory Driven Development" And I press "searchButton" Then I should see “No results found"
  • 45. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados /** * @Given /^I am on the main page$/ */ public function goToMainPage() { return new Given('I am on "/wiki/Main_Page"'); } /** * @Then /^I press the search button$/ */ public function pressSearchButton() { return new Then('I press "searchButton"'); }
  • 46. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Mink en Symfony2: MinkBundle //deps [mink] git=https://github.com/Behat/Mink.git target=/behat/mink [MinkBundle] git=https://github.com/Behat/MinkBundle.git target=/bundles/Behat/MinkBundle
  • 47. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados //app/autoload.php $loader->registerNamespaces(array( // .. 'BehatMink' => __DIR__.'/../vendor/behat/mink/src', 'BehatMinkBundle' => __DIR__.'/../vendor/bundles', )); //app/AppKernel.php public function registerBundles() { // .. if ('test' === $this->getEnvironment()) { $bundles[] = new BehatBehatBundleBehatBundle(); $bundles[] = new BehatMinkBundleMinkBundle(); } }
  • 48. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados #app/config/config_test.yml mink: base_url: http://localhost/app_test.php browser_name: chrome goutte: ~ sahi: ~ zombie: ~
  • 49. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados //web/app_test.php if (!in_array(@$_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1', ))) { header('HTTP/1.0 403 Forbidden'); exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.'); } require_once __DIR__.'/../app/bootstrap.php.cache'; require_once __DIR__.'/../app/AppKernel.php'; use SymfonyComponentHttpFoundationRequest; $kernel = new AppKernel('test', true); $kernel->loadClassCache(); $kernel->handle(Request::createFromGlobals())->send();
  • 50. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados namespace AcmeDemoBundleFeaturesContext; use BehatMinkBundleContextMinkContext; class FeatureContext extends MinkContext { /** * @When /^I go to the user account page$/ */ public function showUserAccount() { $user = $this->getContainer()->get('security.context') ->getToken()->getUser(); $session = $this->getSession(); $session->visit('/account/'. $user->getSlug()); } }
  • 51. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Qué Driver usar # symfony driver (default) @mink:symfony Scenario: ... # goutte driver @mink:goutte Scenario: ... # sahi driver @mink:sahi o @javascript Scenario: ... # zombie.js driver @mink:zombie Scenario: ...
  • 52. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Trucos: Salida de Behat app/console -e=test behat -f pretty,junit --out ,. @AcmeDemoBundle
  • 53. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Trucos: repetir Tests app/console -e=test behat --rerun="re.run" @AcmeDemoBundle
  • 54. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados BDD vs TDD • BDD es TDD BDD vs UnitTesting • Unit testing comprueba unidades • BDD comprueba funcionalidad
  • 55. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados Stop Press!!! Behat 2.4 • BehatBundle y MinkBundle deprecated • Usar MinkExtension y Symfony2Extension • Más info en http://behat.org
  • 56. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados //deps [mink] git=https://github.com/Behat/Mink.git target=/behat/mink version=v1.3.3 [gherkin] git=https://github.com/Behat/Gherkin.git target=/behat/gherkin version=v2.1.1 [behat] git=https://github.com/Behat/Behat.git target=/behat/behat version=v2.3.5
  • 57. Desarrollo guiado por comportamiento (BDD) con Symfony2, Behat y Mink – Carlos Granados ¡¡Gracias!! ¿Preguntas? • carlos@planetapluton.com • @carlos_granados • http://es.linkedin.com/in/carlosgranados