Giter Club home page Giter Club logo

vscode-yet-another-phpunit's Introduction

Build Status Marketplace Version

Yet Another PHPUnit

This extension is an enhanced fork-n-remake of Better PHPUnit. The major part of the code is taken from that repository.

Installation

Download it from the Marketplace or search for Yet Another PHPUnit in your VSCode editor extension panel.

Demo GIF

Features

  • Color output!
  • SSH support
  • Docker support
  • Run individual methods
  • Run a single file
  • Run tests inside a folder
  • Run all the tests
  • Test failures are displayed in the "Problems" panel for quick access
  • CodeLens to run single tests just in one click

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.

Run a test method:

  • Click Run test above the method name
    or
  • Place your cursor on the method name, open the command menu with cmd+shift+p and select Yet PHPUnit: Run

Run a test file:

  • Click Run class tests above the class name
    or
  • Right click on the file in the "Explorer" tab on the left sidebar and select Run File Tests
    or
  • Place your cursor on the class name, open the command menu with cmd+shift+p and select Yet PHPUnit: Run

Run a folder tests:

  • Right click on the folder in the "Explorer" tab on the left sidebar and select Run Tests Inside Folder

Run all the tests:

  • Open the command menu: Cmd+Shift+p
  • Select: Yet PHPUnit: Run All

Re-run last executed test:

  • Open the command menu: Cmd+Shift+p
  • Select: Yet PHPUnit: Re-Run Test

Global configuration variables

Name Type Default Description
yet-phpunit.commandSuffix string null Content (flags, arguments) to be appended to PHPUnit command. For example, if you want to use --testdox this is the correct place.
yet-phpunit.phpunitBinary string null A custom path of PHPUnit binary file. By default it will be auto-discovered from vendor folder.
yet-phpunit.codelens boolean true Set it to false to disable Code Lens, namely the clickable label "Run test" above methods and classes.

How to use these values

Open your settings (or Workspace settings), switch to JSON and put them like this:

{
    "yet-phpunit.commandSuffix": null,
    "yet-phpunit.phpunitBinary": null,
    "yet-phpunit.codelens": true
}

SSH configuration

If you plan to use SSH, take a look also to new VSCode feature: Remote development.

Variables to set up tests over SSH (for VMs like Laravel Homestead):

Name Type Default Description
yet-phpunit.ssh.enable boolean false Set it to true to enable SSH.
yet-phpunit.ssh.binary string ssh Custom SSH agent binary, for example plink.exe (PuTTY ssh).
yet-phpunit.ssh.host string null SSH hostname.
yet-phpunit.ssh.user string null SSH username.
yet-phpunit.ssh.port number 22 SSH port.
yet-phpunit.ssh.options string null Additional SSH options (arguments, flags etc.).
yet-phpunit.ssh.shellAppend string null Stuff to append after the SSH and PHPUnit command. For example, to enable color on Windows this is the right place.
yet-phpunit.ssh.paths object {} The SSH path map. Keys are local (host) paths and values are remote (guest) paths.

Example of configuration

If you use PuTTy, you have to use plink as binary file (it's part of with PuTTy)

{
    "yet-phpunit.ssh.enable": true,
    "yet-phpunit.ssh.binary": "plink.exe",
    "yet-phpunit.ssh.host": "host",
    "yet-phpunit.ssh.user": "user",
    "yet-phpunit.ssh.port": "22",
    "yet-phpunit.ssh.options": null,
    "yet-phpunit.ssh.shellAppend": null,
    "yet-phpunit.ssh.paths": {
        "/your/local/path": "/your/remote/path"
    }
}

Docker

Variables to set up tests in a Docker container:

Name Type Default Description
yet-phpunit.docker.enable boolean false Set it to true to enable Docker support.
yet-phpunit.docker.command string null Command base for Docker, for example docker exec your-container. This is required if you enable Docker.
yet-phpunit.docker.paths object {} The SSH path map. Keys are local (host) paths and values are remote (guest) paths.

Example of configuration

Example of configuration for an already running Container:

{
    "yet-phpunit.docker.enable": true,
    "yet-phpunit.docker.command": "docker exec <container-name>",
    "yet-phpunit.docker.paths": {
        "/your/local/path": "/your/remote/path"
    },
}

Example of configuration to start up a container with Docker Compose and kill it when finished:

{
    "yet-phpunit.docker.enable": true,
    "yet-phpunit.docker.command": "docker-compose run --rm <container-name>",
    "yet-phpunit.docker.paths": {
        "/your/local/path": "/your/remote/path"
    },
}

Tip: if you want to run Docker over a SSH session just should use both options ssh.enable and docker.enable together.

Roadmap: what's next?

This is what I'd love to implement in the future:

  • Run a single suite tests
  • Panel on left sidebar to see suites and available tests
  • Re-run failures

Credits

vscode-yet-another-phpunit's People

Contributors

danilopolani avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vscode-yet-another-phpunit's Issues

Debugging unit tests?

Here are the relevant parts of my workspace configuration:

    "yet-phpunit.docker.enable": true,
    "yet-phpunit.docker.command": "docker-compose -f /home/rulatir/works/webzuu/zuu/docker/docker-compose-dev.yml --project-directory=/home/rulatir/works/webzuu/zuu exec php /usr/bin/env XDEBUG_CONFIG=\"remote_host=172.17.0.1\",
    "yet-phpunit.phpunitBinary": "/apps/cms/vendor/bin/phpunit",
    "yet-phpunit.xmlConfigFilepath": "/apps/cms/phpunit.xml",
    "yet-phpunit.codelens": true,
    "yet-phpunit.docker.paths": {
        "/home/rulatir/works/webzuu/zuu/apps/cms": "/apps/cms"
    },

As you can see, the docker command uses env to pass XDEBUG_CONFIG to phpunit. It works. I can set a breakpoint in a test method, hit the codelens, and it stops on the breakpoint. But I would like to be able to define a separate "run configuration" for debugging tests, and there doesn't seem to be a way to do this.

I want to be able to:

  • debug my tests with Xdebug extension loaded and the right env vars passed,
  • run my tests normally with an alternate no-xdebug php.ini,
  • without having to edit the configuration every time I want to switch between the above two modes.

CodeLens and functions that are not tests.

Hi

Codelens does not seem to work if your first functions aren't tests. For example, I always have my setup methods and data providers at the top of my tests, then the test functions under that. The test link disappears when that is the case. See the images attached.

Image 1, with setUp function.

Screenshot 2019-05-08 at 09 54 27

Image 2, without setUp function.

Screenshot 2019-05-08 at 09 54 51

Also, this seems to happen the test functions that come after a non test function.

phpunit.xml file is required

The phpunit.xml file is required for the links above classes and tests to work. I just copied the phpunit.xml here and it worked.

Just putting this here in case the shortcuts weren't working for you.

Gutter colors for tests

Hi @danilopolani

This is a great plugin, very quick. I it possible to add gutter colors so that one can easily see which tests are failing within the file. Similar to how vs-code phpunit is supposed to do it. I found your extension after that stopped showing colors completely for me.

Thanks

Putty: unknown option -tt

Great work, I like it.

I am using Windows 10, and using ( Laravel Homestead ) vagrant box as a guest.

Whenever I try to do the test via SSH mode, I get this error by Putty:
unknown option -tt


"yet-phpunit.ssh.enable": true,
"yet-phpunit.ssh.binary": "c:/Users/user11/tools/putty.exe -ssh",
"yet-phpunit.ssh.host": "127.0.0.1",
"yet-phpunit.ssh.user": "vagrant",
"yet-phpunit.ssh.port": "2222",
"yet-phpunit.ssh.options": null,
"yet-phpunit.ssh.paths": {
  "d:/sites/blog": "/home/vagrant/code/blog"
},

Could not open input file: /home/ . . . /vendor/bin/phpunit

Hello everyone! I'm facing an issue that I can not run any kind of test because I get this error:

> Executing task: /home/ . . . /vendor/bin/phpunit /home/ . . . /Tests/Feature/ . . . /ControllerIndexTest.php --filter '^.*::it_fails_to_access_the_endpoint_if_the_user_is_not_authenticated( .*)?$'  <

Could not open input file: /home/ . . . /vendor/bin/phpunit
The terminal process "/usr/bin/zsh '-c', '/home/ . . . /vendor/bin/phpunit /home/ . . . /Tests/Feature/ . . . /ControllerIndexTest.php --filter '^.*::it_fails_to_access_the_endpoint_if_the_user_is_not_authenticated( .*)?$' '" terminated with exit code: 1.

Anyone has any ideia why this is happening?

Use the integrated terminal for the tasks

OS: windows 10.

When running the test task, It doesn't get executed in the integrated terminal ( for my case "git bash" ), but instead the default windows's terminal ( CMD ) is opened for the task to execute, not the integrated terminal.

It seems that the default windows's terminal has a higher priority than the integrated terminal.

"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",

Thank you,

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.