Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

BDD in Symfony2

21,213 views

Published on

Quality assurance is one of the most difficult things to implement around software development. Most of time it is left for the final phase of development and very often overlooked entirely. As many experienced web development teams already know, QA needs to be part of the development process from the get-go. Behavior development/testing is just one aspect of quality assurance. And we'll talk about that.

Published in: Technology
  • DOWNLOAD FULL BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Good
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Nice + 1
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • symfony, BDD
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Saw this in Paris. Interesting and impressive presentation. +1
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

BDD in Symfony2

  1. 1. BDD with Symfony2
  2. 2. Iwho am everzet senior from-birth PHP developer at
  3. 3. TIMELINE UnitTest Test code automatically
  4. 4. TDD Write tests firstTIMELINE UnitTest Test code automatically
  5. 5. BDD Dan North TDD Write tests firstTIMELINE UnitTest Test code automatically
  6. 6. BDD ❿evolution of TDD
  7. 7. - Oh, man, i hate evolutions! What’s wrong with TDD?
  8. 8. Test-Driven Development- Oh, man, i hate evolutions! What’s wrong with TDD?
  9. 9. Are we really talking about tests??? But how to test something, that not exists yet? Test-Driven Development- Oh, man, i hate evolutions! What’s wrong with TDD?
  10. 10. In reality, we’re talking bout software design Test-Driven Development - Oh, man, i hate evolutions! What’s wrong with TDD?
  11. 11. BehaviorTest-Driven Development © 2003, Dan North
  12. 12. BDD was introduced as set of conventions over TDD
  13. 13. BDD was introduced as set of conventions over TDDTest method names should be sentencestestFindsCustomerById() ❿ tests, that class finds customer by IDtestFailsForDuplicateCustomers() ❿tests, that class fails for dup customers
  14. 14. BDD was introduced as set of conventions over TDDTest method names should be sentencestestFindsCustomerById() ❿ tests, that class finds customer by IDtestFailsForDuplicateCustomers() ❿tests, that class fails for dup customersTest method names should start with “should” wordshouldFindCustomerById() ❿ class should find customer by IDshouldFailForDuplicateCustomers() ❿class should fail for dup customers
  15. 15. BDD was introduced as set of conventions over TDDTest method names should be sentencestestFindsCustomerById() ❿ tests, that class finds customer by IDtestFailsForDuplicateCustomers() ❿tests, that class fails for dup customersTest method names should start with “should” wordshouldFindCustomerById() ❿ class should find customer by IDshouldFailForDuplicateCustomers() ❿class should fail for dup customersTestCase class should be nouns in test method sentencesclass CustomerTableTest extends PHPUnitTestCase{ /** * @Test */ shouldFindCustomerById() ❿ CustomerTable should find customer by ID ...}
  16. 16. ASSERTIONS are TEST-oriented too TESTing assertEquals($expected, $actual)assertGreaterThan($expected, $actual) assertInstanceOf($class, $actual)
  17. 17. ASSERTIONS are TEST-oriented too TESTing Describing assertEquals($expected, $actual) $actual should be Equals to $expectedassertGreaterThan($expected, $actual) $actual should be GreaterThan $expected assertInstanceOf($class, $actual) $actual should be InstanceOf $class
  18. 18. Design first Spec BDD BDD Dan North TDD Write tests firstTIMELINE UnitTest Test code automatically
  19. 19. Specification-oriented BDD Frameworks
  20. 20. *Spec RSpec by Dave Astels
  21. 21. *Spec RSpec by Dave Astels JSpec by TJ Holowaychuk
  22. 22. *Spec RSpec by Dave Astels JSpec by TJ Holowaychuk Fabulous by Alex Rudakov
  23. 23. RSpec # bowling_spec.rb require bowling describe Bowling, "#score" do it "returns 0 for all gutter game" do bowling = Bowling.new 20.times { bowling.hit(0) } bowling.score.should == 0 end end
  24. 24. RSpec # bowling_spec.rb require bowling describe Bowling, "#score" do it "returns 0 for all gutter game" do bowling = Bowling.new 20.times { bowling.hit(0) } bowling.score.should == 0 end end Write class SPECIFICATION, not UnitTEST
  25. 25. SCENARIOORIENTEDBDD photo by dsearls
  26. 26. VOCABULARY photophoto by dsearls by Horia Varlan
  27. 27. e rs e st r t foVOCABULARY photophoto by dsearls by Horia Varlan
  28. 28. e rs e st r t foVOCABULARY f ora na ly st s photophoto by dsearls by Horia Varlan
  29. 29. e rs e st r t fo VOCABULARY f rs ora pe na lo e ve ly d stfor s photophoto by dsearls by Horia Varlan
  30. 30. for rs bu e sin e st ess r t fo VOCABULARY f rs ora pe na lo e ve ly d stfor s photophoto by dsearls by Horia Varlan
  31. 31. for rs bu e st 1 sin e ess r t fo VOCABULARY f rs ora pe na lo e ve ly d stfor s photophoto by dsearls by Horia Varlan
  32. 32. ELIMINATING some of the AMBIGUITY and MISCOMMUNICATION testersbusiness developers VOCABULARY analysts photophoto by dsearls by Horia Varlan
  33. 33. MU NICATIONSCOM photo by joshfassbind.com
  34. 34. Story: In order to [A] As a [B] I need [C]
  35. 35. Story: In order to [A] As a [B] I need [C] A ❿ benefit or value of the feature the B ❿ person (or role) who will benefit the C❿some feature
  36. 36. Story: In order to [A] ❿ strength is that it forces you to Its As a [B] identify the value of delivering a story when you first define it. I need [C] © Dan North A ❿ benefit or value of the feature the B ❿ person (or role) who will benefit the C❿some feature
  37. 37. Story: A story’s behaviour is simply its acceptance criteria! ❿ the system fulfills all the acceptance if criteria, it’s behaving correctly; if it doesn’t, it isn’t.
  38. 38. Story:In order to ...As a ...I need ...
  39. 39. Story:In order to ...As a ...I need ... Given some initial context (the givens), When an event occurs, Then ensure some outcomes.
  40. 40. Story:In order to ...As a ...I need ... Given some initial context (the givens), When an event occurs, Then ensure some outcomes. Given some initial context (the givens), When an event occurs, Then ensure some outcomes.
  41. 41. Story:In order to ...As a ...I need ... Scenario 1: Given some initial context (the givens), When an event occurs, Then ensure some outcomes. Scenario 2: Given some initial context (the givens), When an event occurs, Then ensure some outcomes.
  42. 42. Scenario BDD Design first Spec BDD Analyse first BDD Dan North TDD Write tests firstTIMELINE UnitTest Test code automatically
  43. 43. GHERKINDSL photo by isobel.gordon
  44. 44. Story:In order to ...As a ...I need ... Scenario 1: Given some initial context (the givens), When an event occurs, Then ensure some outcomes. Scenario 2: Given some initial context (the givens), When an event occurs, Then ensure some outcomes.
  45. 45. Feature: Feature descriptionIn order to ...As a ...I need ... Scenario: 1st scenario title Given some initial context (the givens) When an event occurs Then ensure some outcomes Scenario: 2nd scenario title Given some initial context (the givens) When an event occurs Then ensure some outcomes
  46. 46. # language: frFonctionnalité: Feature descriptionIn order to ...As a ...I need ... Scénario: 1st scenario title Etant donné some initial context (the givens) Lorsque an event occurs Alors ensure some outcomes Scénario: 2nd scenario title Etant donné some initial context (the givens) Lorsque an event occurs Alors ensure some outcomes
  47. 47. # language: ja : Feature descriptionIn order to ...As a ...I need ... : 1st scenario title some initial context (the givens) an event occurs ensure some outcomes : 2nd scenario title some initial context (the givens) an event occurs ensure some outcomes
  48. 48. # language: ruФункционал: Feature descriptionIn order to ...As a ...I need ... Сценарий: 1st scenario title Допустим some initial context (the givens) Когда an event occurs То ensure some outcomes Сценарий: 2nd scenario title Допустим some initial context (the givens) Когда an event occurs То ensure some outcomes
  49. 49. # language: en-pirateAhoy matey!: Feature descriptionIn order to ...As a ...I need ... Heave to: 1st scenario title Let go and haul some initial context (the givens) Blimey! an event occurs Aye ensure some outcomes Heave to: 2nd scenario title Let go and haul some initial context (the givens) Blimey! an event occurs Aye ensure some outcomes
  50. 50. # language: en-pirateAhoy matey!: Heave to: Let go and haul some initial context (the givens) Blimey! an event occurs Aye ensure some outcomes Heave to: Let go and haul some initial context (the givens) Blimey! an event occurs Aye ensure some outcomes
  51. 51. Acceptance criteria should be executable!
  52. 52. Feature: Feature descriptionIn order to ...As a ...I need ... Scenario: 1st scenario title Given some initial context (the givens) When an event occurs Then ensure some outcomes Scenario: 2nd scenario title Given some initial context (the givens) When an event occurs Then ensure some outcomes
  53. 53. feature treeFeature: Feature description 1. featureIn order to ...As a ...I need ... Scenario: 1st scenario title2. scenario Given some initial context (the givens) 3. step When an event occurs ... Then ensure some outcomes ... Scenario: 2nd scenario title2. scenario Given some initial context (the givens) 3. step When an event occurs ... Then ensure some outcomes ...
  54. 54. STEP DEFINITIONS Given I have a bank account
  55. 55. STEP DEFINITIONS Given I have a bank account <?php Given(/^I have a bank account$/);
  56. 56. STEP DEFINITIONS Given I have a bank account <?php Given(/^I have a bank account$/, function() { throw new BehatBehatExceptionPending(); } );
  57. 57. STEP DEFINITIONS Given I have a bank account <?php $steps->Given(/^I have a bank account$/, function() { throw new BehatBehatExceptionPending(); } );
  58. 58. STEP DEFINITIONS Given I have a bank account <?php $steps->Given(/^I have a bank account$/, function() { throw new BehatBehatExceptionPending(); ??? } );
  59. 59. STEP RESULT TYPES1. Pending step ❿that throw new BehatBehatExceptionPending();
  60. 60. STEP RESULT TYPES1. Pending step ❿that throw new BehatBehatExceptionPending();2. Undefined step ❿that have no definitions (found)
  61. 61. STEP RESULT TYPES1. Pending step ❿that throw new BehatBehatExceptionPending();2. Undefined step ❿that have no definitions (found)3. Ambiguous step ❿which match multiple definitions
  62. 62. STEP RESULT TYPES1. Pending step ❿that throw new BehatBehatExceptionPending();2. Undefined step ❿that have no definitions (found)3. Ambiguous step ❿which match multiple definitions4. Failed step ❿that throw Exception();
  63. 63. STEP RESULT TYPES1. Pending step ❿that throw new BehatBehatExceptionPending();2. Undefined step ❿that have no definitions (found)3. Ambiguous step ❿which match multiple definitions4. Failed step ❿that throw Exception();5. Skipped step ❿that follows pending/undefined/failed
  64. 64. STEP RESULT TYPES1. Pending step ❿that throw new BehatBehatExceptionPending();2. Undefined step ❿that have no definitions (found)3. Ambiguous step ❿which match multiple definitions4. Failed step ❿that throw Exception();5. Skipped step ❿that follows pending/undefined/failed6. Passed step ❿that doesn’t throw exceptions
  65. 65. STEP DEFINITIONS Given I have a bank account <?php $steps->Given(/^I have a bank account$/, function() { throw new BehatBehatExceptionPending(); } );
  66. 66. STEP DEFINITIONS Given I have a bank account <?php $steps->Given(/^I have a bank account$/, function() { throw new BehatBehatExceptionPending(); } ); When I deposit 35$
  67. 67. STEP DEFINITIONS Given I have a bank account <?php $steps->Given(/^I have a bank account$/, function() { throw new BehatBehatExceptionPending(); } ); When I deposit 35$ <?php $steps->When(/^I deposit (d+)$$/, function($dollars) { // $dollars === 35 } );
  68. 68. STEP DEFINITIONS Given I have a bank account <?php $steps->Given(/^I have a bank account$/, function() { throw new BehatBehatExceptionPending(); } ); When I deposit 35$ <?php $steps->When(/^I deposit (d+)$$/, function($dollars) { // $dollars === 35 } );
  69. 69. STEP DEFINITIONS Given I have a bank account <?php $steps->Given(/^I have a bank account$/, function($world) { throw new BehatBehatExceptionPending(); } ); When I deposit 35$ <?php $steps->When(/^I deposit (d+)$$/, function($world, $dollars) { // $dollars === 35 } );
  70. 70. STEP DEFINITIONS Given I have a bank account <?php $steps->Given(/^I have a bank account$/, function($world) { $world->account = new BankAccount(); } ); When I deposit 35$ <?php $steps->When(/^I deposit (d+)$$/, function($world, $dollars) { $world->account->deposit($dollars); } );
  71. 71. TESTING OUTCOME Then I should have 35$
  72. 72. TESTING OUTCOME Then I should have 35$ <?php $steps->Then(/^I should have (d+)$$/, function($world, $balance) { if ($balance !== $world->account->getBalance()) { throw new Exception(Wrong balance!); } } );
  73. 73. TESTING OUTCOME Then I should have 35$ <?php $steps->Then(/^I should have (d+)$$/, function($world, $balance) { if ($balance !== $world->account->getBalance()) { throw new Exception(Wrong balance!); } } ); Then I should have 35$ ( using PHPUnit ) <?php $steps->Then(/^I should have (d+)$$/, function($world, $balance) { assertEquals($balance, $world->account->getBalance()); } );
  74. 74. STEP DEFINITIONS <?php $steps->Given(/^I have a bank account$/, function($world) { $world->account = new BankAccount(); } ); $steps->When(/^I deposit (d+)$$/, function($world, $dollars) { $world->account->deposit($dollars); } ); $steps->Then(/^I should have (d+)$$/, function($world, $balance) { assertEquals($balance, $world->account->getBalance()); } );
  75. 75. STEP DEFINITIONS <?php $steps-> Given(/^I have a bank account$/, function($world) { $world->account = new BankAccount(); } )-> When(/^I deposit (d+)$$/, function($world, $dollars) { $world->account->deposit($dollars); } )-> Then(/^I should have (d+)$$/, function($world, $balance) { assertEquals($balance, $world->account->getBalance()); } );
  76. 76. d le un atB e hB
  77. 77. BehatBundle USAGE 1. Install: http://symfony2bundles.org/Behat/BehatBundle
  78. 78. BehatBundle USAGE 1. Install: http://symfony2bundles.org/Behat/BehatBundle 2. Setup: $ app/console behat:test:bundle --init ApplicationHelloBundle . src/Application/HelloBundle/Tests/Features ❿write and put your features here steps ❿place step definition files here    steps.php ❿example step definition file support ❿place support scripts here bootstrap.php ❿bootstrap env.php ❿environment (context) initialization
  79. 79. BehatBundle USAGE 1. Install: http://symfony2bundles.org/Behat/BehatBundle 2. Setup: $ app/console behat:test:bundle --init ApplicationHelloBundle . src/Application/HelloBundle/Tests/Features ❿write and put your features here steps ❿place step definition files here    steps.php ❿example step definition file support ❿place support scripts here bootstrap.php ❿bootstrap env.php ❿environment (context) initialization 3. Colorize: $ app/console behat:test:bundle ApplicationHelloBundle
  80. 80. BUNDLEDSteps
  81. 81. BUNDLEDSteps Browser Steps Given /^I am on(?: the)? (.*)$/ When /^I go to(?: the)? (.*)$/ When /^I (?:follow|click)(?: the)? "([^"]*)"(?: link)*$/ When /^I go back$/ When /^I go forward$/ When /^I send (POST|PUT|DELETE) to (.*) with:$/ When /^I follow redirect$/
  82. 82. BUNDLEDSteps Browser Steps Given /^I am on(?: the)? (.*)$/ When /^I go to(?: the)? (.*)$/ When /^I (?:follow|click)(?: the)? "([^"]*)"(?: link)*$/ When /^I go back$/ When /^I go forward$/ When /^I send (POST|PUT|DELETE) to (.*) with:$/ When /^I follow redirect$/ Form Steps When /^I fill in "([^"]*)" with "([^"]*)"$/ When /^I select "([^"]*)" from "([^"]*)"$/ When /^I uncheck "([^"]*)"$/ When /^I uncheck "([^"]*)"$/ When /^I attach the file at "([^"]*)" to "([^"]*)"$/ When /^I press "([^"]*)" in (.*) form$/
  83. 83. BUNDLEDSteps Request Steps Then /^Request method is (.*)$/ Then /^Request has cookie "([^"]*)"$/ Then /^Request has not cookie "([^"]*)"$/ Then /^Request cookie "([^"]*)" is "([^"]*)"$/
  84. 84. BUNDLEDSteps Request Steps Then /^Request method is (.*)$/ Then /^Request has cookie "([^"]*)"$/ Then /^Request has not cookie "([^"]*)"$/ Then /^Request cookie "([^"]*)" is "([^"]*)"$/ Response Steps Then /^Response status code is (d+)$/ Then /^I should see "([^"]*)"$/ Then /^I should not see "([^"]*)"$/ Then /^I should see element "([^"]*)"$/ Then /^Header "([^"]*)" is set to "([^"]*)"$/ Then /^Header "([^"]*)" is not set to "([^"]*)"$/ Then /^I was redirected$/ Then /^I was not redirected$/ Then /^Print output$/
  85. 85. Feature: User logins
  86. 86. Feature: User logins In order to have extended abilities As a site user I need to be able to login
  87. 87. Feature: User logins In order to have extended abilities As a site user I need to be able to login Scenario: Existing user can login
  88. 88. Feature: User logins In order to have extended abilities As a site user I need to be able to login Scenario: Existing user can login Scenario: Non-existing user can’t login
  89. 89. Feature: User logins In order to have extended abilities As a site user I need to be able to login Scenario: Existing user can login Given a site have “everzet” user with “qwerty” password And I am on the “/login” When I fill in “username” with “everzet” And I fill in “password” with “qwerty” And I press “login” in login form Then I should see “Welcome, everzet” Scenario: Non-existing user can’t login Given a site have “everzet” user with “qwerty” password And I am on the “/login” When I fill in “username” with “someone” And I fill in “password” with “qwerty” And I press “login” in login form Then I should see “Login or password is incorrect”
  90. 90. Feature: User logins In order to have extended abilities As a site user I need to be able to login Scenario: Existing user can login Given a site have “everzet” user with “qwerty” password And I am on the “/login” When I fill in “username” with “everzet” And I fill in “password” with “qwerty” And I press “login” in login form Then I should see “Welcome, everzet” Scenario: Non-existing user can’t login Given a site have “everzet” user with “qwerty” password And I am on the “/login” When I fill in “username” with “someone” And I fill in “password” with “qwerty” And I press “login” in login form Then I should see “Login or password is incorrect”
  91. 91. Feature: User logins In order to have extended abilities As a site user I need to be able to login Scenario: Existing user can login Given I am on the “/login” page When I fill in “username” with “everzet” And I fill in “password” with “qwerty” And I press “login” in login form Then I should see “Welcome, everzet” Scenario: Non-existing user can’t login Given I am on the “/login” page When I fill in “username” with “someone” And I fill in “password” with “qwerty” And I press “login” in login form Then I should see “Login or password is incorrect”
  92. 92. Feature: User logins In order to have extended abilities As a site user I need to be able to login Background: Given a site have “everzet” user with “qwerty” password Scenario: Existing user can login Given I am on the “/login” page When I fill in “username” with “everzet” And I fill in “password” with “qwerty” And I press “login” in login form Then I should see “Welcome, everzet” Scenario: Non-existing user can’t login Given I am on the “/login” page When I fill in “username” with “someone” And I fill in “password” with “qwerty” And I press “login” in login form Then I should see “Login or password is incorrect”
  93. 93. Feature: User logins In order to have extended abilities As a site user I need to be able to login Background: Given a site have users: | username | password | | everzet | qwerty | Scenario: Existing user can login Given I am on the “/login” page When I fill in “username” with “everzet” And I fill in “password” with “qwerty” And I press “login” in login form Then I should see “Welcome, everzet” Scenario: Non-existing user can’t login Given I am on the “/login” page When I fill in “username” with “someone” And I fill in “password” with “qwerty” And I press “login” in login form Then I should see “Login or password is incorrect”
  94. 94. Feature: User logins In order to have extended abilities As a site user I need to be able to login Background: Given a site have users: | username | password | | everzet | qwerty | Scenario: Existing user can login Given I am on the “/login” page When I fill in “username” with “everzet” And I fill in “password” with “qwerty” And I press “login” in login form Then I should see “Welcome, everzet” Scenario: Non-existing user can’t login Given I am on the “/login” page When I fill in “username” with “someone” And I fill in “password” with “qwerty” And I press “login” in login form Then I should see “Login or password is incorrect”
  95. 95. Feature: User logins In order to have extended abilities As a site user I need to be able to login Background: Given a site have users: | username | password | | everzet | qwerty | Scenario Outline: Only existing users can login Given I am on the “/login” page When I fill in “username” with “<username>” And I fill in “password” with “<password>” And I press “login” in login form Then I should see “<message>”
  96. 96. Feature: User logins In order to have extended abilities As a site user I need to be able to login Background: Given a site have users: | username | password | | everzet | qwerty | Scenario Outline: Only existing users can login Given I am on the “/login” page When I fill in “username” with “<username>” And I fill in “password” with “<password>” And I press “login” in login form Then I should see “<message>” Examples:
  97. 97. Feature: User logins In order to have extended abilities As a site user I need to be able to login Background: Given a site have users: | username | password | | everzet | qwerty | Scenario Outline: Only existing users can login Given I am on the “/login” page When I fill in “username” with “<username>” And I fill in “password” with “<password>” And I press “login” in login form Then I should see “<message>” Examples: | username | password | message | | everzet | qwerty | Welcome, everzet | | someone | pa$$word | Login or password is incorrect |
  98. 98. USAGE 1. Colorize: $ app/console behat:test:bundle ApplicationHelloBundle
  99. 99. USAGE 1. Colorize: $ app/console behat:test:bundle ApplicationHelloBundle 2. Write missing steps: <?php $steps->Given(/^a site have users:$/, function($world, $table) { $em = $world->getClient()-> getKernel()-> getContainer()-> get(doctrine.orm.entity_manager); // remove all users from test db with EntityManager foreach ($table->getRowHash() as $row) { // persist new user into test db with EntityManager // $row[‘username’] AND $row[‘password’] } $em->flush(); });
  100. 100. One more thing http://Behat.org
  101. 101. In-browser testing andother frameworks support
  102. 102. Sahi
  103. 103. SahiGoutte
  104. 104. SahiGoutteSelenium
  105. 105. SahiGoutteSeleniumsfBrowser
  106. 106. SahiGoutteSeleniumsfBrowserSymfony2 Client
  107. 107. SahiGoutteSeleniumsfBrowserSymfony2 Client through one clean API
  108. 108. Mink
  109. 109. <?php// src/Sensio/HelloBundle/Tests/Controller/HelloControllerTest.phpnamespace SensioHelloBundleTestsController;use SymfonyBundleFrameworkBundleTestWebTestCase;use BehatMink;class HelloControllerTest extends WebTestCase{ public function testIndexWithSymfony2Client() { $client = $this->createClient(); $driver = new MinkDriverSymfony2ClientDriver($client); $session = new MinkSession($driver); $session->visit(/hello/Fabien); $page = $session->getPage(); $this->assertTrue($page->hasContent(Hello Fabien)); } public function testIndexWithSahi() { $driver = new MinkDriverSahiDriver(SAHI_SESSION_ID); $session = new MinkSession($driver); $session->visit(/hello/Fabien); $page = $session->getPage(); $this->assertTrue($page->hasContent(Hello Fabien)); }}
  110. 110. <?php// src/Sensio/HelloBundle/Tests/Controller/HelloControllerTest.phpnamespace SensioHelloBundleTestsController;use SymfonyBundleFrameworkBundleTestWebTestCase;use BehatMink;class HelloControllerTest extends WebTestCase{ public function testIndexWithSymfony2Client() { $client = $this->createClient(); $driver = new MinkDriverSymfony2ClientDriver($client); $session = new MinkSession($driver); $session->visit(/hello/Fabien); $page = $session->getPage(); $this->assertTrue($page->hasContent(Hello Fabien)); } public function testIndexWithSahi() { $driver = new MinkDriverSahiDriver(SAHI_SESSION_ID); $session = new MinkSession($driver); $session->visit(/hello/Fabien); $page = $session->getPage(); $this->assertTrue($page->hasContent(Hello Fabien)); }}
  111. 111. Feature: User logins In order to have extended abilities As a site user I need to be able to login Background: Given a site have users: | username | password | | everzet | qwerty | Scenario Outline: Only existing users can login Given I am on the “/login” page When I fill in “username” with “<username>” And I fill in “password” with “<password>” And I press “login” in login form Then I should see “<message>” Examples: | username | password | message | | everzet | qwerty | Welcome, everzet | | someone | pa$$word | Login or password is incorrect |
  112. 112. Feature: User logins In order to have extended abilities As a site user I need to be able to login Background: Given a site have users: | username | password | | everzet | qwerty | @javascript Scenario Outline: Only existing users can login Given I am on the “/login” page When I fill in “username” with “<username>” And I fill in “password” with “<password>” And I press “login” in login form Then I should see “<message>” Examples: | username | password | message | | everzet | qwerty | Welcome, everzet | | someone | pa$$word | Login or password is incorrect |
  113. 113. http://Behat.orgQuestions?http://joind.in/2769

×