Skip to content
This is a simple example of how to use bdd
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ansible
app
bin
features
spec/SimpleTracker
src/SimpleTracker
web
.gitignore
README.md
Vagrantfile
behat.yml
composer.json
composer.lock

README.md

SIMPLE TRACKER

Install behat and phpspec via composer.json, configure the autoloader and set the bin-dir

Add this to composer.json:

    {
        "require": {
            "php": "~5.5.0"
        },
        "require-dev": {
            "behat/behat": "~3.0",
            "phpspec/phpspec": "~2.1",
            "phpunit/phpunit": "~4.4"
        },
        "autoload": {
            "psr-0": {
                "SimpleTracker": "src"
            }
        },
        "config": {
            "bin-dir": "bin"
        }
    }

Run composer install

Configure a simple project manager context through behat

  • Add behat.yml
    default:
        suites:
            projectManager:
                contexts: [ SimpleProjectManagerContext ]
                filters:  { role: project manager, tags: simple }
  • Run bin/behat --init
  • Add the simple tag to the pm edits a project feature

Leverage behat to start your code

  • Append snippets bin/behat features/pm_edits_project.feature:7 --append-snippets
  • Run behat bin/behat features/pm_edits_project.feature:7 and implement the first pending definition
  • Run behat again and see the scenario fail

Leverage phpspec to build your domain

  • Run phpspec bin/phpspec run and see you have no specs or examples yet
  • Describe the project class under the right namespace bin/phpspec describe SimpleTracker/Project/Project
  • Run phpspec and choose yes when it asks to add the project class
  • Add a let method to your spec to construct a project through a given constructor and arguments
  • Run phpspec and choose yes when it asks to add the constructor to your project class

Use the initialized domain concepts in your behat context

  • Use the project class in your behat context
  • Run behat with bin/behat features/pm_edits_project.feature:7 and see the first step pass
  • Start by implementing the next pending definition and combine behat and phpspec to build your domain by repeating the steps

Leverage phpunit to test the then in your scenario

  • Use the assertion framework use PHPUnit_Framework_Assert as Assert;
  • Define the step by adding assertions
  • Make the step pass by again leveraging behat and phpspec

Adding a touch of symfony

  • Install a clean version of the framework, one folder up composer create-project symfony/framework-standard-edition ../framework/ "~2.6.4"

  • Copy the web and app folder to your bdd project cp -R ../framework/app/ . && cp -R ../framework/web .

  • Delete the AppBundle reference in app/AppKernel.php

  • Replace your composer.json with the following:

    {
        "require": {
            "php": ">=5.3.3",
            "symfony/symfony": "2.6.*",
            "doctrine/orm": "~2.2,>=2.2.3,<2.5",
            "doctrine/dbal": "<2.5",
            "doctrine/doctrine-bundle": "~1.2",
            "twig/extensions": "~1.0",
            "symfony/assetic-bundle": "~2.3",
            "symfony/swiftmailer-bundle": "~2.3",
            "symfony/monolog-bundle": "~2.4",
            "sensio/distribution-bundle": "~3.0,>=3.0.12",
            "sensio/framework-extra-bundle": "~3.0,>=3.0.2",
            "incenteev/composer-parameter-handler": "~2.0"
        },
        "require-dev": {
            "behat/behat": "~3.0",
            "behat/mink": "~1.6.0",
            "behat/mink-extension": "~2.0.0",
            "behat/symfony2-extension": "~2.0.0",
            "behat/mink-browserkit-driver": "~1.2.0",
            "phpspec/phpspec": "~2.1",
            "phpunit/phpunit": "~4.4",
            "sensio/generator-bundle": "~2.3"
        },
        "autoload": {
            "psr-0": {
                "SimpleTracker": "src"
            }
        },
        "scripts": {
            "post-root-package-install": [
                "SymfonyStandard\\Composer::hookRootPackageInstall"
            ],
            "post-install-cmd": [
                "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
                "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
                "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
                "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
                "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
                "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles"
            ],
            "post-update-cmd": [
                "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
                "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
                "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
                "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
                "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
                "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles"
            ]
        },
        "config": {
            "bin-dir": "bin"
        },
        "extra": {
            "symfony-app-dir": "app",
            "symfony-web-dir": "web",
            "symfony-assets-install": "relative",
            "incenteev-parameters": {
                "file": "app/config/parameters.yml"
            },
            "branch-alias": {
                "dev-master": "2.6-dev"
            }
        }
    }
  • Run composer update
  • Make a single front-controller by replacing the contents of web/app.php with the following:
    <?php
    
    use Symfony\Component\Debug\Debug;
    use Symfony\Component\HttpFoundation\Request;
    
    $loader = require_once __DIR__.'/../app/bootstrap.php.cache';
    
    $env = getenv('SYMFONY_ENV') ?: 'prod';
    $debug = getenv('SYMFONY_DEBUG') === '1';
    
    if ($debug) {
        Debug::enable();
    }
    
    require_once __DIR__.'/../app/AppKernel.php';
    require_once __DIR__.'/../app/AppCache.php';
    
    $kernel = new AppKernel($env, $debug);
    $kernel->loadClassCache();
    $kernel = new AppCache($kernel);
    
    $request = Request::createFromGlobals();
    $response = $kernel->handle($request);
    $response->send();
    $kernel->terminate($request, $response);

Add an online simple project manager context

  • Replace the contents of `behat.yml with the following:
    default:
        suites:
            simpleProjectManager:
                contexts: [ SimpleProjectManagerContext ]
                filters:  { role: project manager, tags: simple }
    
            projectManager:
                contexts: [ ProjectManagerContext ]
                filters:  { role: project manager, tags: less-simple }
    
            onlineSimpleProjectManager:
                contexts: [ OnlineSimpleProjectManagerContext ]
                filters:  { role: project manager, tags: simple-critical }
    
        extensions:
            Behat\Symfony2Extension: ~
            Behat\MinkExtension:
                default_session: 'symfony2'
                sessions:
                    symfony2: { symfony2: ~ }
  • Initialize behat `bin/behat --init
  • Mark the scenario in pm_edits_project.feature as simple-critical
  • Mark the feature for assigning a task in pm_assigns_task_to_sprint.feature as less-simple
  • Add snippets to the online simple project manager context bin/behat features/pm_edits_project.feature --append-snippets --tags=simple-critical

Leverage Symfony and Mink to implement your pages and functional tests

  • Implement the given and when steps in your scenario by using Mink

  • Implement needed methods via phpspec

  • Generate a symfony bundle app/console generate:bundle --bundle-name=SimpleTrackerAppBundle --namespace=SimpleTracker/AppBundle

  • Choose xml as the configuration format

  • Cleanup controller and tests

  • Add your mapping doctrine config:

    orm:
            auto_generate_proxy_classes: "%kernel.debug%"
            auto_mapping: false
            mappings:
                simple_tracker:
                    is_bundle: false
                    type:      xml
                    dir:       %kernel.root_dir%/config/doctrine
                    prefix:    SimpleTracker
  • Add orm-files for you entities to app/config/doctrine
  • Add repositories
  • Implement controller and template
  • Implement the when and then in behat to test your scenario
You can’t perform that action at this time.