simplecov-phpunit 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7c0f0bf592b51c0a10a3d0ad52e8311f2be68df
4
- data.tar.gz: 7a2b82ba1a1012f48fd1d6e38a8a392d29b37b18
3
+ metadata.gz: e27b3f5fb187ab7e4111b1bbc570e5762e472d7e
4
+ data.tar.gz: f6274cd06ed99c24dbf081ee6a1bd7101b3d70cb
5
5
  SHA512:
6
- metadata.gz: 43db0ccc96affeb47be183650fd50183e451a569de49ac3d51157bee189d1f4d4862d33b4269e5051cfcc44399e6e77276ca2bb18edccde942542a686ae4ef3d
7
- data.tar.gz: 51be9b81f866810fc009ec9005ad3f0f8194fb5c885352c3b7acfb8ddd6380d6a6e88b7b7ead99383a32ced170947356bf379008400a49f6c97768f2c94d5676
6
+ metadata.gz: edf79f212dd2ddcff3634d92488f11fba7cef8acc6719dd6713978712224869ac82b0f9045d223523dbfc90b015b180b9169214eb504304c14f41a4d16cce3b3
7
+ data.tar.gz: 5339b0a04ff840d18027a27c3fb0d0a2d1cb3a721cdfd07cc67e96cbd3800e0a4a8aba1491d73723469c1d6244fefcd58c8ad86505003961e0977b199d62fecf
data/README.md CHANGED
@@ -13,12 +13,12 @@ https://rubygems.org/gems/simplecov-phpunit
13
13
 
14
14
  or via `Gemfile`:
15
15
 
16
- gem 'simplecov-phpunit', '~>0.3'
16
+ gem 'simplecov-phpunit', '~>0.4'
17
17
 
18
18
  or via `.gemspec`:
19
19
 
20
20
  spec.add_development_dependency 'simplecov', '~>0.12'
21
- spec.add_development_dependency 'simplecov-phpunit', '~>0.3'
21
+ spec.add_development_dependency 'simplecov-phpunit', '~>0.4'
22
22
 
23
23
  ## Usage
24
24
 
File without changes
@@ -8,24 +8,36 @@ module SimpleCov
8
8
 
9
9
  class PHPUnit < SimpleCov::Formatter::SimpleFormatter
10
10
 
11
- def initialize()
11
+ def initialize
12
12
  super()
13
13
 
14
14
  @base_dir_path = Dir.pwd
15
15
  @coverage_dir_path = File.expand_path('coverage', @base_dir_path)
16
- @index_html_file = File.open(File.expand_path('index.html', @coverage_dir_path), 'wb')
16
+ assets_dst_path = File.expand_path('_assets', @coverage_dir_path)
17
17
 
18
- simplecov_phpunit_version = Gem::Specification.find_by_name('simplecov-phpunit').version.to_s
19
- @version_html = %{<a href="https://github.com/TheFox/simplecov-phpunit">SimpleCov PHPUnit Formatter #{simplecov_phpunit_version}</a>}
20
- @ruby_version_html = %{<a href="https://www.ruby-lang.org/en/">Ruby #{RUBY_VERSION}</a>}
21
18
 
22
- simplecov_version = Gem::Specification.find_by_name('simplecov').version.to_s
23
- @simplecov_version_html = %{<a href="https://github.com/colszowka/simplecov">SimpleCov #{simplecov_version}</a>}
24
19
 
25
- full_gem_path = Gem::Specification.find_by_name('simplecov-phpunit').full_gem_path
26
- assets_src_path = File.expand_path('assets', full_gem_path)
27
- assets_dst_path = File.expand_path('_assets', @coverage_dir_path)
20
+ simplecov_phpunit_gem = Gem::Specification.find_by_name('simplecov-phpunit')
21
+ assets_src_path = File.expand_path('assets', simplecov_phpunit_gem.full_gem_path)
22
+ @simplecov_phpunit_version_html = %(<a href="https://github.com/TheFox/simplecov-phpunit">SimpleCov PHPUnit Formatter #{simplecov_phpunit_gem.version}</a>)
23
+ @ruby_version_html = %(<a href="https://www.ruby-lang.org/en/">Ruby #{RUBY_VERSION}</a>)
24
+
25
+ simplecov_gem = Gem::Specification.find_by_name('simplecov')
26
+ @simplecov_version_html = %(<a href="https://github.com/colszowka/simplecov">SimpleCov #{simplecov_gem.version}</a>)
27
+
28
+
29
+ FileUtils.rm_rf(assets_dst_path)
28
30
  FileUtils.cp_r(assets_src_path, assets_dst_path)
31
+
32
+
33
+ @bootstrap_css_html = %(<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">)
34
+
35
+ @style_css_href = '_assets/style.css'
36
+ @style_css_html = %(<link href="#{@style_css_href}" rel="stylesheet" />)
37
+
38
+ @jquery_js_html = %(<script src="http://code.jquery.com/jquery-1.12.4.min.js" crossorigin="anonymous"></script>)
39
+
40
+ @bootstrap_js_html = %(<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>)
29
41
  end
30
42
 
31
43
  def format(result)
@@ -35,48 +47,51 @@ module SimpleCov
35
47
  total_status = status_by_percent(result.files.covered_percent)
36
48
  total_percent_f = '%.2f' % result.files.covered_percent
37
49
 
38
- @index_html_file.write(%{<!DOCTYPE html>
39
- <html lang="en">
40
- <head>
41
- <meta charset="UTF-8" />
42
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
43
-
44
- <title>Code Coverage for #{@base_dir_path}</title>
45
-
46
- <link href="_assets/css/bootstrap.min.css" rel="stylesheet">
47
- <link href="_assets/css/style.css" rel="stylesheet">
48
-
49
- </head>
50
- <div class="container">
51
- <table class="table table-bordered">
52
- <thead>
53
- <tr>
54
- <td>&nbsp;</td>
55
- <td colspan="3"><div align="center"><strong>Code Coverage</strong></div></td>
56
- </tr>
57
- <tr>
58
- <td>&nbsp;</td>
59
- <td colspan="3"><div align="center"><strong>Lines</strong></div></td>
60
- </tr>
61
- </thead>
62
- <tr>
63
- <td class="#{total_status}">Total</td>
64
- <td class="#{total_status} big">
65
- <div class="progress">
66
- <div class="progress-bar progress-bar-#{total_status}" role="progressbar" aria-valuenow="#{total_percent_f}" aria-valuemin="0" aria-valuemax="100" style="width: #{total_percent_f}%">
67
- <span class="sr-only">#{total_percent_f}% covered (#{total_status})</span>
68
- </div>
69
- </div>
70
- </td>
71
- <td class="#{total_status} small"><div align="right">#{total_percent_f}%</div></td>
72
- <td class="#{total_status} small"><div align="right">#{result.files.covered_lines}&nbsp;/&nbsp;#{result.files.lines_of_code}</div></td>
73
- </tr>
74
- })
50
+ index_html = ''
51
+ index_html << <<-EOHTML
52
+ <!DOCTYPE html>
53
+ <html lang="en">
54
+ <head>
55
+ <meta charset="UTF-8" />
56
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
57
+
58
+ <title>Code Coverage for #{@base_dir_path}</title>
59
+
60
+ #{@bootstrap_css_html}
61
+ #{@style_css_html}
62
+
63
+ </head>
64
+ <div class="container">
65
+ <table class="table table-bordered">
66
+ <thead>
67
+ <tr>
68
+ <td>&nbsp;</td>
69
+ <td colspan="3"><div align="center"><strong>Code Coverage</strong></div></td>
70
+ </tr>
71
+ <tr>
72
+ <td>&nbsp;</td>
73
+ <td colspan="3"><div align="center"><strong>Lines</strong></div></td>
74
+ </tr>
75
+ </thead>
76
+ <tr>
77
+ <td class="#{total_status}">Total</td>
78
+ <td class="#{total_status} big">
79
+ <div class="progress">
80
+ <div class="progress-bar progress-bar-#{total_status}" role="progressbar" aria-valuenow="#{total_percent_f}" aria-valuemin="0" aria-valuemax="100" style="width: #{total_percent_f}%">
81
+ <span class="sr-only">#{total_percent_f}% covered (#{total_status})</span>
82
+ </div>
83
+ </div>
84
+ </td>
85
+ <td class="#{total_status} small"><div align="right">#{total_percent_f}%</div></td>
86
+ <td class="#{total_status} small"><div align="right">#{result.files.covered_lines}&nbsp;/&nbsp;#{result.files.lines_of_code}</div></td>
87
+ </tr>
88
+ EOHTML
75
89
 
76
90
  result.files.each do |file|
77
91
  relative_file_path = file.filename[@base_dir_path.size.next..-1]
78
92
  # file_name = File.basename(file.filename)
79
- html_file_path = relative_file_path
93
+ html_file_path =
94
+ relative_file_path
80
95
  .split('/')
81
96
  .join('_') + '.html'
82
97
 
@@ -85,79 +100,78 @@ module SimpleCov
85
100
  file_status = status_by_percent(file.covered_percent)
86
101
  file_percent_f = '%.2f' % file.covered_percent
87
102
 
88
- @index_html_file.write(%{
89
-
90
- <tr>
91
- <td class="#{file_status}"><span class="glyphicon glyphicon-file"></span> <a href="#{html_file_path}">#{relative_file_path}</a></td>
92
- <td class="#{file_status} big">
93
- <div class="progress">
94
- <div class="progress-bar progress-bar-#{file_status}" role="progressbar" aria-valuenow="100.00" aria-valuemin="0" aria-valuemax="100" style="width: #{file_percent_f}%">
95
- <span class="sr-only">#{file_percent_f}% covered (#{file_status})</span>
96
- </div>
97
- </div>
98
- </td>
99
- <td class="#{file_status} small"><div align="right">#{file_percent_f}%</div></td>
100
- <td class="#{file_status} small"><div align="right">#{file.covered_lines.count}&nbsp;/&nbsp;#{file.lines_of_code}</div></td>
101
- </tr>
102
-
103
- })
104
-
105
- @html_file = File.open("#{@coverage_dir_path}/#{html_file_path}", 'wb')
106
- @html_file.write(%{<!DOCTYPE html>
107
- <html lang="en">
108
- <head>
109
- <meta charset="UTF-8" />
110
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
111
-
112
- <title>Code Coverage for #{file.filename}</title>
113
-
114
- <link href="_assets/css/bootstrap.min.css" rel="stylesheet">
115
- <link href="_assets/css/style.css" rel="stylesheet">
116
-
117
- </head>
118
- <body>
119
- <header>
120
- <div class="container">
121
- <div class="row">
122
- <div class="col-md-12">
123
- <ol class="breadcrumb">
124
- <li><a href="index.html">#{@base_dir_path}</a></li>
125
- <li class="active">#{relative_file_path}</li>
126
- </ol>
127
- </div>
128
- </div>
129
- </div>
130
- </header>
131
- <div class="container">
132
- <table class="table table-bordered">
133
- <thead>
134
- <tr>
135
- <td>&nbsp;</td>
136
- <td colspan="3"><div align="center"><strong>Code Coverage</strong></div></td>
137
- </tr>
138
- <tr>
139
- <td>&nbsp;</td>
140
- <td colspan="3"><div align="center"><strong>Lines</strong></div></td>
141
- </tr>
142
- </thead>
143
- <tbody>
144
- <tr>
145
- <td class="#{file_status}">Covered</td>
146
- <td class="#{file_status} big">
147
- <div class="progress">
148
- <div class="progress-bar progress-bar-#{file_status}" role="progressbar" aria-valuenow="#{file_percent_f}" aria-valuemin="0" aria-valuemax="100" style="width: #{file_percent_f}%">
149
- <span class="sr-only">#{file_percent_f}% covered (#{file_status})</span>
103
+ index_html << <<-EOHTML
104
+ <tr>
105
+ <td class="#{file_status}"><span class="glyphicon glyphicon-file"></span> <a href="#{html_file_path}">#{relative_file_path}</a></td>
106
+ <td class="#{file_status} big">
107
+ <div class="progress">
108
+ <div class="progress-bar progress-bar-#{file_status}" role="progressbar" aria-valuenow="100.00" aria-valuemin="0" aria-valuemax="100" style="width: #{file_percent_f}%">
109
+ <span class="sr-only">#{file_percent_f}% covered (#{file_status})</span>
110
+ </div>
150
111
  </div>
151
- </div>
152
- </td>
153
- <td class="#{file_status} small"><div align="right">#{file_percent_f}%</div></td>
154
- <td class="#{file_status} small"><div align="right">#{file.covered_lines.count}&nbsp;/&nbsp;#{file.lines_of_code}</div></td>
155
- </tr>
156
- </tbody>
157
- </table>
158
- <table id="code" class="table table-borderless table-condensed">
159
- <tbody>
160
- })
112
+ </td>
113
+ <td class="#{file_status} small"><div align="right">#{file_percent_f}%</div></td>
114
+ <td class="#{file_status} small"><div align="right">#{file.covered_lines.count}&nbsp;/&nbsp;#{file.lines_of_code}</div></td>
115
+ </tr>
116
+ EOHTML
117
+
118
+ html = ''
119
+ html << <<-EOHTML
120
+ <!DOCTYPE html>
121
+ <html lang="en">
122
+ <head>
123
+ <meta charset="UTF-8" />
124
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
125
+
126
+ <title>Code Coverage for #{file.filename}</title>
127
+
128
+ #{@bootstrap_css_html}
129
+ #{@style_css_html}
130
+
131
+ </head>
132
+ <body>
133
+ <header>
134
+ <div class="container">
135
+ <div class="row">
136
+ <div class="col-md-12">
137
+ <ol class="breadcrumb">
138
+ <li><a href="index.html">#{@base_dir_path}</a></li>
139
+ <li class="active">#{relative_file_path}</li>
140
+ </ol>
141
+ </div>
142
+ </div>
143
+ </div>
144
+ </header>
145
+ <div class="container">
146
+ <table class="table table-bordered">
147
+ <thead>
148
+ <tr>
149
+ <td>&nbsp;</td>
150
+ <td colspan="3"><div align="center"><strong>Code Coverage</strong></div></td>
151
+ </tr>
152
+ <tr>
153
+ <td>&nbsp;</td>
154
+ <td colspan="3"><div align="center"><strong>Lines</strong></div></td>
155
+ </tr>
156
+ </thead>
157
+ <tbody>
158
+ <tr>
159
+ <td class="#{file_status}">Covered</td>
160
+ <td class="#{file_status} big">
161
+ <div class="progress">
162
+ <div class="progress-bar progress-bar-#{file_status}" role="progressbar" aria-valuenow="#{file_percent_f}" aria-valuemin="0" aria-valuemax="100" style="width: #{file_percent_f}%">
163
+ <span class="sr-only">#{file_percent_f}% covered (#{file_status})</span>
164
+ </div>
165
+ </div>
166
+ </td>
167
+ <td class="#{file_status} small"><div align="right">#{file_percent_f}%</div></td>
168
+ <td class="#{file_status} small"><div align="right">#{file.covered_lines.count}&nbsp;/&nbsp;#{file.lines_of_code}</div></td>
169
+ </tr>
170
+ </tbody>
171
+ </table>
172
+ <table id="code" class="table table-borderless table-condensed">
173
+ <tbody>
174
+ EOHTML
161
175
 
162
176
  file.lines.each do |line|
163
177
  # puts " line #{line.line_number} #{line.coverage} #{line.status} #{line.src}"
@@ -165,70 +179,73 @@ module SimpleCov
165
179
  line_coverage = line.coverage ? line.coverage : ''
166
180
  line_src = CGI.escapeHTML(line.src.chomp)
167
181
 
168
- @html_file.write(%{<tr})
182
+ html << %(<tr)
169
183
 
170
184
  if line.covered?
171
- @html_file.write(%{ class="covered-by-large-tests"})
185
+ html << %( class="covered-by-large-tests")
172
186
  elsif line.missed?
173
- @html_file.write(%{ class="danger"})
187
+ html << %( class="danger")
174
188
  elsif line.skipped?
175
- @html_file.write(%{ class="warning"})
176
- else
189
+ html << %( class="warning")
177
190
  end
178
191
 
179
- @html_file.write(%{><td><div align="right"><a name="#{line.line_number}"></a><a href="##{line.line_number}">#{line.line_number}</a></div></td><td><div align="left">#{line_coverage}</div></td><td class="codeLine"><span class="default">#{line_src}</span></td></tr>})
192
+ html << %(><td><div align="right"><a name="#{line.line_number}"></a><a href="##{line.line_number}">#{line.line_number}</a></div></td><td><div align="left">#{line_coverage}</div></td><td class="codeLine"><span class="default">#{line_src}</span></td></tr>)
180
193
  end
181
194
 
182
- @html_file.write(%{
183
- </tbody>
184
- </table>
185
- <footer>
186
- <hr/>
187
- <h4>Legend</h4>
188
- <p>
189
- <span class="success"><strong>Executed</strong></span>
190
- <span class="danger"><strong>Not Executed</strong></span>
191
- <span class="warning"><strong>Skipped Code</strong></span>
192
- </p>
193
- <p>
194
- <small>Generated by #{@version_html} using #{@ruby_version_html} and #{@simplecov_version_html} at #{result.created_at.strftime('%F %T %z')}.</small>
195
- </p>
196
- </footer>
197
- </div>
195
+ html << <<-EOHTML
196
+ </tbody>
197
+ </table>
198
+ <footer>
199
+ <hr/>
200
+ <h4>Legend</h4>
201
+ <p>
202
+ <span class="success"><strong>Executed</strong></span>
203
+ <span class="danger"><strong>Not Executed</strong></span>
204
+ <span class="warning"><strong>Skipped Code</strong></span>
205
+ </p>
206
+ <p>
207
+ <small>Generated by #{@simplecov_phpunit_version_html} using #{@ruby_version_html} and #{@simplecov_version_html} at #{result.created_at.strftime('%F %T %z')}.</small>
208
+ </p>
209
+ </footer>
210
+ </div>
198
211
 
199
- <script src="_assets/js/jquery.min.js" type="text/javascript"></script>
200
- <script src="_assets/js/bootstrap.min.js" type="text/javascript"></script>
201
-
202
- </body>
203
- </html>
204
- })
212
+ #{@jquery_js_html}
213
+ #{@bootstrap_js_html}
214
+
215
+ </body>
216
+ </html>
217
+ EOHTML
205
218
 
206
- @html_file.close
219
+ html_file = File.open("#{@coverage_dir_path}/#{html_file_path}", 'wb')
220
+ html_file.write(html.gsub(/^\t{6}/, ''))
221
+ html_file.close
207
222
  end
208
223
 
209
- @index_html_file.write(%{
210
- </table>
211
- <footer>
212
- <hr/>
213
- <h4>Legend</h4>
214
- <p>
215
- <span class="danger"><strong>Low</strong>: 0% to 49%</span>
216
- <span class="warning"><strong>Medium</strong>: 50% to 89%</span>
217
- <span class="success"><strong>High</strong>: 90% to 100%</span>
218
- </p>
219
- <p>
220
- <small>Generated by #{@version_html} using #{@ruby_version_html} and #{@simplecov_version_html} at #{result.created_at.strftime('%F %T %z')}.</small>
221
- </p>
222
- </footer>
223
- </div>
224
-
225
- <script src="_assets/js/jquery.min.js" type="text/javascript"></script>
226
- <script src="_assets/js/bootstrap.min.js" type="text/javascript"></script>
227
-
228
- </html>
229
- })
230
-
231
- @index_html_file.close
224
+ index_html << <<-EOHTML
225
+ </table>
226
+ <footer>
227
+ <hr/>
228
+ <h4>Legend</h4>
229
+ <p>
230
+ <span class="danger"><strong>Low</strong>: 0% to 49%</span>
231
+ <span class="warning"><strong>Medium</strong>: 50% to 89%</span>
232
+ <span class="success"><strong>High</strong>: 90% to 100%</span>
233
+ </p>
234
+ <p>
235
+ <small>Generated by #{@simplecov_phpunit_version_html} using #{@ruby_version_html} and #{@simplecov_version_html} at #{result.created_at.strftime('%F %T %z')}.</small>
236
+ </p>
237
+ </footer>
238
+ </div>
239
+
240
+ #{@jquery_js_html}
241
+ #{@bootstrap_js_html}
242
+
243
+ </html>
244
+ EOHTML
245
+
246
+ index_html_file = File.open(File.expand_path('index.html', @coverage_dir_path), 'wb')
247
+ index_html_file.write(index_html.gsub(/^\t{5}/, ''))
248
+ index_html_file.close
232
249
 
233
250
  puts 'done'
234
251
  puts
@@ -4,8 +4,8 @@ module SimpleCov
4
4
 
5
5
  module PHPUnitFormatter
6
6
 
7
- VERSION = '0.3.0'
8
- DATE = '2016-09-19'
7
+ VERSION = '0.4.0'
8
+ DATE = '2016-09-22'
9
9
  HOMEPAGE = 'https://github.com/TheFox/simplecov-phpunit'
10
10
 
11
11
  end