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.
PHP Quebec - January 2014
Eric Hogue
@ehogue
erichogue.ca
Guarding Your Code Against
Bugs with Continuous Testing
Continuous Testing
Wikipedia
a software development practice that extends
test-driven development by means of automatic
test execution in the...
How I Discovered it
Test Driven Development
Repetitive ...
Code Kata
Eureka!
Automate the Automated Tests
Searching
autotest
AutoPHPUnit
Watchr
Guard
Plugins
Installation - Settings
Ruby
Install Ruby With RVM
$ curl -sSL https://get.rvm.io | bash
-s stable --ruby
$ ruby -v
ruby 2.1.3p242 (2014-09-19 revision...
RubyGems + Bundler
Gemfile
source 'https://rubygems.org'
group :development do
gem 'guard'
end
bundle install
$ bundle install
Fetching gem metadata from https:
//rubygems.org/...........
...
Installing guard 2.6.1
Yo...
Running Guard
$ bundle exec guard
00:53:09 - ERROR - No Guardfile found,
please create one with `guard init`.
Guardfile
Project root - Guardfile
Home folder - .Guardfile
Home folder - .guard.rb
notification :off
Guardfile
notification :off
guard 'guardname' do
end
Guardfile
notification :off
guard 'guardname', :option => value do
end
Guardfile
notification :off
guard 'guardname', :option => value do
watch(%r{^regex$})
end
Guardfile
Notifications
System Notification
group :development do
gem 'libnotify' #Linux
gem 'growl' #Mac OS
gem 'rb-notifu' #Windows
end
Gemfile
notification :libnotify #Linux
notification :growl #Mac OS
notification :notifu #Windows
Guardfile
Terminal Title
notification :terminal_title
Guardfile
tmux
notification :tmux,
display_message: true
Guardfile
notification :off
No Notifications
PHP Guards
Guard::PHPUnit2
Gemfile
group :development do
...
gem 'guard-phpunit2', :git =>
"https://github.com/EricHogue/guard-
phpunit2.git"
end
Guardfile
guard 'phpunit2', :cli => '--colors',
:tests_path => 'tests' do
watch(%r{^tests/.+Test.php$})
end
Guardfile
guard 'phpunit2', :cli => '--colors',
:tests_path => 'tests' do
watch(%r{^tests/.+Test.php$})
end
Guardfile
guard 'phpunit2', :cli => '--colors',
:tests_path => 'tests' do
watch(%r{^tests/.+Test.php$})
end
Guardfile
guard 'phpunit2', :cli => '--colors',
:tests_path => 'tests' do
watch(%r{^tests/.+Test.php$})
end
bundle exec guard
Guardfile
…
watch(%r{^src/(.+).php$}) { |m|
"tests/#{m[1]}Test.php"
}
%r{^src/(.+).php$}
src/TDD/Factorial.php
"tests/#{m[1]}Test.php"
phpunit tests/TDD/FactorialTest.php
:all_on_start
guard 'phpunit2', :all_on_start =>
true do
end
default => true
:tests_path
guard 'phpunit2', :tests_path =>
'path/to/tests' do
end
default => pwd
:all_after_pass
guard 'phpunit2', :all_after_pass =>
true do
end
default => true
:keep_failed
guard 'phpunit2', :keep_failed =>
true do
end
default => true
:command
guard 'phpunit2', :command =>
'./vendor/bin/phpunit' do
end
default => phpunit
:cli
guard 'phpunit2',
:cli => '--colors' do
end
default => nil
Guard::PHPCS
Gemfile
group :development do
...
gem 'guard-phpcs'
end
Guardfile
guard 'phpcs', :standard => 'PSR2',
:executable => "./vendor/bin/phpcs"
do
watch(%r{.*.php$})
end
Guardfile
guard 'phpcs', :standard => 'PSR2',
:executable => "./vendor/bin/phpcs"
do
watch(%r{.*.php$})
end
Guardfile
guard 'phpcs', :standard => 'PSR2',
:executable => "./vendor/bin/phpcs"
do
watch(%r{.*.php$})
end
Guardfile
guard 'phpcs', :standard => 'PSR2',
:executable => "./vendor/bin/phpcs"
do
watch(%r{.*.php$})
end
PHPCS - PSR2
Guard::PHPMD
Gemfile
group :development do
...
gem 'guard-phpmd'
end
Guardfile
guard 'phpmd',
:executable => './vendor/bin/phpmd',
:rules => 'pmd-rules.xml' do
watch(%r{.*.php$})
end
Guardfile
guard 'phpmd',
:executable => './vendor/bin/phpmd',
:rules => 'pmd-rules.xml' do
watch(%r{.*.php$})
end
Guardfile
guard 'phpmd',
:executable => './vendor/bin/phpmd',
:rules => 'pmd-rules.xml' do
watch(%r{.*.php$})
end
pmd-rules.xml
...
<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml" ...
Guardfile
guard 'phpmd',
:executable => './vendor/bin/phpmd',
:rules => 'pmd-rules.xml' do
watch(%r{.*.php$})
end
PHPMD
Other Guards
More
More than 200 plugins
JavaScript
Gemfile
group :development do
...
gem 'guard-jasmine'
end
Guardfile
guard 'jasmine', :jasmine_url => 'http:
//localhost:8000/SpecRunner.html'
...
end
Guardfile
guard 'jasmine', :jasmine_url => '',
:server => :none do
watch(%r{spec/.+Spec.js$})
end
Guardfile
guard 'jasmine', :jasmine_url => '',
:server => :none do
watch(%r{spec/.+Spec.js$})
end
Guard::Jasmine
LiveReload
LiveReload
Gemfile
group :development do
...
gem 'guard-livereload'
end
Guardfile
guard 'livereload' do
watch(%r{public/.+.(css|js|html)})
end
Guard::Bundler
Gemfile
group :development do
...
gem 'guard-bundler'
end
Guardfile
guard :bundler do
watch('Gemfile')
end
Guard::Bundler
Guard::Shell
Gemfile
group :development do
...
gem 'guard-shell'
end
Guardfile
guard 'shell' do
watch(%r{^.+.php$}) do |m|
`php -l #{m[0]}`
true
end
end
Lint check
Guardfile
`php -l #{m[0]}`
if ($?.success?)
n "#{m[0]} correct",'Syntax',:success
else
n "#{m[0]} incorrect",'Syntax',:fai...
Composer
Guardfile
guard 'shell' do
watch("composer.lock") do |m|
p "Running composer install"
`composer install`
…
end
end
Composer
Inline Guard
Guardfile
require 'guard/plugin'
module ::Guard
class BehatGuard < ::Guard::Plugin
end
end
Guardfile
def start
puts 'Run all Behat tests'
puts `./vendor/bin/behat`
end
Guardfile
def run_on_changes(paths)
paths.each do |file|
puts `./vendor/bin/behat #{file}`
end
end
Guardfile
guard 'BehatGuard' do
watch(%r{^features/.+.feature$})
end
Behat
PHPUnit
PHPCS
PHPMD
php -l
composer install
Jasmine
LiveReload
Behat
Automate Your Automated Test
Questions?
PHP Mentoring: http://phpmentoring.org/
Comments: https://joind.in/13245
twitter: @ehogue
Blog: http://erichogu...
EndlessTunnel.jpg - Trey Ratcliff - https://www.flickr.com/photos/stuckincustoms/4539732832
History.jpg - Morten Diesen - ...
Guarding Your Code Against Bugs with Continuous Testing
Guarding Your Code Against Bugs with Continuous Testing
Guarding Your Code Against Bugs with Continuous Testing
Guarding Your Code Against Bugs with Continuous Testing
You’ve finished this document.
Download and read it offline.
Upcoming SlideShare
Commencer avec le tdd
Next
Upcoming SlideShare
Commencer avec le tdd
Next
Download to read offline and view in fullscreen.

0

Share

Guarding Your Code Against Bugs with Continuous Testing

Download to read offline

TDD (Test Driven Development) is getting more and more popular. But what can you do to take it to the next level?

What if you could know if your tests are passing every time you save a file without taking your hands off the keyboard. This is what continuous testing gives you.

In this session, we will cover how you can continuously test your PHP application. We will cover
- Installation and configuration
- Running the tests
- Running static analysers
- Executing tools that can make your life easier

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

Guarding Your Code Against Bugs with Continuous Testing

  1. 1. PHP Quebec - January 2014 Eric Hogue @ehogue erichogue.ca Guarding Your Code Against Bugs with Continuous Testing
  2. 2. Continuous Testing
  3. 3. Wikipedia a software development practice that extends test-driven development by means of automatic test execution in the background. http://en.wikipedia.org/wiki/Continuous_test-driven_development
  4. 4. How I Discovered it
  5. 5. Test Driven Development
  6. 6. Repetitive ...
  7. 7. Code Kata
  8. 8. Eureka!
  9. 9. Automate the Automated Tests
  10. 10. Searching
  11. 11. autotest
  12. 12. AutoPHPUnit
  13. 13. Watchr
  14. 14. Guard
  15. 15. Plugins
  16. 16. Installation - Settings
  17. 17. Ruby
  18. 18. Install Ruby With RVM $ curl -sSL https://get.rvm.io | bash -s stable --ruby $ ruby -v ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]
  19. 19. RubyGems + Bundler
  20. 20. Gemfile source 'https://rubygems.org' group :development do gem 'guard' end
  21. 21. bundle install $ bundle install Fetching gem metadata from https: //rubygems.org/........... ... Installing guard 2.6.1 Your bundle is complete!
  22. 22. Running Guard $ bundle exec guard 00:53:09 - ERROR - No Guardfile found, please create one with `guard init`.
  23. 23. Guardfile
  24. 24. Project root - Guardfile
  25. 25. Home folder - .Guardfile
  26. 26. Home folder - .guard.rb
  27. 27. notification :off Guardfile
  28. 28. notification :off guard 'guardname' do end Guardfile
  29. 29. notification :off guard 'guardname', :option => value do end Guardfile
  30. 30. notification :off guard 'guardname', :option => value do watch(%r{^regex$}) end Guardfile
  31. 31. Notifications
  32. 32. System Notification
  33. 33. group :development do gem 'libnotify' #Linux gem 'growl' #Mac OS gem 'rb-notifu' #Windows end Gemfile
  34. 34. notification :libnotify #Linux notification :growl #Mac OS notification :notifu #Windows Guardfile
  35. 35. Terminal Title
  36. 36. notification :terminal_title Guardfile
  37. 37. tmux
  38. 38. notification :tmux, display_message: true Guardfile
  39. 39. notification :off No Notifications
  40. 40. PHP Guards
  41. 41. Guard::PHPUnit2
  42. 42. Gemfile group :development do ... gem 'guard-phpunit2', :git => "https://github.com/EricHogue/guard- phpunit2.git" end
  43. 43. Guardfile guard 'phpunit2', :cli => '--colors', :tests_path => 'tests' do watch(%r{^tests/.+Test.php$}) end
  44. 44. Guardfile guard 'phpunit2', :cli => '--colors', :tests_path => 'tests' do watch(%r{^tests/.+Test.php$}) end
  45. 45. Guardfile guard 'phpunit2', :cli => '--colors', :tests_path => 'tests' do watch(%r{^tests/.+Test.php$}) end
  46. 46. Guardfile guard 'phpunit2', :cli => '--colors', :tests_path => 'tests' do watch(%r{^tests/.+Test.php$}) end
  47. 47. bundle exec guard
  48. 48. Guardfile … watch(%r{^src/(.+).php$}) { |m| "tests/#{m[1]}Test.php" }
  49. 49. %r{^src/(.+).php$} src/TDD/Factorial.php "tests/#{m[1]}Test.php" phpunit tests/TDD/FactorialTest.php
  50. 50. :all_on_start guard 'phpunit2', :all_on_start => true do end default => true
  51. 51. :tests_path guard 'phpunit2', :tests_path => 'path/to/tests' do end default => pwd
  52. 52. :all_after_pass guard 'phpunit2', :all_after_pass => true do end default => true
  53. 53. :keep_failed guard 'phpunit2', :keep_failed => true do end default => true
  54. 54. :command guard 'phpunit2', :command => './vendor/bin/phpunit' do end default => phpunit
  55. 55. :cli guard 'phpunit2', :cli => '--colors' do end default => nil
  56. 56. Guard::PHPCS
  57. 57. Gemfile group :development do ... gem 'guard-phpcs' end
  58. 58. Guardfile guard 'phpcs', :standard => 'PSR2', :executable => "./vendor/bin/phpcs" do watch(%r{.*.php$}) end
  59. 59. Guardfile guard 'phpcs', :standard => 'PSR2', :executable => "./vendor/bin/phpcs" do watch(%r{.*.php$}) end
  60. 60. Guardfile guard 'phpcs', :standard => 'PSR2', :executable => "./vendor/bin/phpcs" do watch(%r{.*.php$}) end
  61. 61. Guardfile guard 'phpcs', :standard => 'PSR2', :executable => "./vendor/bin/phpcs" do watch(%r{.*.php$}) end
  62. 62. PHPCS - PSR2
  63. 63. Guard::PHPMD
  64. 64. Gemfile group :development do ... gem 'guard-phpmd' end
  65. 65. Guardfile guard 'phpmd', :executable => './vendor/bin/phpmd', :rules => 'pmd-rules.xml' do watch(%r{.*.php$}) end
  66. 66. Guardfile guard 'phpmd', :executable => './vendor/bin/phpmd', :rules => 'pmd-rules.xml' do watch(%r{.*.php$}) end
  67. 67. Guardfile guard 'phpmd', :executable => './vendor/bin/phpmd', :rules => 'pmd-rules.xml' do watch(%r{.*.php$}) end
  68. 68. pmd-rules.xml ... <rule ref="rulesets/codesize.xml" /> <rule ref="rulesets/design.xml" /> <rule ref="rulesets/naming.xml" /> <rule ref="rulesets/unusedcode.xml" /> <rule ref="rulesets/controversial.xml" /> ...
  69. 69. Guardfile guard 'phpmd', :executable => './vendor/bin/phpmd', :rules => 'pmd-rules.xml' do watch(%r{.*.php$}) end
  70. 70. PHPMD
  71. 71. Other Guards
  72. 72. More More than 200 plugins
  73. 73. JavaScript
  74. 74. Gemfile group :development do ... gem 'guard-jasmine' end
  75. 75. Guardfile guard 'jasmine', :jasmine_url => 'http: //localhost:8000/SpecRunner.html' ... end
  76. 76. Guardfile guard 'jasmine', :jasmine_url => '', :server => :none do watch(%r{spec/.+Spec.js$}) end
  77. 77. Guardfile guard 'jasmine', :jasmine_url => '', :server => :none do watch(%r{spec/.+Spec.js$}) end
  78. 78. Guard::Jasmine
  79. 79. LiveReload
  80. 80. LiveReload
  81. 81. Gemfile group :development do ... gem 'guard-livereload' end
  82. 82. Guardfile guard 'livereload' do watch(%r{public/.+.(css|js|html)}) end
  83. 83. Guard::Bundler
  84. 84. Gemfile group :development do ... gem 'guard-bundler' end
  85. 85. Guardfile guard :bundler do watch('Gemfile') end
  86. 86. Guard::Bundler
  87. 87. Guard::Shell
  88. 88. Gemfile group :development do ... gem 'guard-shell' end
  89. 89. Guardfile guard 'shell' do watch(%r{^.+.php$}) do |m| `php -l #{m[0]}` true end end
  90. 90. Lint check
  91. 91. Guardfile `php -l #{m[0]}` if ($?.success?) n "#{m[0]} correct",'Syntax',:success else n "#{m[0]} incorrect",'Syntax',:failed end
  92. 92. Composer
  93. 93. Guardfile guard 'shell' do watch("composer.lock") do |m| p "Running composer install" `composer install` … end end
  94. 94. Composer
  95. 95. Inline Guard
  96. 96. Guardfile require 'guard/plugin' module ::Guard class BehatGuard < ::Guard::Plugin end end
  97. 97. Guardfile def start puts 'Run all Behat tests' puts `./vendor/bin/behat` end
  98. 98. Guardfile def run_on_changes(paths) paths.each do |file| puts `./vendor/bin/behat #{file}` end end
  99. 99. Guardfile guard 'BehatGuard' do watch(%r{^features/.+.feature$}) end
  100. 100. Behat
  101. 101. PHPUnit PHPCS PHPMD php -l composer install Jasmine LiveReload Behat
  102. 102. Automate Your Automated Test
  103. 103. Questions? PHP Mentoring: http://phpmentoring.org/ Comments: https://joind.in/13245 twitter: @ehogue Blog: http://erichogue.ca/
  104. 104. EndlessTunnel.jpg - Trey Ratcliff - https://www.flickr.com/photos/stuckincustoms/4539732832 History.jpg - Morten Diesen - http://www.flickr.com/photos/mortendiesen/8091682612 StreetLights.jpg - William Warby - http://www.flickr.com/photos/wwarby/2460655511 FadeToGrey.jpg - Andreas Levers - https://www.flickr.com/photos/96dpi/2571056264 Kata.jpg - ser... ser... - http://www.flickr.com/photos/el_ser_lomo/3267627038 Archimedes.jpg - Sputnik Beanburger III - https://www.flickr.com/photos/sputnikbeanburgeriii/4690475562/in/photostream/ GearWork2.jpg - Curious Expeditions - https://www.flickr.com/photos/curiousexpeditions/489992128 SARHelicopter.jpg - UK Ministry of Defence - https://www.flickr.com/photos/defenceimages/8695434365 RelayBox.jpg - Ed Hunsinger - https://www.flickr.com/photos/edrabbit/4698481573 Ruby.jpg - Joren De Groof - https://www.flickr.com/photos/jorendegroof/4470431763 RubyGems.png - Linux Screenshots - https://www.flickr.com/photos/xmodulo/14652484443 Files.jpg - Travis Wise - https://www.flickr.com/photos/photographingtravis/14745936519 Root.jpg - きうこ - https://www.flickr.com/photos/kiuko/9112281601 Home.jpg - Warren - https://www.flickr.com/photos/jety/3277812553 Alarm.jpg - Fabian - https://www.flickr.com/photos/snapsi42/3436162040 Containers.jpg - www.GlynLowe.com - https://www.flickr.com/photos/glynlowe/10921733615 Mess.jpg - Moyan Brenn - https://www.flickr.com/photos/aigle_dore/5481297641 Shells.jpg - Bemep - https://www.flickr.com/photos/40626436@N00/40822551 DoItYourself.jpg - Vlasta Juricek - https://www.flickr.com/photos/vlastula/3229196769 Languages.jpg - Valerie Everett - https://www.flickr.com/photos/valeriebb/3008977110 Javascript.jpg - Nathan Smith - https://www.flickr.com/photos/nathansmith/4704268314 Stacks.jpg - Roman Boed - https://www.flickr.com/photos/romanboed/13356494013 js.png - Chris Williams - https://github.com/voodootikigod/logo.js AssemblyLine.jpg - Fiat Chrysler Automobiles: Corporate - https://www.flickr.com/photos/chryslergroup/13194222244 CarCrash.jpg - JaseMan - http://www.flickr.com/photos/bargas/3695903512/

TDD (Test Driven Development) is getting more and more popular. But what can you do to take it to the next level? What if you could know if your tests are passing every time you save a file without taking your hands off the keyboard. This is what continuous testing gives you. In this session, we will cover how you can continuously test your PHP application. We will cover - Installation and configuration - Running the tests - Running static analysers - Executing tools that can make your life easier

Views

Total views

692

On Slideshare

0

From embeds

0

Number of embeds

4

Actions

Downloads

4

Shares

0

Comments

0

Likes

0

×