-
Notifications
You must be signed in to change notification settings - Fork 11
/
unittests.js
255 lines (211 loc) · 8.09 KB
/
unittests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/* eslint-disable */
define( function( require, exports, module ) {
'use strict';
// Get dependencies.
var FileUtils = brackets.getModule( 'file/FileUtils' ),
// Get Todo modules.
Defaults = require( 'modules/Defaults' ),
Events = require( 'modules/Events' ),
CommandRunner = require( 'modules/CommandRunner' ),
Paths = require( 'modules/Paths' ),
Strings = require( 'modules/Strings' ),
// Setup paths and other variables.
extensionPath = FileUtils.getNativeModuleDirectoryPath( module ),
testPath = extensionPath + '/unittest-files/';
// Start testing!
describe( 'PHP Code Quality Tools', function() {
// Test module holding default values.
describe( 'Defaults Module', function() {
// Defaults should be in the form of a object.
it( 'should be an object', function() {
expect( Defaults ).toBeDefined();
expect( Defaults ).toEqual( jasmine.any( Object ) );
} );
// Array of enabled tools.
it( 'should expose enabledTools value', function() {
expect( Defaults.enabledTools ).toBeDefined();
expect( Defaults.enabledTools ).toEqual( jasmine.any( Array ) );
} );
// Array of CodeSniffer standards.
it( 'should expose phpcsStandards variable', function() {
expect( Defaults.phpcsStandards ).toBeDefined();
expect( Defaults.phpcsStandards ).toEqual( jasmine.any( Array ) );
} );
// Array of Mess Detector rulesets.
it( 'should expose phpmdRulesets variable', function() {
expect( Defaults.phpmdRulesets ).toBeDefined();
expect( Defaults.phpmdRulesets ).toEqual( jasmine.any( Array ) );
} );
} );
// Test module running commands.
describe( 'CommandRunner Module', function() {
// Run command should be available.
it( 'should expose run method', function() {
expect( CommandRunner.run ).toBeDefined();
expect( CommandRunner.run ).toEqual( jasmine.any( Function ) );
} );
// Node connection should be available.
it( 'should expose Node connection', function() {
expect( CommandRunner._nodeConnection).toBeDefined();
expect( CommandRunner._nodeConnection ).toEqual( jasmine.any( Object ) );
} );
// Node connection should be available.
it( 'should expose initialized getter', function() {
expect( CommandRunner.initialized ).toBeDefined();
expect( CommandRunner.initialized ).toEqual( jasmine.any( Function ) );
} );
// Node domain should be setup.
it( 'should have a Node domain setup', function() {
expect( CommandRunner._nodeConnection).toBeDefined();
expect( CommandRunner._nodeConnection ).toEqual( jasmine.any( Object ) );
expect( CommandRunner._nodeConnection.domains.phplinttools ).not.toBeNull();
} );
// Run PHP executable.
it( 'should be able to run php executable', function() {
var response = null;
runs( function() {
CommandRunner.run( 'php -v', {}, function( data ) {
response = data;
} );
} );
waitsFor( function() {
return ( response !== null );
}, 'Command output should be returned.', 100 );
// Run expectations on returned comments.
runs( function() {
expect( response ).toEqual( jasmine.any( String ) );
expect( response ).toMatch( 'PHP' );
} );
} );
// Run CodeSniffer.
it( 'should be able to run CodeSniffer through PHP', function() {
var response = null;
runs( function() {
var options = {
cwd: Paths.get( 'base', true ) + 'phpcs'
};
CommandRunner.run( 'php ' + Paths.get( 'phpcs' ) + ' --version', options, function( data ) {
response = data;
} );
} );
waitsFor( function() {
return ( response !== null );
}, 'Command output should be returned.', 100 );
// Run expectations on returned comments.
runs( function() {
expect( response ).toEqual( jasmine.any( String ) );
expect( response ).toMatch( 'PHP_CodeSniffer' );
} );
} );
// Run Copy/Paste Detector.
it( 'should be able to run Copy/Paste Detector through PHP', function() {
var response = null;
runs( function() {
CommandRunner.run( 'php ' + Paths.get( 'phpcpd' ) + ' --version', {}, function( data ) {
response = data;
} );
} );
waitsFor( function() {
return ( response !== null );
}, 'Command output should be returned.', 100 );
// Run expectations on returned comments.
runs( function() {
expect( response ).toEqual( jasmine.any( String ) );
expect( response ).toMatch( 'Bergmann' );
} );
} );
// Run Mess Detector.
it( 'should be able to run Mess Detetctor through PHP', function() {
var response = null;
runs( function() {
CommandRunner.run( 'php ' + Paths.get( 'phpmd' ) + ' --version', {}, function( data ) {
response = data;
} );
} );
waitsFor( function() {
return ( response !== null );
}, 'Command output should be returned.', 100 );
// Run expectations on returned comments.
runs( function() {
expect( response ).toEqual( jasmine.any( String ) );
expect( response ).toMatch( 'PHPMD' );
} );
} );
} );
// Test module holding default values.
describe( 'Events Module', function() {
// Events should be in the form of a object.
it( 'should be an object', function() {
expect( Events ).toBeDefined();
expect( Events ).toEqual( jasmine.any( Object ) );
} );
// Events should have a publish method.
it( 'should expose publish method', function() {
expect( Events.publish ).toBeDefined();
expect( Events.publish ).toEqual( jasmine.any( Function ) );
} );
// Events should have a subscribe method.
it( 'should expose subscribe method', function() {
expect( Events.subscribe ).toBeDefined();
expect( Events.subscribe ).toEqual( jasmine.any( Function ) );
} );
// Events should have a subscribe method.
it( 'should expose unsubscribe method', function() {
expect( Events.unsubscribe ).toBeDefined();
expect( Events.unsubscribe ).toEqual( jasmine.any( Function ) );
} );
// Events should have a cache object.
it( 'should expose cache object', function() {
expect( Events.cache ).toBeDefined();
expect( Events.cache ).toEqual( jasmine.any( Object ) );
} );
// Callbacks should be added to the cache array.
it( 'should add events to cache', function() {
Events.subscribe( 'test', function() {} );
expect( Events.cache[ 'test' ] ).toBeDefined();
expect( Events.cache[ 'test' ] ).toEqual( jasmine.any( Array ) );
expect( Events.cache[ 'test' ].length ).toEqual( 1 );
} );
// Callbacks should be removed from cache array.
it( 'should remove events to cache', function() {
var handle = Events.subscribe( 'test', function() {} );
Events.unsubscribe( handle );
expect( Events.cache[ 'test' ] ).toBeDefined();
expect( Events.cache[ 'test' ] ).toEqual( jasmine.any( Array ) );
expect( Events.cache[ 'test' ].length ).toEqual( 0 );
} );
// Callbacks should be triggered when Events subscribed to are triggered.
it( 'should run triggered events', function() {
var response = null;
Events.subscribe( 'test', function() {
response = 'test';
} );
runs( function() {
Events.publish( 'test' );
} );
waitsFor( function() {
return ( response !== null );
}, 'Event should be triggered.', 100 );
// Run expectations on returned value.
runs( function() {
expect( response ).toEqual( jasmine.any( String ) );
expect( response ).toMatch( 'test' );
} );
} );
} );
// Test module holding string values.
describe( 'Strings Module', function() {
// Strings should be in the form of a object.
it( 'should be an object', function() {
expect( Strings ).toBeDefined();
expect( Strings ).toEqual( jasmine.any( Object ) );
} );
// Make sure strings are returned.
it( 'should expose EXTENSION_NAME property', function() {
expect( Strings.EXTENSION_NAME ).toBeDefined();
expect( Strings.EXTENSION_NAME ).toEqual( jasmine.any( String ) );
expect( Strings.EXTENSION_NAME ).toMatch( 'PHP Code Quality Tools' );
} );
} );
} );
} );