Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed Oct 27, 2017
0 parents commit a1de9e3
Show file tree
Hide file tree
Showing 14 changed files with 3,849 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"env": {
"browser": false,
"commonjs": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module"
},
"rules": {
"no-const-assign": "warn",
"no-this-before-super": "warn",
"no-undef": "warn",
"no-unreachable": "warn",
"no-unused-vars": "warn",
"constructor-super": "warn",
"valid-typeof": "warn"
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.vscode-test/
.vsix
7 changes: 7 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.vscode/**
.vscode-test/**
test/**
.gitignore
jsconfig.json
vsc-extension-quickstart.md
.eslintrc.json
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Change Log
All notable changes to the "better-phpunit" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]
- Initial release
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Better PHPUnit

![Demo GIF](demo.gif)

## Features:
- Color output!
- Run individual methods by placing your cursor anywhere in the method
- Test failures are displayed in the "Problems" panel for quick access

> Note: this plugin registers "tasks" to run phpunit, not a command like other extensions. This makes it possible to leverage the problem output and color terminal.
Keybindings:
> Note: you will have to add these bindings to your own `keybindings.json` file, otherwise, the bindings will not work right.
```
{
"key": "cmd+k cmd+o",
"command": "workbench.action.tasks.runTask",
"args": "phpunit: method"
},
{
"key": "cmd+k cmd+i",
"command": "workbench.action.tasks.runTask",
"args": "phpunit: file"
}
```
Binary file added demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const vscode = require('vscode');

function activate(context) {

let disposable = vscode.commands.registerCommand('extension.sayHello', function () {
vscode.window.showInformationMessage('Hello World!');
});

let provider = vscode.workspace.registerTaskProvider('phpunit', {
provideTasks: () => {
const rootDirectory = vscode.workspace.rootPath;
const fileName = vscode.window.activeTextEditor.document.fileName;
const methodName = getMethodName(vscode.window.activeTextEditor.selection.active.line);

return [
new vscode.Task(
{type: "phpunit", task: "file"},
"file",
'phpunit',
new vscode.ShellExecution(`${rootDirectory}/vendor/bin/phpunit ${fileName}`),
'$phpunit'
),
new vscode.Task(
{ type: "phpunit", task: "method" },
"method",
'phpunit',
new vscode.ShellExecution(`${rootDirectory}/vendor/bin/phpunit ${fileName} --filter ${methodName}`),
'$phpunit'
),
];
},
resolveTask(task) {
return undefined;
}
});

context.subscriptions.push([disposable, provider]);
}
exports.activate = activate;

function deactivate() {
}
exports.deactivate = deactivate;

function getMethodName(lineNumber) {
let methodName = '';
let line = lineNumber;

while (line > 0) {
const lineText = vscode.window.activeTextEditor.document.lineAt(line).text;
const methodMatch = lineText.match(/^.*function\s*(.*)\(/);
const classMatch = lineText.match(/^.*class\s*(\w*)\s*.*$/);
if (methodMatch || classMatch) {
const match = methodMatch || classMatch;
methodName = match[1];
break;
}
line = line - 1;
}

return methodName;
}
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": [
"es6"
]
},
"exclude": [
"node_modules"
]
}
Loading

0 comments on commit a1de9e3

Please sign in to comment.