Fix PHP-CS-Fixer beautifier specs for missing php/php-cs-fixer
This commit is contained in:
parent
8ff76bc41d
commit
7c9281e4b4
|
@ -19,7 +19,7 @@ notifications:
|
||||||
script: sh build-package.sh
|
script: sh build-package.sh
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- APM_TEST_PACKAGES="linter atom-typescript language-marko language-tss language-html-swig"
|
- APM_TEST_PACKAGES="language-marko language-tss language-html-swig"
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
- pip
|
- pip
|
||||||
|
|
|
@ -74,6 +74,7 @@ install:
|
||||||
# pip will build them from source using the MSVC compiler matching the
|
# pip will build them from source using the MSVC compiler matching the
|
||||||
# target Python version and architecture
|
# target Python version and architecture
|
||||||
- "%CMD_IN_ENV% pip install --upgrade autopep8"
|
- "%CMD_IN_ENV% pip install --upgrade autopep8"
|
||||||
|
- where autopep8
|
||||||
|
|
||||||
# Ruby & Gem
|
# Ruby & Gem
|
||||||
- cinst ruby -y
|
- cinst ruby -y
|
||||||
|
@ -111,7 +112,7 @@ build_script:
|
||||||
|
|
||||||
- cd %APPVEYOR_BUILD_FOLDER%
|
- cd %APPVEYOR_BUILD_FOLDER%
|
||||||
# Install languages to Atom
|
# Install languages to Atom
|
||||||
- apm install linter atom-typescript language-marko language-tss language-html-swig
|
- apm install language-marko language-tss language-html-swig
|
||||||
# Show current PATH
|
# Show current PATH
|
||||||
- echo %PATH%
|
- echo %PATH%
|
||||||
# Run tests on package
|
# Run tests on package
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
PHPCSFixer = require "../src/beautifiers/php-cs-fixer"
|
PHPCSFixer = require "../src/beautifiers/php-cs-fixer"
|
||||||
Beautifier = require "../src/beautifiers/beautifier"
|
Beautifier = require "../src/beautifiers/beautifier"
|
||||||
|
path = require 'path'
|
||||||
|
|
||||||
# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
|
# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
|
||||||
#
|
#
|
||||||
|
@ -27,62 +28,109 @@ describe "PHP-CS-Fixer Beautifier", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
beautifier = new PHPCSFixer()
|
beautifier = new PHPCSFixer()
|
||||||
|
# console.log('new beautifier')
|
||||||
|
|
||||||
it "should error when beautifier's program not found", ->
|
OSSpecificSpecs = ->
|
||||||
expect(beautifier).not.toBe(null)
|
text = "<?php echo \"test\"; ?>"
|
||||||
expect(beautifier instanceof Beautifier).toBe(true)
|
|
||||||
|
|
||||||
waitsForPromise shouldReject: true, ->
|
it "should error when beautifier's program not found", ->
|
||||||
text = ""
|
expect(beautifier).not.toBe(null)
|
||||||
language = "PHP"
|
expect(beautifier instanceof Beautifier).toBe(true)
|
||||||
options = {
|
|
||||||
fixers: ""
|
|
||||||
levels: ""
|
|
||||||
}
|
|
||||||
# Mock PATH
|
|
||||||
beautifier.getShellEnvironment = -> Promise.resolve({
|
|
||||||
PATH: ''
|
|
||||||
})
|
|
||||||
#
|
|
||||||
p = beautifier.beautify(text, language, options)
|
|
||||||
expect(p).not.toBe(null)
|
|
||||||
expect(p instanceof beautifier.Promise).toBe(true)
|
|
||||||
cb = (v) ->
|
|
||||||
# console.log(v)
|
|
||||||
expect(v).not.toBe(null)
|
|
||||||
expect(v instanceof Error).toBe(true, \
|
|
||||||
"Expected #{v} to be instance of Error")
|
|
||||||
expect(v.code).toBe("CommandNotFound", \
|
|
||||||
"Expected to be CommandNotFound")
|
|
||||||
return v
|
|
||||||
p.then(cb, cb)
|
|
||||||
return p
|
|
||||||
|
|
||||||
# it "should error with help description \
|
waitsForPromise shouldReject: true, ->
|
||||||
# when beautifier's program not found", ->
|
language = "PHP"
|
||||||
# expect(beautifier).not.toBe(null)
|
options = {
|
||||||
# expect(beautifier instanceof Beautifier).toBe(true)
|
fixers: ""
|
||||||
#
|
levels: ""
|
||||||
# waitsForPromise shouldReject: true, ->
|
}
|
||||||
# help = {
|
# Mock PATH
|
||||||
# link: "http://test.com"
|
beautifier.getShellEnvironment = -> Promise.resolve({
|
||||||
# program: "test-program"
|
PATH: ''
|
||||||
# pathOption: "Lang - Test Program Path"
|
})
|
||||||
# }
|
#
|
||||||
# p = beautifier.run("program", [], help: help)
|
p = beautifier.beautify(text, language, options)
|
||||||
# expect(p).not.toBe(null)
|
expect(p).not.toBe(null)
|
||||||
# expect(p instanceof beautifier.Promise).toBe(true)
|
expect(p instanceof beautifier.Promise).toBe(true)
|
||||||
# cb = (v) ->
|
cb = (v) ->
|
||||||
# # console.log(v)
|
# console.log(v)
|
||||||
# expect(v).not.toBe(null)
|
expect(v).not.toBe(null)
|
||||||
# expect(v instanceof Error).toBe(true)
|
expect(v instanceof Error).toBe(true, \
|
||||||
# expect(v.code).toBe("CommandNotFound")
|
"Expected '#{v}' to be instance of Error")
|
||||||
# expect(v.description).not.toBe(null)
|
expect(v.code).toBe("CommandNotFound", \
|
||||||
# expect(v.description.indexOf(help.link)).not.toBe(-1)
|
"Expected to be CommandNotFound")
|
||||||
# expect(v.description.indexOf(help.program)).not.toBe(-1)
|
return v
|
||||||
# expect(v.description
|
p.then(cb, cb)
|
||||||
# .indexOf(help.pathOption)).not.toBe(-1, \
|
return p
|
||||||
# "Error should have a description.")
|
|
||||||
# return v
|
failWhichProgram = (failingProgram) ->
|
||||||
# p.then(cb, cb)
|
it "should error when '#{failingProgram}' not found", ->
|
||||||
# return p
|
expect(beautifier).not.toBe(null)
|
||||||
|
expect(beautifier instanceof Beautifier).toBe(true)
|
||||||
|
|
||||||
|
if not beautifier.isWindows and failingProgram is "php"
|
||||||
|
# Only applicable on Windows
|
||||||
|
return
|
||||||
|
|
||||||
|
waitsForPromise shouldReject: true, ->
|
||||||
|
language = "PHP"
|
||||||
|
options = {
|
||||||
|
fixers: ""
|
||||||
|
levels: ""
|
||||||
|
}
|
||||||
|
cb = (v) ->
|
||||||
|
# console.log('cb value', v)
|
||||||
|
expect(v).not.toBe(null)
|
||||||
|
expect(v instanceof Error).toBe(true, \
|
||||||
|
"Expected '#{v}' to be instance of Error")
|
||||||
|
expect(v.code).toBe("CommandNotFound", \
|
||||||
|
"Expected to be CommandNotFound")
|
||||||
|
expect(v.file).toBe(failingProgram)
|
||||||
|
return v
|
||||||
|
# which = beautifier.which.bind(beautifier)
|
||||||
|
beautifier.which = (exe, options) ->
|
||||||
|
return beautifier.Promise.resolve(null) \
|
||||||
|
if not exe?
|
||||||
|
if exe is failingProgram
|
||||||
|
beautifier.Promise.resolve(failingProgram)
|
||||||
|
else
|
||||||
|
# which(exe, options)
|
||||||
|
# console.log('fake exe path', exe)
|
||||||
|
beautifier.Promise.resolve("/#{exe}")
|
||||||
|
|
||||||
|
oldSpawn = beautifier.spawn.bind(beautifier)
|
||||||
|
beautifier.spawn = (exe, args, options) ->
|
||||||
|
# console.log('spawn', exe, args, options)
|
||||||
|
if exe is failingProgram
|
||||||
|
er = new Error('ENOENT')
|
||||||
|
er.code = 'ENOENT'
|
||||||
|
return beautifier.Promise.reject(er)
|
||||||
|
else
|
||||||
|
return beautifier.Promise.resolve({
|
||||||
|
returnCode: 0,
|
||||||
|
stdout: 'stdout',
|
||||||
|
stderr: ''
|
||||||
|
})
|
||||||
|
p = beautifier.beautify(text, language, options)
|
||||||
|
expect(p).not.toBe(null)
|
||||||
|
expect(p instanceof beautifier.Promise).toBe(true)
|
||||||
|
p.then(cb, cb)
|
||||||
|
return p
|
||||||
|
|
||||||
|
failWhichProgram('php')
|
||||||
|
failWhichProgram('php-cs-fixer')
|
||||||
|
|
||||||
|
describe "Mac/Linux", ->
|
||||||
|
|
||||||
|
beforeEach ->
|
||||||
|
# console.log('mac/linx')
|
||||||
|
beautifier.isWindows = false
|
||||||
|
|
||||||
|
do OSSpecificSpecs
|
||||||
|
|
||||||
|
describe "Windows", ->
|
||||||
|
|
||||||
|
beforeEach ->
|
||||||
|
# console.log('windows')
|
||||||
|
beautifier.isWindows = true
|
||||||
|
|
||||||
|
do OSSpecificSpecs
|
||||||
|
|
|
@ -243,41 +243,55 @@ module.exports = class Beautifier
|
||||||
@debug('exePath, env:', exePath, env)
|
@debug('exePath, env:', exePath, env)
|
||||||
exe = exePath ? exeName
|
exe = exePath ? exeName
|
||||||
# Spawn command
|
# Spawn command
|
||||||
stdout = ""
|
|
||||||
stderr = ""
|
|
||||||
options = {
|
options = {
|
||||||
env: env
|
env: env
|
||||||
}
|
}
|
||||||
@debug('spawn', exe, args)
|
cmd = @spawn(exe, args, options)
|
||||||
cmd = spawn(exe, args, options)
|
.then(({returnCode, stdout, stderr}) ->
|
||||||
# add a 'data' event listener for the spawn instance
|
# If return code is not 0 then error occured
|
||||||
cmd.stdout.on('data', (data) -> stdout += data )
|
if not ignoreReturnCode and returnCode isnt 0
|
||||||
cmd.stderr.on('data', (data) -> stderr += data )
|
reject(stderr)
|
||||||
# when the spawn child process exits,
|
else
|
||||||
# check if there were any errors and
|
resolve(stdout)
|
||||||
# close the writeable stream
|
)
|
||||||
cmd.on('exit', (returnCode) =>
|
.catch((err) =>
|
||||||
@debug('spawn done', returnCode, stderr, stdout)
|
@debug('error', err)
|
||||||
# If return code is not 0 then error occured
|
# Check if error is ENOENT
|
||||||
if not ignoreReturnCode and returnCode isnt 0
|
# (command could not be found)
|
||||||
reject(stderr)
|
if err.code is 'ENOENT' or err.errno is 'ENOENT'
|
||||||
else
|
reject(@commandNotFoundError(exeName, help))
|
||||||
resolve(stdout)
|
else
|
||||||
)
|
# continue as normal error
|
||||||
cmd.on('error', (err) =>
|
reject(err)
|
||||||
@debug('error', err)
|
)
|
||||||
# Check if error is ENOENT
|
|
||||||
# (command could not be found)
|
|
||||||
if err.code is 'ENOENT' or err.errno is 'ENOENT'
|
|
||||||
reject(@commandNotFoundError(exeName, help))
|
|
||||||
else
|
|
||||||
# continue as normal error
|
|
||||||
reject(err)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
###
|
||||||
|
Spawn
|
||||||
|
###
|
||||||
|
spawn: (exe, args, options) ->
|
||||||
|
return new Promise((resolve, reject) =>
|
||||||
|
@debug('spawn', exe, args)
|
||||||
|
cmd = spawn(exe, args, options)
|
||||||
|
# add a 'data' event listener for the spawn instance
|
||||||
|
stdout = ""
|
||||||
|
stderr = ""
|
||||||
|
cmd.stdout.on('data', (data) -> stdout += data )
|
||||||
|
cmd.stderr.on('data', (data) -> stderr += data )
|
||||||
|
# when the spawn child process exits,
|
||||||
|
# check if there were any errors and
|
||||||
|
# close the writeable stream
|
||||||
|
cmd.on('exit', (returnCode) =>
|
||||||
|
@debug('spawn done', returnCode, stderr, stdout)
|
||||||
|
resolve({returnCode, stdout, stderr})
|
||||||
|
)
|
||||||
|
cmd.on('error', (err) =>
|
||||||
|
@debug('error', err)
|
||||||
|
reject(err)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
###
|
###
|
||||||
Logger instance
|
Logger instance
|
||||||
|
@ -288,10 +302,10 @@ module.exports = class Beautifier
|
||||||
###
|
###
|
||||||
setupLogger: ->
|
setupLogger: ->
|
||||||
@logger = require('../logger')(__filename)
|
@logger = require('../logger')(__filename)
|
||||||
# console.log(@logger)
|
# @verbose(@logger)
|
||||||
# Merge logger methods into beautifier class
|
# Merge logger methods into beautifier class
|
||||||
for key, method of @logger
|
for key, method of @logger
|
||||||
# console.log(key, method)
|
# @verbose(key, method)
|
||||||
@[key] = method
|
@[key] = method
|
||||||
@verbose("Beautifier logger has been initialized.")
|
@verbose("Beautifier logger has been initialized.")
|
||||||
|
|
||||||
|
|
|
@ -19,15 +19,15 @@ module.exports = class PHPCSFixer extends Beautifier
|
||||||
if isWin
|
if isWin
|
||||||
# Find php-cs-fixer.phar script
|
# Find php-cs-fixer.phar script
|
||||||
@Promise.all([
|
@Promise.all([
|
||||||
@which(options.cs_fixer_path)
|
@which(options.cs_fixer_path) if options.cs_fixer_path
|
||||||
@which('php-cs-fixer')
|
@which('php-cs-fixer')
|
||||||
@which('php-cs-fixer.phar')
|
]).then((paths) =>
|
||||||
]).then((paths...)=>
|
|
||||||
@debug('php-cs-fixer paths', paths)
|
@debug('php-cs-fixer paths', paths)
|
||||||
path = require('path')
|
_ = require('lodash')
|
||||||
# Get first valid path
|
# Get first valid, absolute path
|
||||||
phpCSFixerPath = _.find(paths, (p) -> path.isAbsolute(p) )
|
phpCSFixerPath = _.find(paths, (p) -> p and p.charAt(0) is '/' )
|
||||||
@debug('phpCSFixerPath', phpCSFixerPath)
|
@verbose('phpCSFixerPath', phpCSFixerPath)
|
||||||
|
@debug('phpCSFixerPath', phpCSFixerPath, paths)
|
||||||
# Check if PHP-CS-Fixer path was found
|
# Check if PHP-CS-Fixer path was found
|
||||||
if phpCSFixerPath?
|
if phpCSFixerPath?
|
||||||
# Found PHP-CS-Fixer path
|
# Found PHP-CS-Fixer path
|
||||||
|
@ -47,7 +47,8 @@ module.exports = class PHPCSFixer extends Beautifier
|
||||||
@readFile(tempFile)
|
@readFile(tempFile)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
# could not find PHP-CS-Fixer path
|
@verbose('php-cs-fixer not found!')
|
||||||
|
# Could not find PHP-CS-Fixer path
|
||||||
@Promise.reject(@commandNotFoundError(
|
@Promise.reject(@commandNotFoundError(
|
||||||
'php-cs-fixer'
|
'php-cs-fixer'
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue