Drupal 7 ci and testing


Published on

Published in: Lifestyle, Technology
1 Comment
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Drupal 7 ci and testing

  1. 1. Drupal 7 ContinuousIntegration and TestingSmashing Phing and Behat for fun & profit
  2. 2. Heya! |°▿▿▿▿°|/• Claudio Beatrice• @omissis• 7+ years experience in PHP• Founder of the Drupal ItaliaAssociation• Worked in Italy, France andGermany
  3. 3. So: D7, CI and TestingYeah! Nowadays it’spossible to leverage thepower of a tool or two toget a seamless continuousintegration process notmuch different to the onewe’re used to whendeveloping with lower-levelframeworks.
  4. 4. Continuous IntegrationContinuous integration (CI) is the practice, insoftware engineering, of merging all developerworkspaces with a shared mainline several times aday.- Wikipedia
  5. 5. Testing History tldrBDDCombining TDD with Domain-Driven DesignUnit testingTesting code automaticallyTDDWriting tests first
  6. 6. Agile Testing Matrixby Briack MarickAcceptanceTestingUsabilityTestingUnit TestingPerformanceTestingTechnology-facingBusiness-facingCritiqueproductSupportprogramming
  7. 7. What is that about?Basically, a collection of softwares sporting the ugliestset of icons in the known universe!
  8. 8. JenkinsJenkins is a Java application that monitors executions ofrepeated jobs, such as building a software project or jobsrun by cron.
  9. 9. JenkinsIn a nutshell, Jenkins provides an easy-to-use so-calledcontinuous integration system, making it easier fordevelopers to integrate changes to the project, andmaking it easier for users to obtain a fresh build. Theautomated, continuous build increases the productivity.
  10. 10. PhingA cross-platform build tool for PHP based on Apache AntIt offers a standard, declarative way(XML) of writingscripts to handle operations such as packaging,deploying and testing web application.It features a rich set of tasks for dealing with file systemoperations, SQL executions, code analysis and linting,documentation generation and much, much more.
  11. 11. Phing
  12. 12. DrushDrush is a command line shell and scripting interface forDrupal, a veritable Swiss Army knife designed to make lifeeasier for those of us who spend some of our workinghours hacking away at the command prompt.
  13. 13. PHPUnitIt’s the de-facto standard unit testing framework for PHP andpart of the larger xUnit family.Its primary goal is to take the smallest piece of testablesoftware in the application, isolate it from the rest of the code,and determine whether it behaves exactly as you expect.
  14. 14. PHPUnitIt provides a very useful set of tools for testing code unitssuch as:• Assertions• Fixtures• Database testing• Mock Objects• Code coverage analysis• Several kind of logging formats
  15. 15. BehatBehat is a tool for writing human-readable tests in theform of a story, using a language called Gherkin, thatdescribe the behavior of your application.By writing stories, it is possible to define acceptancecriteria that can be actually executed for testing thebehavior of a web application.
  16. 16. Ambiguity and miscommunication between developers,business owners and testers can be greatly reduced.BehatOne vocabulary to rule them all
  17. 17. BehatFeature: front pageIn order to access the websiteAs an anonymous userI need to be able to see the login formEvery feature comes with a name, followed by three linesdescribing the benefit, the role and the feature itself.This section is required but not important to Behat interms of execution, it’s just there for reading purposes.
  18. 18. BehatScenario: Login page shows the correct buttonsGiven I am on “/”Then I should not see the link “register”And I should see the link “login”And I should see the link “forgot password”Every scenario describes how a feature acts underdifferent conditions and it’s composed by three parts: thecontext, the event and the outcomeThis is the part that will be transformed into a test.
  19. 19. Behat/*** @Then /^I should not see the link "(?P<link>[^"]*)"$/*/public function iShouldNotSeeTheLink($link) {$element = $this->getSession()->getPage();$result = $element->findLink($link);if ($result) {throw new Exception(sprintf("The link %s was present on the page %s and was notsupposed to be",$link,$this->getSession()->getCurrentUrl()));}}
  20. 20. A few more little pieces...• Git, for versioning code• Drush Phing Task, for integrating Drush commands intoPhing targets• Drupal Behat extension, needed to leverage the powerof Drush into our Behat features• Migrate Module, for importing fixtures and migratingdata whenever needed• Features Module, for exporting configuration into code
  21. 21. ...and files!• .gitignore, for not tracking a good bunch of files wedon’t need• drush make, for keeping track of the modules, themesand libraries to ues• build.xml, for describing all the actions Phing will haveto take to build the website• build.ENV.properties, for storing environments variablesused during the build process• behat.yml.dist, for storing Behat’s configurations
  22. 22. Save the environment(s)!• local, the developer’s machine, where everyday work isdone.• dev, a server where the CI actually happens. It getsrebuilt from scratch and throughly tested everytime(ideally after every push on the repository)• stage, a server used to deploy “stable” dev snapshotsat a given point in time, usually for letting the clienttests on a more stable environment
  23. 23. Save the environment(s)!• debug, a copy of the production environment (asfaithful as possible), used for easily reproducing bugshappening on production and also to test deploys.• prod, the environment that hosts the final product,tuned and optimized for best performances.
  24. 24. Let’s sum up a secondJenkins takes those logs and publishes the resultsJenkins clones the repository and invokes PhingPhing performs the build of the website, upload the filesand the database and finally launches the testsPHPUnit and Behat run the testsand log the results in JUnit format
  25. 25. Time for some action!Go grab the code athttp://github.com/agavee/drupal7-base
  26. 26. You deserve some moar• http://www.slideshare.net/everzet/bdd-in-symfony2/• http://www.slideshare.net/headrevision/web-acceptance-testing-with-behat/• http://www.exampler.com/old-blog/2003/08/21/• http://www.phpunit.de/manual/current/en/index.html• http://dannorth.net/whats-in-a-story/
  27. 27. Thank you!http://silent-voice.org/http://agavee.com/@omissis