Skip to content

Commit

Permalink
fix: lint php files with spaces failed
Browse files Browse the repository at this point in the history
  • Loading branch information
kokororin committed Apr 20, 2024
1 parent 9acbb5a commit 6a5d3c5
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 89 deletions.
2 changes: 1 addition & 1 deletion src/PHPFmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class PHPFmt {

// test whether the php file has syntax error
try {
await exec(`${this.config.php_bin} -l ${tmpFileName}`, execOptions);
await exec(`${this.config.php_bin} -l "${tmpFileName}"`, execOptions);
} catch (err) {
this.widget.logError('PHP lint failed', err);
Window.setStatusBarMessage(
Expand Down
29 changes: 16 additions & 13 deletions test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert';
import path from 'path';
import fg from 'fast-glob';
import {
workspace as Workspace,
window as Window,
Expand All @@ -24,20 +24,23 @@ suite('PHPFmt Test', () => {
assert.fail();
}

const filePath = path.join(
Workspace.workspaceFolders[0].uri.fsPath,
'ugly.php'
);
const workspaceFolder = Workspace.workspaceFolders[0].uri.fsPath;
const phpFiles = await fg(['**/*.php'], {
cwd: workspaceFolder,
absolute: true
});

const doc = await Workspace.openTextDocument(filePath);
await Window.showTextDocument(doc);
for (const filePath of phpFiles) {
const doc = await Workspace.openTextDocument(filePath);
await Window.showTextDocument(doc);

const text = doc.getText();
try {
await Commands.executeCommand('editor.action.formatDocument');
assert.notEqual(doc.getText(), text);
} catch (err) {
assert.fail('Failed to format doc');
const text = doc.getText();
try {
await Commands.executeCommand('editor.action.formatDocument');
assert.notEqual(doc.getText(), text);
} catch (err) {
assert.fail(`Failed to format doc: ${filePath}`);
}
}
});

Expand Down
14 changes: 14 additions & 0 deletions testProject/ugly 1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
// This is a file with a space in the name
class Ugly{
private $ugly;

public function __construct($ugly){
$this->ugly=$ugly;
}

public function getUgly()
{
return $this->ugly;
}
}
Loading

0 comments on commit 6a5d3c5

Please sign in to comment.