Skip to content

Commit

Permalink
check for pest
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed Oct 9, 2023
1 parent 81447bd commit 3c2e9fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
"default": null,
"description": "A custom phpunit binary. Ex: 'phpunit', '/usr/local/bin/phpunit'"
},
"better-phpunit.pestBinary": {
"type": [
"string",
"null"
],
"default": null,
"description": "A custom Pest binary. Ex: 'pest', '/usr/local/bin/pest'"
},
"better-phpunit.xmlConfigFilepath": {
"type": [
"string",
Expand Down
23 changes: 19 additions & 4 deletions src/phpunit-command.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const findUp = require('find-up');
const vscode = require('vscode');
const path = require('path');
const fs = require('fs');

module.exports = class PhpUnitCommand {
constructor(options) {
Expand Down Expand Up @@ -67,13 +68,17 @@ module.exports = class PhpUnitCommand {
}

get binary() {
if (vscode.workspace.getConfiguration('better-phpunit').get('phpunitBinary')) {
return vscode.workspace.getConfiguration('better-phpunit').get('phpunitBinary')
const binaryKey = this.isPest ? 'pestBinary' : 'phpunitBinary';

if (vscode.workspace.getConfiguration('better-phpunit').get(binaryKey)) {
return vscode.workspace.getConfiguration('better-phpunit').get(binaryKey)
}

const binary = this.isPest ? 'pest' : 'phpunit';

return this.subDirectory
? this._normalizePath(path.join(this.subDirectory, 'vendor', 'bin', 'phpunit'+this.windowsSuffix))
: this._normalizePath(path.join(vscode.workspace.rootPath, 'vendor', 'bin', 'phpunit'+this.windowsSuffix));
? this._normalizePath(path.join(this.subDirectory, 'vendor', 'bin', binary+this.windowsSuffix))
: this._normalizePath(path.join(vscode.workspace.rootPath, 'vendor', 'bin', binary+this.windowsSuffix));
}

get subDirectory() {
Expand Down Expand Up @@ -102,6 +107,16 @@ module.exports = class PhpUnitCommand {
return method;
}

get isPest() {
const composerJson = findUp.sync('composer.json', { cwd: vscode.window.activeTextEditor.document.fileName });

if (!fs.existsSync(composerJson)) {
return false;
}

return fs.readFileSync(composerJson, 'utf8').includes('pestphp/pest');
}

_normalizePath(path) {
return path
.replace(/\\/g, '/') // Convert backslashes from windows paths to forward slashes, otherwise the shell will ignore them.
Expand Down

0 comments on commit 3c2e9fa

Please sign in to comment.