LoginSignup
0
0

More than 5 years have passed since last update.

phpunit autotest(using guard-shell)

Posted at
$ vi Gemfile
source 'https://rubygems.org'
group :development do
  gem 'guard-shell'
  # Notify
  gem 'libnotify',  require: false
  gem 'rb-inotify', require: false
  gem 'rb-fsevent', require: false
  gem 'growl',      require: false
end
$ bundle
$ rbenv rehash
vi Guardfile
guard 'shell' do
  watch(%r{^protected/(models|components)/(.*)\.php$}){|m|
    testfile = "tests/unit/#{m[0]}/#{m[1]}Test.php"
    run_phpunit(testfile)
  }
  watch(%r{^tests/(.*)Test\.php$}){|m| run_phpunit(m[0]) }
end

def run_phpunit(filename)
  unless FileTest.exist?(filename)
    puts "\n>> Not found #{filename}"
    return
  end

  puts "\n>> run: #{filename}"
  result = `phpunit --bootstrap tests/bootstrap.php #{filename}`
  result =~ /\((.+test.?,.+assertion.?)\)/
  if success = $+
    n "#{success}", File.basename(filename)
    puts ">> passed: #{success}"
  else
    result =~ /(Tests:.+Assertions:.+Failures:.+)/
    failure = $+
    n "Failed", File.basename(filename)
    puts ">> failed"
    puts ">> Error report\n#{result}"
  end
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0