Git Product home page Git Product logo

sublime-phpunit's Introduction

Sublime PHPUnit

This plugin adds PHPUnit support to Sublime Text 2 & 3.

Installation

Use Package Control (Preferences -> Package Control -> Install Package -> PHPUnit) to install this plugin.

PHPUnit Support For Sublime Text

This plugin adds support for running PHPUnit tests from inside Sublime Text.

Right-click in the editor to:

  • Run all unit tests
  • Run the unit tests for the current file
  • Run the unit tests in the current file
  • Run PHPUnit, using the current XML config file
  • Goto the file containing the tests or the file being tested

Right-click in the side-bar to:

  • Run the unit tests in the current file
  • Run all the unit tests
  • Run PHPUnit, using the selected XML config file

You can also open up the Command Palette (CTRL + SHIFT + P on Linux), and type 'PHPUnit' to see what you can do with PHPUnit in the currently open file.

To make this work, you need to create a phpunit.xml.dist or phpunit.xml file for your code (projects using Phix get this for free). The Sublime-PHPUnit plugin searches the folders upwards from whatever you are trying to test, using the first phpunit.xml or phpunit.xml.dist that it finds. Make sure that your phpunit.xml file is either at the top of your tests folder (or even further up), and this plugin will work for you.

PHPUnit support is based on the Ruby Tests plugin

Snippets

We add the following snippets to speed up writing PHP test code.

To use any of the snippets, simply type the name of the snippet, then press the key. Sublime Text 2 will insert the snippet, and you can then use the key to move through any placeholders that you need to replace.

  • phpunit-test: create a new test method inside your TestCase class
  • phpunit-testcase: create a new TestCase class to put your tests inside

Contributions Welcome

Requests for features, and pull requests with patches, are most welcome :)

Please make sure that your pull requests are against the 'develop' branch and not 'master'.

sublime-phpunit's People

Contributors

adri avatar benmatselby avatar captainkuro avatar emestee avatar seldaek avatar stuartherbert avatar yrwein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sublime-phpunit's Issues

Use the `php` binary defined in $PATH

It seems to be defaulting to using /usr/bin/php, which is not the desired behaviour for my setup. I would like it to use /usr/bin/env php or simply php. Is it possible to change the path to PHP in the environment in Sublime or this package?

console without colors

Hi, I try this plugin and I lanch test but no colors shows in console and show caracters.

--- PROCESS COMPLETE ---.

Time: 0 seconds, Memory: 4.00Mb

�[30;42m�[2KOK (1 test, 1 assertion)
�[0m�[2K

Thanks!

Configfile not detected...

I was working good, but after several updates, when I run tests over my phpunit.xml file, this isn't detected and isn't taken as argument to phpunit, to get works on sublime text 2 I modified some lines on this way:

        #if os.path.isfile(os.path.join(folder, configfile)): //211 line
        args.append("-c")
        args.append('"' + folder + configfile + '"')

I would like to know a suggestion, because on sublime text 3 I can't do it; and I would appreciate know the cause to don't have to modify the files, if someone have some idea thanks a lot.

PD. Sorry my bad English.

Accept phpunit.xml with other file names

I would like to have the option to select a phpunit xml file with other names, as for example phpunit-test-this.xml. Actually, only phpunit.xml is accepted in the sidebar right-button command.

TestSuite support

It would be nice to run a test suite from within the plugin.

Considering a TestSuite (AllTests.php) like this:

<?php

class AllTests {
  static public function suite() {
    $suite = new PHPUnit_Framework_TestSuite('Foo');

    $suite->addTestCase('BarTest');

    return $suite;
  }
}

I already tried to modify the plugin (allowing to run the PHPUnit: Run these tests command to show up in a file called *Tests.php), but I failed miserably due to my lacking python knowledge.

PHPUnit doesn't show any results

Hello, I'm using ST2 on OSX 10.9.2.

After I wrote my tests and the phpunit.xml, and "Run Tests..." from right-click menu, the console log appears in the bottom and shows the phpunit command but not the results.

When I copy the command and paste it on the Terminal, it works fine. What possibly did I do wrong? Because when I click "Open Class Being Tested" and "Open phpunit.xml" they just works well.

Here's the screenshot of the console:

screen shot 2014-03-18 at 18 10 38

Sorry for bad English

Color support

Does this support colored output? Cause at the moment I don't? Not sure if there is something I need to set?

image

edit:

Nevermind! There seem to be more problems with this package (like for instance it stops working after you installed it and restart sublime). I will have to find me something else (outside of ST).

ST3 Error: Run All Unit Tests... : __init__() missing 1 required positional argument: 'edit'

When I run "Run All Unit Tests..." from the context menu I get the following error (both from phpunit.xml and from a .php file somewhere in the tree):

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "/Users/XXXXX/Library/Application Support/Sublime Text 3/Packages/sublime-phpunit-feature-st3-support/phpunit.py", line 956, in run
    cmd = PhpunitCommand(self.view.window())
TypeError: __init__() missing 1 required positional argument: 'edit'

Is there any known workaround for this? Any help is appreciated.

Individual tests work fine. Also, acc. to the console the plugin does find phpunit.xml, so that does not seem to be the problem.

Thanks for a great plugin.

Leading path separator check failed under Windows

I'm using ST3 on Windows 7 and had some trouble with PHPUnit not picking up the files properly.
I've ultimately traced it to the PhpunitCommand class with, for example,:

    # remove the folder from the configfile
    if configfile.startswith(folder):
        configfile = configfile[len(folder):]
        if configfile[0] == "/":
            configfile = configfile[1:]`

Which I replaced with

    # remove the folder from the configfile
    if configfile.startswith(folder):
        configfile = configfile[len(folder):]
        if configfile[0] == os.path.sep:
            configfile = configfile[1:]

which brought everything back into line. Am I the only one that's run into this?
My phpunit.xml is buried under folders in the project, so it's not in the 'top folder', which I've seen people recommend...

Running a single test or a group of tests from context-menu

Is it possible to just run one test or a group of tests at a time from the context menu? Running my tests on some classes takes a while and I would appreciate the shorter feedback loop. This could be implemented either via the --filter or --group flag.

Cannot find file containing unit tests

Project Framework: Laravel

I have a phpunit.xml in my root with the following code:

<?xml version="1.0"?>
<phpunit colors="true" bootstrap="artisan" backupGlobals="false">
<testsuites>
<testsuite name="Tests">
<directory suffix=".test.php">application/tests</directory>
</testsuite>
</testsuites>
</phpunit>

When I right click on my file example.test.php the PHPUnit selection states "Cannot find file containing unit tests".

Default install hangs

I think this is as simple as me not having the phpunit.xml file at the time of installation, but after installing the package sublime hangs on my system when opening a command palette or right clicking. Removing the package manually from my system fixed the problem.

Ubuntu 12.10, 64bit
Sublime Text 2 v2.0.1 build 2217

Allow creation of test case

As a developer, I'd like to be able to create a test case file from the current class I'm working on, so that I don't have to create the file manually.

Example:

If im working on application/models/fancy/FancyModel.php

I'd like to right click and select "Create test Case"

that will generate the file application/test/models/fancy/FancyModelTest.php

and open it in the editor

Error loading color scheme

I just tried to run some unit tests and I'm getting the following error.

"
Error loading color scheme
Packages/phpunit/color-schemes/phix-dark.hidden-tmTheme: Unable
to open Packages/phpunit/color-schemes/phix-dark.hidden-tmTheme
"

Full Test Suite Always Runs

I'm running into a problem where my full test suite always runs, regardless of whether I ask it to 'Test This Class…' or 'Run All Unit Tests…'.

My phpunit.xml looks like this:

<?xml version="1.0"?>
<phpunit bootstrap="bootstrap.php" backupGlobals="false" backupStaticAttributes="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" syntaxCheck="true" testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader" verbose="true" strict="true">
    <php>
        <ini name="date.timezone" value="Europe/London"/>
    </php>
    <testsuites>
        <testsuite name="Commerce">
            <directory suffix=".php">.</directory>
        </testsuite>
    </testsuites>
    <filter>
        <blacklist>
            <directory>.</directory>
            <directory>../src/lib</directory>
        </blacklist>
    </filter>
</phpunit>

env: php: No such file or directory

my mac $PATH is '/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin' ; but the plugin's path is [path: /usr/bin:/bin:/usr/sbin:/sbin], and it keeps telling me 'env: php: No such file or directory' due to that i installed my php under the '/usr/loca/bin/' directory. i've tried adding my $PATH to the "override_env" variable in the user's setting.

Here 's my user setting :
{ "path_to_phpunit": "/usr/local/bin/phpunit", "override_env": {"PATH" : "/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin"} }. But it still not working.

Remote tests

I have a setup where I use a virtual machine (with vagrant) to run my development environment and so I need a way to trigger phpunit tests on a remote host collect output and show it there. Is there an easy way to do this? Can I just pass ssh credentials somewhere and have it run the commands there?

Probably replace AsyncProcess func somehow to use a ssh connection? I'm not really that proficient with python at the moment but I could try to hack it out. Would be really great if this can be done natively - I have a feeling there might be a lot of people using vagrant for their projects

Thanks

Issue during on_save event.

Console shows errors after saving a phpunit test file:

AttributeError: 'RunPhpunitOnSave' object has no attribute 'top_folder'

Error on ST3

Hey guys, i'm installed the phpunit plugin on st3 and saw the following error in the console, maybe it's helpful for you:

reloading plugin PHPUnit.phpunit
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 73, in reload_plugin
    m = importlib.import_module(modulename)
  File "X/importlib/__init__.py", line 88, in import_module
  File "<frozen importlib._bootstrap>", line 1577, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1558, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1525, in _find_and_load_unlocked
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 671, in load_module
    exec(compile(source, source_path, 'exec'), mod.__dict__)
  File "phpunit in C:\....\Sublime Text 3\Installed Packages\PHPUnit.sublime-package", line 35
    print "[PHPUnit Plugin " + Msgs.operation + "()] " + msg
                           ^
SyntaxError: invalid syntax

$_SERVER['PWD'] etc not set

This might not be an issue per se, however the $_SERVER array is usually populated with some useful values when php (and indeed phpunit) is run from the command line. It seems that your plug-in does not set any such values?

I use $_SERVER['PWD'] in some of my test code to find the current directory. This is different to dirname() as it doesn't resolve symbolic links.

Anyway my main point is that it is useful to populate $_SERVER with useful values. For some examples try display this array from the command line using PHP. PHPUnit also honours this.

Your script would be far more compatible and have a broader reach if it did populate this system array.

Do you think you might consider it? :-) And if not is there another alternative to getting this information?

unable to run tests sublime text 2

when i run tests this this is what shows in the console.

Traceback (most recent call last):
File "./sublime_plugin.py", line 362, in run_
File "./phpunit.py", line 769, in run
File "./phpunit.py", line 276, in run
File "./phpunit.py", line 234, in start_async
File "./phpunit.py", line 101, in init
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 623, in init
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1141, in _execute_child
raise child_exception

support for sublime text 3

several issues related to moving to Python 3.3

  • changed all "print x" to "print(x)"
  • no thread library:
File "C:\Users\Bill\AppData\Roaming\Sublime Text 3\Packages\sublime-phpunit\phpunit.py", line 7, in <module>
    import thread
ImportError: No module named 'thread'

I commented out the import thread line to see if I could make further progress.

That leads to this not-very-helpful error:

reloading plugin sublime-phpunit.phpunit
TypeError: String required

However, the right-click phpunit options show up. I try clicking "Run these tests", and get error:

File "C:\Users\Bill\AppData\Roaming\Sublime Text 3\Packages\sublime-phpunit\phpunit.py", line 118, in clear_output_view
    edit = self.output_view.begin_edit()
TypeError: begin_edit() missing 2 required positional arguments: 'edit_token' and 'cmd'
TypeError: String required

The sublime text 3 porting guide (http://www.sublimetext.com/docs/3/porting_guide.html) says:

Restricted begin_edit() and end_edit()

begin_end() and end_edit() are no longer directory accessible, except in some special circumstances. The only way to get a valid instance of an Edit object is to place your code in a TextCommand subclass. In general, most code can be refactored by placing the code between begin_edit() and end_edit() in a TextCommand, and then calling run_command on that TextCommand.

This approach removes the issue of dangling Edit objects, and ensures the repeat command and macros work as they should.

And now I'm lost as I'm not really python-literate

Bug in searching for topLevelFolders

When you rely on top_folder_hints usign files or folders like .git and .gitignore the search stops at wrong places, like.

Its very common that people leave an empty .gitignore file in folders that they want in the repo. but in which they dont want to track files inside. (empty folders in git repo)

since .gitignore is a hint on searching top folders, the plugin will stop at wront places and wont be able to find phpunit.xml or classes to be tested.-

Instead, allow the user to configure the top level folder, or/and phpunit.xml location. so you can also save some processing on searching for those.

Run rempte phpunit

is it possible to execute remote phpunit, I have a vagrant box which has my project files, I would like to run tests on that box from sublime text.

Thank you

Ability to specify where dist file lives

I'm developing a Symfony 2 app. the phpunit file lives under the app directory which is one level in from the root.

Usually i have to run phpunit from the root as such

phpunit -c app

Would it be possible to save the location of the dist file in the sublime projects file so that you first look there and then start searching for it up the path?

test files need to end in Test to enable context menu

Hi,
I wanted two things that the plugin didn't easily satisfy:

  1. Test files should end in *Test.php, but not by PHPUnit, only by your plugin to enable the context menus. Checking for other artifacts such as PHPUnit_Framework_TestCase or equivalent would be wiser, or even enabling the menu and then erring on try would be better.
  2. It would be better to document the "commands" that your plugin defines, so that people can assign shortkeys to them. I found "phpunit_run_tests" and "phpunit_run_all_tests" and assigned keyboard shortcuts to them.

Auto-run tests on save

Could we have an option to automatically run the tests for the current file whenever it is saved?

Error on Windows 8 with Sublime Text 2

Hello, I installed the sublime-phpunit plugin over package control. I didn't changed the configuration so its just default. PHP and PHPUnit works fine from command promt.
PHP and PHPUnit can be found under my PATH variable.

If I "right click: Run all tests" the execution command is correct.

Running in folder: C:\Users\createproblem\Documents\projects\web\mn-webapp\app
$ phpunit -c phpunit.xml.dist

This is the error I got in Sublime Text 2

Traceback (most recent call last):
  File ".\sublime_plugin.py", line 362, in run_
    return self.run(edit)
  File ".\phpunit.py", line 721, in run
  File ".\phpunit.py", line 232, in run
  File ".\phpunit.py", line 190, in start_async
  File ".\phpunit.py", line 74, in __init__
  File ".\subprocess.py", line 633, in __init__
  File ".\subprocess.py", line 842, in _execute_child
TypeError: environment can only contain strings

Maybe a problem in my setup?

Some tips to get this plugin work would be nice.

so long
createproblem

Class '<SOMECLASS>' could not be found in '<SOMEPATH>'

Hi,

I tried to run phpunit on my laravel 4.2 project with Sublime 3 on Windows 10. (Before I upgraded to Windows 10, everything worked fine)
I got this error :

PHPUnit 3.7.21 by Sebastian Bergmann.
Class 'SubjectTest' could not be found in '\app\tests\models\SubjectTest.php'.
[Finished in 0.2s]

And here is my SubjectTest.php

<?php
class SubjectTest extends TestCase {
...
}

Do you have any idea how to solve this problem?

Thank you.

Test class name causes "Cannot find file containing unit tests"

Thanks for a great plugin.

I'm running unit tests with sublime-phpunit for ST3 which mostly works great. The one issue I'm having is with some integration tests that don't correspond to specific class files. I.e. for unit tests I have MyClass and MyClassTest, but then I have a class MyIntegrationTests, but there is no class called MyIntegration (by design, or at least, I'm not in a position to change the structure freely). I'm unable to run these tests from sublime, because the context menu/command palette "Run Tests..." option now says

Cannot find file containing unit tests

The current file in the editor, when right-clicking, is the file with the test cases (i.e. MyIntegrationTests. Is there a workaround, or a way to override this behavior, and just run the tests in the file?

Same class names but different namespaces not working properly

First of all, congratulations for this awesome and helpful plugin!
There is something I thing it is simple to solve. Let's go:

If I have two classes with same name in different namespaces:

  • Service\MyClass
  • Command\MyClass

with it's respective tests:

  • Service\MyClassTest
  • Command\MyClassTest

when i'm in Service\MyClass and trigger 'phpunit_toggle_class_test_class' it was suppose to open the respective Service\MyClassTest but it it's always openning one of them: Service\MyClassTest, even if i'm in the other class Command\MyClass it will open the Service\MyClassTest.

I think it's always openning the first match in the 'phpunit_toggle_class_test_class' command. My suggestion is to show a list of options to toggle when in these cases.

I hope i was clear. Sorry about my english.

Thanks a lot!

Not working on window 8 with ST3

It doesn't seem to start. In the console I get this output:

  File "phpunit in D:\apps\Sublime\Data\Installed Packages\PHPUnit.sublime-package", line 35
        print "[PHPUnit Plugin " + Msgs.operation + "()] " + msg
                               ^
    SyntaxError: invalid syntax

Running test in Windows 7 errors out

First I want to say thanks for creating this plugin.

I'm not able to get tests to actually run on my 32-bit Windows 7 box at work.

When I run the test, this is what I see, but no results are shown. I can copy that command into a shell in the specified directory and the test runs.

# Running in folder: C:\www\autopaf\tests
$ phpunit -c phpunit.xml C:\www\autopaf\tests\application\controllers\VendorControllerTest.php

Console log output:

Traceback (most recent call last):
  File ".\sublime_plugin.py", line 362, in run_
  File ".\phpunit.py", line 825, in run
  File ".\phpunit.py", line 183, in run
  File ".\phpunit.py", line 150, in start_async
  File ".\phpunit.py", line 39, in __init__
  File ".\subprocess.py", line 633, in __init__
  File ".\subprocess.py", line 842, in _execute_child
WindowsError: [Error 2] The system cannot find the file specified

Unable to Find Namespace Class

Hi all,

I'm following this tutorial to get the PHPUnit running:
https://jtreminio.com/2013/03/unit-testing-tutorial-part-2-assertions-writing-a-useful-test-and-dataprovider/

For a simple start, I've declared just a class and its tester. As it was told in the tutorial (part 1), I have installed PHPUnit via Composer. My tests work just fine when I use the PHPUnit like:

$ ./vendor/bin/phpunit

However, when I try to run tests from Sublime Text 3 command palette or like $ phpunit, I get the following error:

Fatal error: Class 'MyNamespace\MyClass' not found in /Users/k/Sites/Project/MyNamespace/Test/MyClassTest.php on line 14

No errors when I include the class file with require_once.

Global instance of PHPUnit is under /usr/local/bin. Is there a way to force the plugin to use phpunit command from the project root, like /vendor/bin/phpunit?

context menu slowdown in php files

Hello,

this plugin slows down the context menü when i right click into an php file.
The contextmenu hangs for about 2-3 seconds and than it appears.

It onlyhappens by right clicking into the code-view-part of an php file.

Can you please take a look into this ? Thanks!

best regards....

PHPUnit plugin is causing massive lag/freeze!

I am using ST2 on OSX 10.9 (Macbook Air 2012) and I decided to use ST2 as my main editor of choice.

After installing the necessary plugins (wish PHPUnit was one of) I noticed that when I opened ST2 and I pressed CMD+shift+P (super+shift+p) I had to wait 10+ seconds before ST2 was done and could react on my input again.

I almost got crazy over not being able to find the cause of this. I found it after disabling all plugins and activating the plugins one by one until I reached PHPUnit.

I havent adjusted anything with the PHPUnit settings. I also not using PEAR, but composer with globally installed PHPUnit (~/.composer/vendor/bin).

Anyone have the same experience? What could it be and how could this be solved?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.