1
1
PHPCSFixer = require " ../src/beautifiers/php-cs-fixer"
2
2
Beautifier = require " ../src/beautifiers/beautifier"
3
+ Executable = require " ../src/beautifiers/executable"
3
4
path = require ' path'
4
5
5
6
# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
@@ -30,10 +31,15 @@ describe "PHP-CS-Fixer Beautifier", ->
30
31
describe " Beautifier::beautify" , ->
31
32
32
33
beautifier = null
34
+ execSpawn = null
33
35
34
36
beforeEach ->
35
37
beautifier = new PHPCSFixer ()
36
38
# console.log('new beautifier')
39
+ execSpawn = Executable .prototype .spawn
40
+
41
+ afterEach ->
42
+ Executable .prototype .spawn = execSpawn
37
43
38
44
OSSpecificSpecs = ->
39
45
text = " <?php echo \" test\" ; ?>"
@@ -49,13 +55,14 @@ describe "PHP-CS-Fixer Beautifier", ->
49
55
levels : " "
50
56
}
51
57
# Mock spawn
52
- beautifier .spawn = (exe , args , options ) ->
58
+ # beautifier.spawn
59
+ Executable .prototype .spawn = (exe , args , options ) ->
53
60
# console.log('spawn', exe, args, options)
54
61
er = new Error (' ENOENT' )
55
62
er .code = ' ENOENT'
56
63
return beautifier .Promise .reject (er)
57
64
# Beautify
58
- p = beautifier .beautify (text, language, options)
65
+ p = beautifier .loadExecutables (). then (() -> beautifier . beautify (text, language, options) )
59
66
expect (p).not .toBe (null )
60
67
expect (p instanceof beautifier .Promise ).toBe (true )
61
68
cb = (v ) ->
@@ -74,7 +81,7 @@ describe "PHP-CS-Fixer Beautifier", ->
74
81
expect (beautifier).not .toBe (null )
75
82
expect (beautifier instanceof Beautifier).toBe (true )
76
83
77
- if not beautifier .isWindows and failingProgram is " php"
84
+ if not Executable .isWindows and failingProgram is " php"
78
85
# Only applicable on Windows
79
86
return
80
87
@@ -104,8 +111,9 @@ describe "PHP-CS-Fixer Beautifier", ->
104
111
# console.log('fake exe path', exe)
105
112
beautifier .Promise .resolve (" /#{ exe} " )
106
113
107
- oldSpawn = beautifier .spawn .bind (beautifier)
108
- beautifier .spawn = (exe , args , options ) ->
114
+ # oldSpawn = beautifier.spawn.bind(beautifier)
115
+ # beautifier.spawn
116
+ Executable .prototype .spawn = (exe , args , options ) ->
109
117
# console.log('spawn', exe, args, options)
110
118
if exe is failingProgram
111
119
er = new Error (' ENOENT' )
@@ -117,28 +125,28 @@ describe "PHP-CS-Fixer Beautifier", ->
117
125
stdout : ' stdout' ,
118
126
stderr : ' '
119
127
})
120
- p = beautifier .beautify (text, language, options)
128
+ p = beautifier .loadExecutables (). then (() -> beautifier . beautify (text, language, options) )
121
129
expect (p).not .toBe (null )
122
130
expect (p instanceof beautifier .Promise ).toBe (true )
123
131
p .then (cb, cb)
124
132
return p
125
133
126
- # failWhichProgram('php ')
127
- failWhichProgram (' php-cs-fixer' )
134
+ failWhichProgram (' PHP ' )
135
+ # failWhichProgram('php-cs-fixer')
128
136
129
137
unless isWindows
130
138
describe " Mac/Linux" , ->
131
139
132
140
beforeEach ->
133
141
# console.log('mac/linx')
134
- beautifier .isWindows = false
142
+ Executable .isWindows = () -> false
135
143
136
144
do OSSpecificSpecs
137
145
138
146
describe " Windows" , ->
139
147
140
148
beforeEach ->
141
149
# console.log('windows')
142
- beautifier .isWindows = true
150
+ Executable .isWindows = () -> true
143
151
144
152
do OSSpecificSpecs
0 commit comments