autotestforphp 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ * 1 major enhancement:
2
+ * Initial release
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Fábio Galvão Rehm
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.rdoc
6
+ Rakefile
7
+ autotestforphp.gemspec
8
+ bin/autotestforphp
9
+ images/fail.png
10
+ images/pass.png
11
+ lib/autotestforphp.rb
12
+ lib/autotestforphp/cli.rb
13
+ lib/autotestforphp/notification.rb
14
+ lib/autotestforphp/notification/linux.rb
15
+ lib/autotestforphp/notification/mac.rb
16
+ lib/autotestforphp/notification/windows.rb
17
+ lib/autotestforphp/result.rb
18
+ script/console
19
+ script/destroy
20
+ script/generate
21
+ test/autotestforphp/test_autotestforphp.rb
22
+ test/cli/test_autotestforphp_cli.rb
23
+ test/test_helper.rb
24
+ test/test_linux.rb
25
+ test/test_mac.rb
26
+ test/test_notification.rb
27
+ test/test_result.rb
28
+ test/test_windows.rb
@@ -0,0 +1,7 @@
1
+
2
+ For more information on autotestforphp, see http://autotestforphp.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
@@ -0,0 +1,139 @@
1
+ = AutotestForPHP
2
+
3
+ * http://github.com/fgrehm/autotestforphp
4
+ * fgrehm@gmail.com
5
+
6
+
7
+ == DESCRIPTION:
8
+
9
+ AutotestForPHP is based off of ZenTest autotest which is a popular Ruby tool for running tests as soon as files get changed:
10
+ * http://www.zenspider.com/ZSS/Products/ZenTest/
11
+
12
+ Code for displaying notifications is based on Carlos Brando autotest-notification gem:
13
+ * http://github.com/carlosbrando/autotest-notification
14
+
15
+ The tool was written on Ruby but you don't need to be a Ruby programmer in order to use it, just make sure you have Ruby and RubyGems installed:
16
+ * http://www.ruby-lang.org
17
+ * http://rubygems.org/read/chapter/3
18
+
19
+
20
+ == REQUIREMENTS:
21
+
22
+ * PHP5
23
+ * PHPUnit
24
+ * Ruby
25
+ * RubyGems
26
+
27
+ * Linux:
28
+ You need to have libnotify binaries installed.
29
+
30
+ For ubuntu this means: sudo apt-get install libnotify-bin
31
+
32
+ Other distributions may package it with other names, do a search for libnotify using your distribution package
33
+ manager.
34
+
35
+ If you use KDE and do not have libnotify-bin installed, it will try to use kdialog which is part of KDE.
36
+ It also works if you have zenity installed.
37
+
38
+ * Mac:
39
+ You need to have Growl and growlnotify installed on your machine.
40
+
41
+ Download Growl[http://growl.info/index.php] and install it like any other application on your Mac.
42
+
43
+ Then you must install the growlnotify.
44
+
45
+ In your shell, cd to the directory on the Growl disk image containing growlnotify, and type ./install.sh.
46
+ That script will install growlnotify to /usr/local/bin and the manpage to /usr/local/man.
47
+
48
+ * Windows:
49
+ You need to have Snarl and ruby-snarl installed on your machine.
50
+
51
+ Download Snarl[http://www.fullphat.net/] and install it like any other application on your machine.
52
+
53
+ Run in the command prompt:
54
+
55
+ gem install ruby-snarl
56
+
57
+
58
+ == INSTALL:
59
+
60
+ gem install autotestforphp --source http://gemcutter.org
61
+
62
+
63
+ == USAGE
64
+
65
+ autotestforphp --install
66
+
67
+ autotestforphp
68
+
69
+ During instalation, AutotestForPHP will create:
70
+
71
+ 1. An empty PHPUnit boostrap file on autotestforphp/bootstrap-autotest.php to be used when running tests
72
+
73
+ 2. An empty config file on autotestforphp/config.autotest
74
+
75
+ 3. A PHPUnit config file on autotestforphp/phpunit-autotest.xml to will configure the bootstrap file to be used,
76
+ tests folder and log results to a XML file needed for displaying notifications:
77
+
78
+ <phpunit bootstrap="./autotestforphp/bootstrap-autotest.php">
79
+ <testsuite name="Application">
80
+ <directory>./test/</directory>
81
+ </testsuite>
82
+ <logging>
83
+ <log type="junit" target="./autotestforphp/logfile.xml" />
84
+ <!-- log type="test-xml" target="./autotestforphp/logfile.xml" for PHPUnit <= 3.2 /-->
85
+ </logging>
86
+ </phpunit>
87
+
88
+ You can specify the folders or files to be watched on <em>autotestforphp/config.autotest</em> file by setting the FOLDERS_TO_WATCH Ruby constant
89
+
90
+ Example:
91
+
92
+ FOLDERS_TO_WATCH = ['./src/**/*', './app/**/*', './test/**/*', './some_specific_file.php']
93
+
94
+ If no folders are specified in config file, AutotestForPHP will watch for changes on the following folders (if they exist):
95
+
96
+ * src
97
+ * app
98
+ * lib
99
+ * test
100
+
101
+
102
+ == CONTRIBUTORS:
103
+
104
+ * Fabio Rehm [http://github.com/fgrehm]
105
+ * Andrea Fiore [http://github.com/web-bug]
106
+
107
+
108
+ == TODO:
109
+
110
+ * Default <em>autotestforphp/bootstrap-autotest.php</em>
111
+ * Write comments about config usage on <em>autotestforphp/config.autotest</em>
112
+ * Folders / files to skip
113
+ * Check if tool was already installed and skip file creation
114
+
115
+
116
+ == LICENSE:
117
+
118
+ (The MIT License)
119
+
120
+ Copyright (c) 2009
121
+
122
+ Permission is hereby granted, free of charge, to any person obtaining
123
+ a copy of this software and associated documentation files (the
124
+ 'Software'), to deal in the Software without restriction, including
125
+ without limitation the rights to use, copy, modify, merge, publish,
126
+ distribute, sublicense, and/or sell copies of the Software, and to
127
+ permit persons to whom the Software is furnished to do so, subject to
128
+ the following conditions:
129
+
130
+ The above copyright notice and this permission notice shall be
131
+ included in all copies or substantial portions of the Software.
132
+
133
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
134
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
135
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
136
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
137
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
138
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
139
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/autotestforphp'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'autotestforphp' do
14
+ self.developer 'Fabio Rehm', 'fgrehm@gmail.com'
15
+ #self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
18
+
19
+ end
20
+
21
+ remove_task :test
22
+
23
+ Rake::TestTask.new do |t|
24
+ t.libs << "lib"
25
+ t.test_files = FileList['test/**/test*.rb']
26
+ t.verbose = true
27
+ end
28
+
29
+
30
+ require 'newgem/tasks'
31
+ Dir['tasks/**/*.rake'].each { |t| load t }
32
+
33
+ # TODO - want other tests/tasks run by default? Add them to the list
34
+ # remove_task :default
35
+ # task :default => [:spec, :features]
@@ -0,0 +1,35 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{autotestforphp}
3
+ s.version = "0.0.3"
4
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
5
+ s.authors = ["F\303\241bio Rehm"]
6
+ s.date = %q{2009-07-24}
7
+ s.default_executable = %q{autotestforphp}
8
+ s.description = %q{Autotest tool for PHP}
9
+ s.email = ["fgrehm@gmail.com"]
10
+ s.executables = ["autotestforphp"]
11
+ s.homepage = %q{http://github.com/fgrehm/autotestforphp}
12
+ s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
13
+ s.files = ["History.txt", "License.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "autotestforphp.gemspec", "bin/autotestforphp", "images/fail.png", "images/pass.png", "lib/autotestforphp.rb", "lib/autotestforphp/cli.rb", "lib/autotestforphp/notification.rb", "lib/autotestforphp/notification/linux.rb", "lib/autotestforphp/notification/mac.rb", "lib/autotestforphp/notification/windows.rb", "lib/autotestforphp/result.rb", "script/console", "script/destroy", "script/generate", "test/autotestforphp/test_autotestforphp.rb", "test/cli/test_autotestforphp_cli.rb", "test/test_helper.rb", "test/test_linux.rb", "test/test_mac.rb", "test/test_notification.rb", "test/test_result.rb", "test/test_windows.rb"]
14
+ s.post_install_message = %q{PostInstall.txt}
15
+ s.rdoc_options = ["--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{autotestforphp}
18
+ s.rubygems_version = %q{1.3.4}
19
+ s.summary = %q{Autotest tool for PHP}
20
+ s.test_files = ["test/cli/test_autotestforphp_cli.rb", "test/test_linux.rb", "test/test_notification.rb", "test/test_helper.rb", "test/test_windows.rb", "test/test_result.rb", "test/test_mac.rb", "test/autotestforphp/test_autotestforphp.rb"]
21
+
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_development_dependency(%q<hoe>, [">= 2.3.2"])
29
+ else
30
+ s.add_dependency(%q<hoe>, [">= 2.3.2"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<hoe>, [">= 2.3.2"])
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2009-7-22.
4
+ # Copyright (c) 2009. All rights reserved.
5
+
6
+ require 'rubygems'
7
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/autotestforphp")
8
+ require "autotestforphp/cli"
9
+
10
+ Autotestforphp::CLI.execute(STDOUT, ARGV)
Binary file
Binary file
@@ -0,0 +1,192 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'date'
5
+ require 'rexml/document'
6
+ require 'autotestforphp/notification'
7
+ require 'autotestforphp/result'
8
+
9
+ class Autotestforphp
10
+ VERSION = '0.0.3'
11
+
12
+ class << self
13
+ def install
14
+ new.install
15
+ end
16
+ def run(folders_to_watch)
17
+ folders_to_watch.map!{ |folder| File.expand_path(folder) }
18
+ atp = new
19
+ atp.watch(folders_to_watch)
20
+ atp.run
21
+ end
22
+ end
23
+
24
+ attr_accessor(:files_to_watch,
25
+ :filters,
26
+ :interrupted,
27
+ :last_mtime,
28
+ :tainted,
29
+ :wants_to_quit)
30
+
31
+ def initialize
32
+ # reset
33
+ self.files_to_watch = []
34
+ end
35
+
36
+ def base_path=(path)
37
+ @base_path = path
38
+ end
39
+ def base_path
40
+ if @base_path.nil?
41
+ self.base_path = File.expand_path('./') + "/"
42
+ end
43
+ @base_path
44
+ end
45
+ def config_file_path
46
+ "#{base_path}autotestforphp/config.autotest"
47
+ end
48
+ def phpunit_log_file_path
49
+ "#{base_path}autotestforphp/logfile.xml"
50
+ end
51
+ def phpunit_config_file_path
52
+ "#{base_path}autotestforphp/phpunit-autotest.xml"
53
+ end
54
+ def bootstrap_file_path
55
+ "#{base_path}autotestforphp/bootstrap-autotest.php"
56
+ end
57
+
58
+ def phpunit_config_file_exists?
59
+ File.exist?(phpunit_config_file_path)
60
+ end
61
+ def bootstrap_file_exists?
62
+ File.exist?(bootstrap_file_path)
63
+ end
64
+ def phpunit_log_file_exists?
65
+ File.exist?(phpunit_log_file_path)
66
+ end
67
+ def config_file_exists?
68
+ File.exist?(config_file_path)
69
+ end
70
+
71
+ def make_test_cmd
72
+ case RUBY_PLATFORM
73
+ when /linux/,/darwin/
74
+ cmd = "phpunit"
75
+ when /mswin/
76
+ cmd = "phpunit.bat"
77
+ else
78
+ raise('Your OS not supported yet!')
79
+ end
80
+ "#{cmd} --configuration \"#{phpunit_config_file_path}\""
81
+ end
82
+
83
+ def install
84
+ Dir.mkdir("#{base_path}autotestforphp/") unless File.exist?("#{base_path}autotestforphp/")
85
+ File.open(phpunit_config_file_path, 'w') do |f|
86
+ f.puts <<-CONFIG
87
+ <phpunit bootstrap="./autotestforphp/bootstrap-autotest.php">
88
+ <testsuite name="Application">
89
+ <directory>./test/</directory>
90
+ </testsuite>
91
+ <logging>
92
+ <log type="junit" target="./autotestforphp/logfile.xml" />
93
+ <!-- log type="test-xml" target="./autotestforphp/logfile.xml" for PHPUnit <= 3.2 /-->
94
+ </logging>
95
+ </phpunit>
96
+ CONFIG
97
+ end
98
+ File.open(bootstrap_file_path, 'w').close
99
+ File.open(config_file_path, 'w').close
100
+ end
101
+
102
+ def run
103
+ add_sigint_handler
104
+
105
+ loop do # ^c handler
106
+ begin
107
+ run_all_tests
108
+ wait_for_changes
109
+ rescue Interrupt
110
+ break if self.wants_to_quit
111
+ reset
112
+ end
113
+ end
114
+ end
115
+
116
+ def run_all_tests
117
+ cmd = make_test_cmd
118
+ self.last_mtime = Time.now
119
+
120
+ clear_log
121
+ clear_screen
122
+ puts cmd
123
+ system(cmd)
124
+
125
+ notify
126
+ end
127
+ def watch(folders)
128
+ self.last_mtime = Time.now
129
+ self.filters = folders
130
+ folders.each do |arg|
131
+ Dir[arg].each do |file|
132
+ self.files_to_watch << file unless File.directory?(file)
133
+ end
134
+ end
135
+ end
136
+ def files_have_changed
137
+ not self.files_to_watch.find { |f|
138
+ File.exist?(f) and File.mtime(f) > self.last_mtime
139
+ }.nil?
140
+ end
141
+ def add_sigint_handler
142
+ trap 'INT' do
143
+ if self.interrupted then
144
+ self.wants_to_quit = true
145
+ else
146
+ puts "Interrupt a second time to quit"
147
+ self.interrupted = true
148
+ sleep 1.5
149
+ raise Interrupt, nil # let the run loop catch it
150
+ end
151
+ end
152
+ end
153
+ def wait_for_changes
154
+ sleep 1.5 until files_have_changed
155
+ end
156
+ def reset
157
+ self.interrupted = false
158
+ self.tainted = false
159
+ self.wants_to_quit = false
160
+ self.watch(self.filters)
161
+ end
162
+
163
+ private
164
+
165
+ def clear_log
166
+ File.delete(phpunit_log_file_path) if phpunit_log_file_exists?
167
+ end
168
+ def clear_screen
169
+ case RUBY_PLATFORM
170
+ when /linux/,/darwin/
171
+ system("clear")
172
+ when /mswin/
173
+ system("cls")
174
+ else
175
+ raise('Your OS not supported yet!')
176
+ end
177
+ end
178
+ def notify
179
+ unless File.exist?(phpunit_log_file_path) and File.size(phpunit_log_file_path) > 0
180
+ msg = 'Tests could not be executed'
181
+ img = Notification::Config.fail_image
182
+ else
183
+ f = File.new(phpunit_log_file_path)
184
+ result = Result.build_from_xml(f)
185
+ f.close
186
+ msg = result.message
187
+ img = result.image
188
+ end
189
+
190
+ Notification.notify('Autotest for PHP', msg, img)
191
+ end
192
+ end
@@ -0,0 +1,43 @@
1
+ require 'optparse'
2
+
3
+ class Autotestforphp
4
+ class CLI
5
+ def self.execute(stdout, arguments=['--run'])
6
+ arguments = ['--run'] unless arguments.size > 0 # defaults to run
7
+
8
+ OptionParser.new do |opts|
9
+ opts.banner = <<-BANNER.gsub(/^ /,'')
10
+ Usage: #{File.basename($0)} [options]
11
+
12
+ Options are:
13
+ BANNER
14
+
15
+ opts.separator("")
16
+
17
+ opts.on('-i', '--install',
18
+ 'Install AutotestForPHP') do
19
+ Autotestforphp.install
20
+ stdout.puts 'Autotest for PHP was installed successfully'
21
+ end
22
+
23
+ opts.on('-r', '--run',
24
+ 'Run AutotestForPHP (default)') do
25
+ config_file = File.expand_path('./autotestforphp/config.autotest')
26
+ load config_file if File.exist?(config_file)
27
+
28
+ unless defined?(FOLDERS_TO_WATCH)
29
+ folders = ["./src/**/*", "./test/**/*", "./app/**/*", "./lib/**/*"]
30
+ else
31
+ folders = FOLDERS_TO_WATCH
32
+ end
33
+ Autotestforphp.run(folders)
34
+ end
35
+
36
+ opts.on("-h", "--help",
37
+ "Show this help message.") { stdout.puts opts; exit }
38
+
39
+ opts.parse!(arguments)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,38 @@
1
+ class Autotestforphp
2
+ module Notification
3
+ class Config
4
+
5
+ class << self
6
+ attr_reader :images_directory
7
+ attr_accessor :success_image, :fail_image#, :expiration_in_seconds
8
+
9
+ def images_directory=(path)
10
+ @images_directory = File.expand_path(path)
11
+
12
+ @success_image = "#{@images_directory}/pass.png"
13
+ @fail_image = "#{@images_directory}/fail.png"
14
+ end
15
+ end
16
+
17
+ self.images_directory = "#{File.dirname(__FILE__)}/../../images/"
18
+
19
+ # self.expiration_in_seconds = 3
20
+
21
+ end
22
+
23
+ class << self
24
+ def notify(title, msg, img = Config.success_image)
25
+ case RUBY_PLATFORM
26
+ when /linux/
27
+ Linux.notify(title, msg, img)
28
+ when /darwin/
29
+ Mac.notify(title, msg, img)
30
+ when /mswin/
31
+ Windows.notify(title, msg, img)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ %w{ linux mac windows }.each { |x| require "autotestforphp/notification/#{x}" }
@@ -0,0 +1,42 @@
1
+ class Autotestforphp
2
+ module Notification
3
+ module Linux
4
+ class << self
5
+
6
+ def notify(title, msg, img)
7
+ if has_notify?
8
+ notify_send(title, msg, img)
9
+ elsif has_zenity?
10
+ zenity(title, msg, img)
11
+ elsif has_kdialog?
12
+ kdialog(title, msg, img)
13
+ end
14
+ end
15
+
16
+ def has_notify?
17
+ system "which notify-send > /dev/null 2>&1"
18
+ end
19
+
20
+ def has_kdialog?
21
+ system "which kdialog > /dev/null 2>&1"
22
+ end
23
+
24
+ def has_zenity?
25
+ system "which zenity > /dev/null 2>&1"
26
+ end
27
+
28
+ def notify_send(title, msg, img)
29
+ system "notify-send -i #{img} '#{title}' '#{msg}'"
30
+ end
31
+
32
+ def kdialog(title, msg, img)
33
+ system "kdialog --title '#{title}' --passivepopup '<img src=\"#{img}\" align=\"middle\"> #{msg}'"
34
+ end
35
+
36
+ def zenity(title, msg, img)
37
+ system "zenity --info --text='#{msg}' --title='#{title}'"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,17 @@
1
+ require 'snarl' if RUBY_PLATFORM =~ /mswin/
2
+
3
+ class Autotestforphp
4
+ module Notification
5
+ module Mac
6
+ @last_test_failed = false
7
+
8
+ class << self
9
+
10
+ def notify(title, msg, img)
11
+ system "growlnotify -n autotest --image #{img} -m '#{msg}' -t #{title} -w"
12
+ #note: -w stops execution until growl notification desapears
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require 'snarl' if RUBY_PLATFORM =~ /mswin/
2
+
3
+ class Autotestforphp
4
+ module Notification
5
+ module Windows
6
+ class << self
7
+ def notify(title, msg, img)
8
+ Snarl.show_message(title, msg, img)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,42 @@
1
+ class Autotestforphp
2
+ class Result
3
+ include REXML
4
+
5
+ attr_reader(:num_tests,
6
+ :num_assertions,
7
+ :num_errors,
8
+ :num_failures)
9
+
10
+ def initialize(num_tests, num_assertions, num_errors, num_failures)
11
+ @num_tests = num_tests
12
+ @num_assertions = num_assertions
13
+ @num_errors = num_errors
14
+ @num_failures = num_failures
15
+ end
16
+
17
+ def message
18
+ "#{num_tests} tests, #{num_assertions} assertions, #{num_failures} failures, #{num_errors} errors"
19
+ end
20
+
21
+ def image
22
+ config = Autotestforphp::Notification::Config
23
+ if num_failures == 0 and num_errors == 0
24
+ config.success_image
25
+ else
26
+ config.fail_image
27
+ end
28
+ end
29
+
30
+ def self.build_from_xml(xml)
31
+ unless xml.is_a?(Document)
32
+ xml = Document.new(xml)
33
+ end
34
+ results = XPath.first(xml, '//testsuite')
35
+ num_tests = results.attributes["tests"].to_i
36
+ num_failures = results.attributes["failures"].to_i
37
+ num_errors = results.attributes["errors"].to_i
38
+ num_assertions = results.attributes["assertions"].to_i
39
+ new(num_tests, num_assertions, num_errors, num_failures)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/autotestforphp.rb'}"
9
+ puts "Loading autotestforphp gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,73 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ # NOT TESTED:
4
+ # add_sigint_handler
5
+ # notify
6
+ # reset
7
+ # run
8
+
9
+ class TestAutotestforphp < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @atp = Autotestforphp.new
13
+ @atp.base_path = File.dirname(__FILE__) + '/'
14
+ end
15
+
16
+ def teardown
17
+ File.delete(File.dirname(__FILE__) + '/sample.php') if File.exist?(File.dirname(__FILE__) + '/sample.php')
18
+ File.delete(File.dirname(__FILE__) + '/sample2.php') if File.exist?(File.dirname(__FILE__) + '/sample2.php')
19
+ File.delete(@atp.bootstrap_file_path) if File.exist?(@atp.bootstrap_file_path)
20
+ File.delete(@atp.phpunit_config_file_path) if File.exist?(@atp.phpunit_config_file_path)
21
+ File.delete(@atp.config_file_path) if File.exist?(@atp.config_file_path)
22
+ Dir.delete("#{@atp.base_path}autotestforphp/") if File.exist?("#{@atp.base_path}autotestforphp/")
23
+ end
24
+
25
+ def test_detect_file_change
26
+ create_file('sample.php')
27
+ create_file('sample2.php')
28
+
29
+ @atp.watch(File.dirname(__FILE__) + '/sample*')
30
+ assert !@atp.files_have_changed
31
+
32
+ sleep 1
33
+ touch_file('sample2.php')
34
+
35
+ assert @atp.files_have_changed
36
+ @atp.last_mtime = Time.now
37
+
38
+ sleep 1
39
+ assert !@atp.files_have_changed
40
+ end
41
+
42
+ def test_make_test_cmd_linux
43
+ @atp.class.const_set :RUBY_PLATFORM, 'linux'
44
+ assert_equal "phpunit --configuration \"#{@atp.phpunit_config_file_path}\"", @atp.make_test_cmd
45
+ end
46
+
47
+ def test_make_test_cmd_windows
48
+ @atp.class.const_set :RUBY_PLATFORM, 'mswin'
49
+ assert_equal "phpunit.bat --configuration \"#{@atp.phpunit_config_file_path}\"", @atp.make_test_cmd
50
+ end
51
+
52
+ def test_install
53
+ @atp.install
54
+
55
+ assert @atp.phpunit_config_file_exists?
56
+ assert @atp.bootstrap_file_exists?
57
+ assert @atp.config_file_exists?
58
+ end
59
+
60
+ # def test_make_test_cmd_mac
61
+ #
62
+ # end
63
+
64
+ private
65
+ def create_file(file_name)
66
+ File.new("#{File.dirname(__FILE__)}/#{file_name}", 'w').close
67
+ end
68
+ def touch_file(file_name)
69
+ File.open("#{File.dirname(__FILE__)}/#{file_name}", 'w') do |f|
70
+ f.puts 'test'
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,42 @@
1
+ require File.join(File.dirname(__FILE__), '..', "test_helper.rb")
2
+ require 'autotestforphp/cli'
3
+ require 'mocha'
4
+
5
+ class TestAutotestforphpCli < Test::Unit::TestCase
6
+ def setup
7
+ @atp = Autotestforphp
8
+ end
9
+
10
+ def test_default_folders_to_watch
11
+ @atp.expects(:run).
12
+ with(["./src/**/*", "./test/**/*", "./app/**/*", "./lib/**/*"]).
13
+ once
14
+
15
+ execute
16
+ end
17
+
18
+ def test_loads_folders_from_config
19
+ @atp.const_set :FOLDERS_TO_WATCH, ["./src/**/*"]
20
+ @atp.expects(:run).
21
+ with(["./src/**/*"]).
22
+ once
23
+
24
+ execute
25
+ end
26
+
27
+ def test_print_message_after_installation
28
+ Autotestforphp.expects(:install).
29
+ once
30
+
31
+ execute(['--install'])
32
+
33
+ assert_match(/Autotest for PHP was installed successfully/, @stdout)
34
+ end
35
+ private
36
+
37
+ def execute(args = [])
38
+ Autotestforphp::CLI.execute(@stdout_io = StringIO.new, args)
39
+ @stdout_io.rewind
40
+ @stdout = @stdout_io.read
41
+ end
42
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'stringio'
3
+ require 'test/unit'
4
+ require 'mocha'
5
+ require File.dirname(__FILE__) + '/../lib/autotestforphp'
6
+
7
+ module Test
8
+ module Unit
9
+ class TestCase
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestLinux < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @notifier = Autotestforphp::Notification::Linux
7
+ end
8
+
9
+ def test_notify_when_use_notify
10
+ @notifier.expects(:has_notify?).returns(true)
11
+ verify_notify(:notify_send)
12
+ end
13
+
14
+ def test_notify_when_use_zenity
15
+ @notifier.expects(:has_notify?).returns(false)
16
+ @notifier.expects(:has_zenity?).returns(true)
17
+ verify_notify(:zenity)
18
+ end
19
+
20
+ def test_notify_when_use_kdialog
21
+ @notifier.expects(:has_notify?).returns(false)
22
+ @notifier.expects(:has_zenity?).returns(false)
23
+ @notifier.expects(:has_kdialog?).returns(true)
24
+ verify_notify(:kdialog)
25
+ end
26
+
27
+ def test_notify_send
28
+ @notifier.expects(:system).with('notify-send -i image \'title\' \'msg\'')
29
+ @notifier.notify_send("title", "msg", "image")
30
+ end
31
+
32
+ def test_notify_kdialog
33
+ @notifier.expects(:system).with('kdialog --title \'title\' --passivepopup \'<img src="image" align="middle"> msg\'')
34
+ @notifier.kdialog("title", "msg", "image")
35
+ end
36
+
37
+ def test_notify_zenity
38
+ @notifier.expects(:system).with('zenity --info --text=\'msg\' --title=\'title\'')
39
+ @notifier.zenity("title", "msg", "image")
40
+ end
41
+
42
+ def test_has_zenity?
43
+ @notifier.expects(:system).with('which zenity > /dev/null 2>&1')
44
+ @notifier.has_zenity?
45
+ end
46
+
47
+ def test_has_notify?
48
+ @notifier.expects(:system).with('which notify-send > /dev/null 2>&1')
49
+ @notifier.has_notify?
50
+ end
51
+
52
+ def test_has_kdialog?
53
+ @notifier.expects(:system).with('which kdialog > /dev/null 2>&1')
54
+ @notifier.has_kdialog?
55
+ end
56
+
57
+ private
58
+
59
+ def verify_notify(method)
60
+ @notifier.expects(method).returns("title", "msg", "image")
61
+ @notifier.notify("title", "msg", "image")
62
+ end
63
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestMac < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @notifier = Autotestforphp::Notification::Mac
7
+ @notifier.stubs(:system)
8
+ end
9
+
10
+ def test_notify
11
+ @notifier.expects(:system).with("growlnotify -n autotest --image image -m 'msg' -t title")
12
+ @notifier.notify("title", "msg", "image")
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNotification < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @title = "title"
7
+ @msg = "message"
8
+ @image = "image"
9
+ end
10
+
11
+ def test_notify_when_os_is_windows
12
+ notifier = Autotestforphp::Notification::Windows
13
+ notifier.expects(:notify).with(@title, @msg, @image)
14
+ verify_to("mswin")
15
+ end
16
+
17
+ def test_notify_when_os_is_linux
18
+ notifier = Autotestforphp::Notification::Linux
19
+ notifier.expects(:notify).with(@title, @msg, @image)
20
+ verify_to("linux")
21
+ end
22
+
23
+ def test_notify_when_os_is_mac
24
+ notifier = Autotestforphp::Notification::Mac
25
+ notifier.expects(:notify).with(@title, @msg, @image)
26
+ verify_to("darwin")
27
+ end
28
+
29
+ private
30
+
31
+ def verify_to(so)
32
+ Autotestforphp::Notification.const_set :RUBY_PLATFORM, so
33
+ Autotestforphp::Notification.notify(@title, @msg, @image)
34
+ end
35
+ end
@@ -0,0 +1,72 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestResult < Test::Unit::TestCase
4
+ include REXML
5
+
6
+ def test_can_parse_xml
7
+ verify_results(10, 4, 2, 1)
8
+ verify_results(10, 0, 0, 0)
9
+ verify_results(10, 2, 3, 1)
10
+ verify_results(100, 200, 22, 51)
11
+ end
12
+
13
+ def test_message
14
+ verify_message(100, 200, 1, 0)
15
+ verify_message(12, 22, 1, 7)
16
+ verify_message(13, 5, 0, 3)
17
+ end
18
+
19
+ def test_image_when_all_passed
20
+ result = create_result(100, 100, 0, 0)
21
+
22
+ assert_equal(Autotestforphp::Notification::Config.success_image, result.image)
23
+ end
24
+
25
+ def test_image_when_failed
26
+ # result = create_result(100, 100, 0, 0)
27
+ #
28
+ # assert_equal(Autotestforphp::Notification::Config.success_image)
29
+ end
30
+
31
+ private
32
+
33
+ def create_result(num_tests, num_assertions, num_errors, num_failures)
34
+ xml = build_xml(num_tests, num_assertions, num_errors, num_failures)
35
+ Autotestforphp::Result.build_from_xml(xml)
36
+ end
37
+
38
+ def verify_message(num_tests, num_assertions, num_errors, num_failures)
39
+ result = create_result(num_tests, num_assertions, num_errors, num_failures)
40
+
41
+ assert_equal("#{num_tests} tests, #{num_assertions} assertions, #{num_failures} failures, #{num_errors} errors", result.message)
42
+ end
43
+
44
+ def verify_results(num_tests, num_assertions, num_errors, num_failures)
45
+ result = create_result(num_tests, num_assertions, num_errors, num_failures)
46
+
47
+ assert_equal(num_tests, result.num_tests)
48
+ assert_equal(num_assertions, result.num_assertions)
49
+ assert_equal(num_errors, result.num_errors)
50
+ assert_equal(num_failures, result.num_failures)
51
+ end
52
+
53
+ def build_xml(num_tests, num_assertions, num_errors, num_failures)
54
+ <<EOF
55
+ <?xml version="1.0" encoding="UTF-8"?>
56
+ <testsuites>
57
+ <testsuite name="FailureErrorTest" file="/home/sb/FailureErrorTest.php" tests="#{num_tests}" assertions="#{num_assertions}" failures="#{num_failures}" errors="#{num_errors}" time="0.019744">
58
+ <testcase name="testFailure" class="FailureErrorTest" file="/home/sb/FailureErrorTest.php" line="6" assertions="1" time="0.011456">
59
+ <failure type="PHPUnit_Framework_ExpectationFailedException">
60
+ failure description
61
+ </failure>
62
+ </testcase>
63
+ <testcase name="testError" class="FailureErrorTest" file="/home/sb/FailureErrorTest.php" line="11" assertions="0" time="0.008288">
64
+ <error type="Exception">testError(FailureErrorTest)
65
+ exception description
66
+ </error>
67
+ </testcase>
68
+ </testsuite>
69
+ </testsuites>
70
+ EOF
71
+ end
72
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class Snarl
4
+ end
5
+
6
+ class TestWindows < Test::Unit::TestCase
7
+ def test_notify
8
+ Snarl.expects(:show_message).with("title", "msg", "image")
9
+ Autotestforphp::Notification::Windows.notify("title", "msg", "image")
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autotestforphp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Fabio Rehm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-25 00:00:00 -03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.2
24
+ version:
25
+ description: |-
26
+ AutotestForPHP is based off of ZenTest autotest which is a popular Ruby tool for running tests as soon as files get changed:
27
+ * http://www.zenspider.com/ZSS/Products/ZenTest/
28
+
29
+ Code for displaying notifications is based on Carlos Brando autotest-notification gem:
30
+ * http://github.com/carlosbrando/autotest-notification
31
+
32
+ The tool was written on Ruby but you don't need to be a Ruby programmer in order to use it, just make sure you have Ruby and RubyGems installed:
33
+ * http://www.ruby-lang.org
34
+ * http://rubygems.org/read/chapter/3
35
+ email:
36
+ - fgrehm@gmail.com
37
+ executables:
38
+ - autotestforphp
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - History.txt
43
+ - License.txt
44
+ - Manifest.txt
45
+ - PostInstall.txt
46
+ files:
47
+ - History.txt
48
+ - License.txt
49
+ - Manifest.txt
50
+ - PostInstall.txt
51
+ - README.rdoc
52
+ - Rakefile
53
+ - autotestforphp.gemspec
54
+ - bin/autotestforphp
55
+ - images/fail.png
56
+ - images/pass.png
57
+ - lib/autotestforphp.rb
58
+ - lib/autotestforphp/cli.rb
59
+ - lib/autotestforphp/notification.rb
60
+ - lib/autotestforphp/notification/linux.rb
61
+ - lib/autotestforphp/notification/mac.rb
62
+ - lib/autotestforphp/notification/windows.rb
63
+ - lib/autotestforphp/result.rb
64
+ - script/console
65
+ - script/destroy
66
+ - script/generate
67
+ - test/autotestforphp/test_autotestforphp.rb
68
+ - test/cli/test_autotestforphp_cli.rb
69
+ - test/test_helper.rb
70
+ - test/test_linux.rb
71
+ - test/test_mac.rb
72
+ - test/test_notification.rb
73
+ - test/test_result.rb
74
+ - test/test_windows.rb
75
+ has_rdoc: true
76
+ homepage: http://github.com/fgrehm/autotestforphp
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options:
81
+ - --main
82
+ - README.rdoc
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ version:
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ version:
97
+ requirements: []
98
+
99
+ rubyforge_project: autotestforphp
100
+ rubygems_version: 1.3.5
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: AutotestForPHP is based off of ZenTest autotest which is a popular Ruby tool for running tests as soon as files get changed:
104
  * http://www.zenspider.com/ZSS/Products/ZenTest/
1
105
 
2
106
  Code for displaying notifications is based on Carlos Brando autotest-notification gem:
3
107
  * http://github.com/carlosbrando/autotest-notification
4
108
 
5
109
  The tool was written on Ruby but you don't need to be a Ruby programmer in order to use it, just make sure you have Ruby and RubyGems installed:
6
110
  * http://www.ruby-lang.org
7
111
  * http://rubygems.org/read/chapter/3
112
+ test_files:
113
+ - test/autotestforphp/test_autotestforphp.rb
114
+ - test/cli/test_autotestforphp_cli.rb
115
+ - test/test_helper.rb
116
+ - test/test_linux.rb
117
+ - test/test_mac.rb
118
+ - test/test_notification.rb
119
+ - test/test_result.rb
120
+ - test/test_windows.rb