Better PHP Projects with Behat

Better PHP Projects with Behat

Originally presented at Capital Laravel Group

2c91f8dbf323072a564dbc4d97a0b627?s=128

Aaron Kuzemchak

April 08, 2014
Tweet

Transcript

  1. Better PHP Projects with Behat Aaron Kuzemchak April 2014 •

    Capital Laravel Group ! kuzemchak.net • @akuzemchak • github.com/akuzemchak
  2. About me

  3. Technical Lead / Senior Developer Visual Chefs www.visualchefs.com

  4. •Husband & father •Guitarist •Gamer •90’s rock enthusiast •PHP &

    Laravel fan
  5. Where to find me Blog kuzemchak.net Twitter @akuzemchak GitHub akuzemchak

  6. About Visual Chefs

  7. Web development agency in Richmond, VA

  8. Experts in Laravel, ExpressionEngine, and CodeIgniter

  9. A great place to work … and we’re hiring

  10. Let’s talk about Behat

  11. A BDD framework for PHP

  12. BDD means “Behavior-Driven Development”

  13. Plan/spec/test software features using stories

  14. Traditional TDD is for code architecture and design

  15. BDD is for software design and expectations

  16. Define features and scenarios based on acceptance criteria

  17. Define steps to achieve acceptance

  18. So, we specify features and business rules…

  19. In plain, natural language…

  20. This spreadsheet is AMAZING!!!

  21. This fosters communication

  22. Communication leads to understanding

  23. Understanding leads to accurate development

  24. We totally businessed that business meeting!

  25. None
  26. Does this sound familiar?

  27. “We need a way to search the site.” The client

  28. “OK… done.” The developer

  29. “Well, that’s not really what we wanted. Can we try

    it this other way?” The client
  30. “OK… done.” The developer

  31. “Hmm, I don’t think this is working. Am I doing

    something wrong?” The client
  32. “Well, that’s what you told me to make it do.”

    The developer
  33. “Well, maybe that’s not what we meant. Can we try

    it this other way now?” The client
  34. This sucks

  35. How can Behat help with this?

  36. “We need a way to search the site.” The client

  37. Feature: Search In order to easily find content As a

    user I need to be able to search the site
  38. “OK, how do you expect this to work?” The developer

  39. Scenario: Search produces results Given I am on the homepage

    When I fill in the search field with “mario” And I press “Search” Then I should see “It’sa me!”
  40. “What happens if the search doesn’t produce any results?” The

    developer
  41. Scenario: Search produces no results Given I am on the

    homepage When I fill in the search field with “the princess” And I press “Search” Then I should see “We can’t find the princess” And I should see “Please try another search term”
  42. “Hey, can we have the search engine suggest terms if

    the user misspells something?” The client
  43. Scenario: Search makes suggestion for typo Given I am on

    the homepage When I fill in the search field with “tanuki” And I press “Search” Then I should see “Did you mean tanooki?”
  44. Better, right?

  45. Inherent benefits

  46. Less confusion

  47. Living documentation

  48. Works well with the “other” BDD Budget-Driven Development

  49. Easy automated testing, regardless of codebase

  50. Mink

  51. Unified API for controlling browser interactions

  52. •Goutte •Sahi •Zombie.js •Selenium •Selenium 2

  53. Integrates directly into Behat via extension system

  54. Gives you lots of pre-defined scenario steps

  55. None
  56. Demo time

  57. Simple Laravel project with Behat integrated

  58. Three features, each with a few scenarios

  59. Objective Learn to configure Behat

  60. Objective Learn various ways to write scenario steps

  61. Objective Learn to bootstrap Laravel during tests

  62. Objective Learn to utilize Behat’s hook system

  63. Objective Run tests in a real browser

  64. A few disclaimers…

  65. I am not an expert on testing

  66. Behat 3.0 is out later this month… This presentation uses

    2.x
  67. Not sure if my examples demonstrate “the right way” But

    is there really a “right way”?
  68. It’s go time!