SlideShare a Scribd company logo
Drupal 7 Continuous
Integration and Testing
Smashing Phing and Behat for fun & profit
Heya! |°▿▿▿▿°|/
• Claudio Beatrice
• @omissis
• 7+ years experience in PHP
• Founder of the Drupal Italia
Association
• Worked in Italy, France and
Germany
So: D7, CI and Testing
Yeah! Nowadays it’s
possible to leverage the
power of a tool or two to
get a seamless continuous
integration process not
much different to the one
we’re used to when
developing with lower-level
frameworks.
Continuous Integration
Continuous integration (CI) is the practice, in
software engineering, of merging all developer
workspaces with a shared mainline several times a
day.
- Wikipedia
Testing History tldr
BDD
Combining TDD with Domain-Driven Design
Unit testing
Testing code automatically
TDD
Writing tests first
Agile Testing Matrix
by Briack Marick
Acceptance
Testing
Usability
Testing
Unit Testing
Performance
Testing
Technology-facing
Business-facing
Critiqueproduct
Support
programming
What is that about?
Basically, a collection of softwares sporting the ugliest
set of icons in the known universe!
Jenkins
Jenkins is a Java application that monitors executions of
repeated jobs, such as building a software project or jobs
run by cron.
Jenkins
In a nutshell, Jenkins provides an easy-to-use so-called
continuous integration system, making it easier for
developers to integrate changes to the project, and
making it easier for users to obtain a fresh build. The
automated, continuous build increases the productivity.
Phing
A cross-platform build tool for PHP based on Apache Ant
It offers a standard, declarative way(XML) of writing
scripts to handle operations such as packaging,
deploying and testing web application.
It features a rich set of tasks for dealing with file system
operations, SQL executions, code analysis and linting,
documentation generation and much, much more.
Phing
Drush
Drush is a command line shell and scripting interface for
Drupal, a veritable Swiss Army knife designed to make life
easier for those of us who spend some of our working
hours hacking away at the command prompt.
PHPUnit
It’s the de-facto standard unit testing framework for PHP and
part of the larger xUnit family.
Its primary goal is to take the smallest piece of testable
software in the application, isolate it from the rest of the code,
and determine whether it behaves exactly as you expect.
PHPUnit
It provides a very useful set of tools for testing code units
such as:
• Assertions
• Fixtures
• Database testing
• Mock Objects
• Code coverage analysis
• Several kind of logging formats
Behat
Behat is a tool for writing human-readable tests in the
form of a story, using a language called Gherkin, that
describe the behavior of your application.
By writing stories, it is possible to define acceptance
criteria that can be actually executed for testing the
behavior of a web application.
Ambiguity and miscommunication between developers,
business owners and testers can be greatly reduced.
Behat
One vocabulary to rule them all
Behat
Feature: front page
In order to access the website
As an anonymous user
I need to be able to see the login form
Every feature comes with a name, followed by three lines
describing the benefit, the role and the feature itself.
This section is required but not important to Behat in
terms of execution, it’s just there for reading purposes.
Behat
Scenario: Login page shows the correct buttons
Given 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 under
different conditions and it’s composed by three parts: the
context, the event and the outcome
This is the part that will be transformed into a test.
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 not
supposed to be",
$link,
$this->getSession()->getCurrentUrl()
));
}
}
A few more little pieces...
• Git, for versioning code
• Drush Phing Task, for integrating Drush commands into
Phing targets
• Drupal Behat extension, needed to leverage the power
of Drush into our Behat features
• Migrate Module, for importing fixtures and migrating
data whenever needed
• Features Module, for exporting configuration into code
...and files!
• .gitignore, for not tracking a good bunch of files we
don’t need
• drush make, for keeping track of the modules, themes
and libraries to ues
• build.xml, for describing all the actions Phing will have
to take to build the website
• build.ENV.properties, for storing environments variables
used during the build process
• behat.yml.dist, for storing Behat’s configurations
Save the environment(s)!
• local, the developer’s machine, where everyday work is
done.
• dev, a server where the CI actually happens. It gets
rebuilt from scratch and throughly tested every
time(ideally after every push on the repository)
• stage, a server used to deploy “stable” dev snapshots
at a given point in time, usually for letting the client
tests on a more stable environment
Save the environment(s)!
• debug, a copy of the production environment (as
faithful as possible), used for easily reproducing bugs
happening on production and also to test deploys.
• prod, the environment that hosts the final product,
tuned and optimized for best performances.
Let’s sum up a second
Jenkins takes those logs and publishes the results
Jenkins clones the repository and invokes Phing
Phing performs the build of the website, upload the files
and the database and finally launches the tests
PHPUnit and Behat run the tests
and log the results in JUnit format
Time for some action!
Go grab the code at
http://github.com/agavee/drupal7-base
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/
Thank you!
http://silent-voice.org/
http://agavee.com/
@omissis

More Related Content

PDF
Auditing Drupal Sites
ZIP
Five Easy Ways to QA Your Drupal Site
PPT
How to Build and Maintain Quality Drupal Sites with Automated Testing
PPTX
Django strategy-test
PDF
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
PPTX
CI / CD w/ Codeception
PDF
Continuous Integration Testing in Django
PDF
Integration testing - A&BP CC
Auditing Drupal Sites
Five Easy Ways to QA Your Drupal Site
How to Build and Maintain Quality Drupal Sites with Automated Testing
Django strategy-test
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
CI / CD w/ Codeception
Continuous Integration Testing in Django
Integration testing - A&BP CC

What's hot (19)

ODP
Integration Testing in Python
PPTX
Automation testing with Drupal 8
PPTX
Continuous Delivery - Automate & Build Better Software with Travis CI
DOCX
Automation Frame works Instruction Sheet
PDF
How to Use Selenium, Successfully
PDF
Codeception
PDF
UI Testing Automation
PDF
Selenium Frameworks
PDF
Automated testing in Drupal
PDF
Getting Started with Selenium
PPT
Automating Software Releases (Dallas/Ft. Worth Perl Mongers 2004)
PDF
Testing with Codeception
PDF
Drupalcamp Simpletest
PPTX
Automate testing with behat, selenium, phantom js and nightwatch.js (5)
PDF
Codeception introduction and use in Yii
PDF
How To Use Selenium Successfully
PDF
Test all the things! Automated testing with Drupal 8
PDF
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
PPTX
Automated Testing using JavaScript
Integration Testing in Python
Automation testing with Drupal 8
Continuous Delivery - Automate & Build Better Software with Travis CI
Automation Frame works Instruction Sheet
How to Use Selenium, Successfully
Codeception
UI Testing Automation
Selenium Frameworks
Automated testing in Drupal
Getting Started with Selenium
Automating Software Releases (Dallas/Ft. Worth Perl Mongers 2004)
Testing with Codeception
Drupalcamp Simpletest
Automate testing with behat, selenium, phantom js and nightwatch.js (5)
Codeception introduction and use in Yii
How To Use Selenium Successfully
Test all the things! Automated testing with Drupal 8
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Automated Testing using JavaScript
Ad

Similar to Drupal 7 ci and testing (20)

ODP
2014 11 20 Drupal 7 -> 8 test migratie
PDF
Behaviour Testing and Continuous Integration with Drupal
ODP
Behat Workshop at WeLovePHP
PDF
Behavioral driven development with Behat
PPTX
Automation in Drupal
PDF
[drupalday2017] - Behat per Drupal: test automatici e molto di più
PPTX
BDD, Behat & Drupal
PPTX
PHPConf.asia 2016 - BDD with Behat for Beginners
PDF
Behat dpc12
PPTX
Zend con 2016 bdd with behat for beginners
PDF
Modernize Your Drupal Development
PPTX
Automated tests to a REST API
PDF
Behaviour Driven Development con Behat & Drupal
PDF
Behaviour Driven Development con Behat & Drupal
PPT
Behat sauce
PDF
Test your modules
PDF
Сontinuous Integration - step to continuous deployment
PDF
Functional testing with behat
PPT
Getting Started With Jenkins And Drupal
PDF
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
2014 11 20 Drupal 7 -> 8 test migratie
Behaviour Testing and Continuous Integration with Drupal
Behat Workshop at WeLovePHP
Behavioral driven development with Behat
Automation in Drupal
[drupalday2017] - Behat per Drupal: test automatici e molto di più
BDD, Behat & Drupal
PHPConf.asia 2016 - BDD with Behat for Beginners
Behat dpc12
Zend con 2016 bdd with behat for beginners
Modernize Your Drupal Development
Automated tests to a REST API
Behaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & Drupal
Behat sauce
Test your modules
Сontinuous Integration - step to continuous deployment
Functional testing with behat
Getting Started With Jenkins And Drupal
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Ad

Recently uploaded (20)

DOC
学历学位硕士ACAP毕业证,澳大利亚凯斯林大学毕业证留学未毕业
PDF
Modern Furniture Trends & Home Interior Decoration
PPTX
examinophobia;how does it occur and how to solve
PDF
4 Mindset Shifts to Turn Frustration into Focus
PDF
Special Needs Dogs – How to Care for Them with Love .pdf
PPTX
Expert Custom Tailoring Services for All Needs.pptx
PDF
Renovating a Midwest Ranch Rustic Modern Charm with Carved Doors
DOCX
Free Pomodoro Tecnique Effect Guide -25mint - pomodorotimer.com.au
PPTX
hhhsyysvwvsydxuguduehshsvdhvdjbuwbjwjdbwubs
PDF
Uniqaya Night Cream For All Skin Type With Natural Ingredients
PPTX
Hyperlipidemia current medication with lifestyle.
PDF
The Top Life Coach in Haarlem is Life Coach Rudolfo.pdf
PDF
5 Popular Designs of Kashmir Silk Handmade Carpets.pdf
PPTX
Role, role conflict and ascribed and achieved role.pptx
PDF
John Baptist Scalabrini Novena - Fr Luciano Final eddition.pdf
PPTX
GEE2-BEED-II: Ibaloi Indigenous People .pptx
PDF
Echoes of Tomorrow - A Sustainable Legacy for Future Generations.pdf
PDF
Pranotsava Monsoon Retreat - Fazlani Nature's Nest
PPTX
Ethical_Clothing_Presentation for everyone
PDF
PrayerPetals- Where Faith and Womanhood Flourish Together.pdf
学历学位硕士ACAP毕业证,澳大利亚凯斯林大学毕业证留学未毕业
Modern Furniture Trends & Home Interior Decoration
examinophobia;how does it occur and how to solve
4 Mindset Shifts to Turn Frustration into Focus
Special Needs Dogs – How to Care for Them with Love .pdf
Expert Custom Tailoring Services for All Needs.pptx
Renovating a Midwest Ranch Rustic Modern Charm with Carved Doors
Free Pomodoro Tecnique Effect Guide -25mint - pomodorotimer.com.au
hhhsyysvwvsydxuguduehshsvdhvdjbuwbjwjdbwubs
Uniqaya Night Cream For All Skin Type With Natural Ingredients
Hyperlipidemia current medication with lifestyle.
The Top Life Coach in Haarlem is Life Coach Rudolfo.pdf
5 Popular Designs of Kashmir Silk Handmade Carpets.pdf
Role, role conflict and ascribed and achieved role.pptx
John Baptist Scalabrini Novena - Fr Luciano Final eddition.pdf
GEE2-BEED-II: Ibaloi Indigenous People .pptx
Echoes of Tomorrow - A Sustainable Legacy for Future Generations.pdf
Pranotsava Monsoon Retreat - Fazlani Nature's Nest
Ethical_Clothing_Presentation for everyone
PrayerPetals- Where Faith and Womanhood Flourish Together.pdf

Drupal 7 ci and testing

  • 1. Drupal 7 Continuous Integration and Testing Smashing Phing and Behat for fun & profit
  • 2. Heya! |°▿▿▿▿°|/ • Claudio Beatrice • @omissis • 7+ years experience in PHP • Founder of the Drupal Italia Association • Worked in Italy, France and Germany
  • 3. So: D7, CI and Testing Yeah! Nowadays it’s possible to leverage the power of a tool or two to get a seamless continuous integration process not much different to the one we’re used to when developing with lower-level frameworks.
  • 4. Continuous Integration Continuous integration (CI) is the practice, in software engineering, of merging all developer workspaces with a shared mainline several times a day. - Wikipedia
  • 5. Testing History tldr BDD Combining TDD with Domain-Driven Design Unit testing Testing code automatically TDD Writing tests first
  • 6. Agile Testing Matrix by Briack Marick Acceptance Testing Usability Testing Unit Testing Performance Testing Technology-facing Business-facing Critiqueproduct Support programming
  • 7. What is that about? Basically, a collection of softwares sporting the ugliest set of icons in the known universe!
  • 8. Jenkins Jenkins is a Java application that monitors executions of repeated jobs, such as building a software project or jobs run by cron.
  • 9. Jenkins In a nutshell, Jenkins provides an easy-to-use so-called continuous integration system, making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. The automated, continuous build increases the productivity.
  • 10. Phing A cross-platform build tool for PHP based on Apache Ant It offers a standard, declarative way(XML) of writing scripts to handle operations such as packaging, deploying and testing web application. It features a rich set of tasks for dealing with file system operations, SQL executions, code analysis and linting, documentation generation and much, much more.
  • 11. Phing
  • 12. Drush Drush is a command line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend some of our working hours hacking away at the command prompt.
  • 13. PHPUnit It’s the de-facto standard unit testing framework for PHP and part of the larger xUnit family. Its primary goal is to take the smallest piece of testable software in the application, isolate it from the rest of the code, and determine whether it behaves exactly as you expect.
  • 14. PHPUnit It provides a very useful set of tools for testing code units such as: • Assertions • Fixtures • Database testing • Mock Objects • Code coverage analysis • Several kind of logging formats
  • 15. Behat Behat is a tool for writing human-readable tests in the form of a story, using a language called Gherkin, that describe the behavior of your application. By writing stories, it is possible to define acceptance criteria that can be actually executed for testing the behavior of a web application.
  • 16. Ambiguity and miscommunication between developers, business owners and testers can be greatly reduced. Behat One vocabulary to rule them all
  • 17. Behat Feature: front page In order to access the website As an anonymous user I need to be able to see the login form Every feature comes with a name, followed by three lines describing the benefit, the role and the feature itself. This section is required but not important to Behat in terms of execution, it’s just there for reading purposes.
  • 18. Behat Scenario: Login page shows the correct buttons Given 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 under different conditions and it’s composed by three parts: the context, the event and the outcome This is the part that will be transformed into a test.
  • 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 not supposed to be", $link, $this->getSession()->getCurrentUrl() )); } }
  • 20. A few more little pieces... • Git, for versioning code • Drush Phing Task, for integrating Drush commands into Phing targets • Drupal Behat extension, needed to leverage the power of Drush into our Behat features • Migrate Module, for importing fixtures and migrating data whenever needed • Features Module, for exporting configuration into code
  • 21. ...and files! • .gitignore, for not tracking a good bunch of files we don’t need • drush make, for keeping track of the modules, themes and libraries to ues • build.xml, for describing all the actions Phing will have to take to build the website • build.ENV.properties, for storing environments variables used during the build process • behat.yml.dist, for storing Behat’s configurations
  • 22. Save the environment(s)! • local, the developer’s machine, where everyday work is done. • dev, a server where the CI actually happens. It gets rebuilt from scratch and throughly tested every time(ideally after every push on the repository) • stage, a server used to deploy “stable” dev snapshots at a given point in time, usually for letting the client tests on a more stable environment
  • 23. Save the environment(s)! • debug, a copy of the production environment (as faithful as possible), used for easily reproducing bugs happening on production and also to test deploys. • prod, the environment that hosts the final product, tuned and optimized for best performances.
  • 24. Let’s sum up a second Jenkins takes those logs and publishes the results Jenkins clones the repository and invokes Phing Phing performs the build of the website, upload the files and the database and finally launches the tests PHPUnit and Behat run the tests and log the results in JUnit format
  • 25. Time for some action! Go grab the code at http://github.com/agavee/drupal7-base
  • 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/