Git Product home page Git Product logo

neotest-phpunit's Introduction

neotest-phpunit

Tests

This plugin provides a PHPUnit adapter for the Neotest framework.

Neotest and PHPUnit

โš ๏ธ This plugin is still in the early stages of development. Please test against your PHPUnit tests โš ๏ธ

๐Ÿ“ฆ Installation

Install with the package manager of your choice:

Lazy

{
  "nvim-neotest/neotest",
  lazy = true,
  dependencies = {
    ...,
    "olimorris/neotest-phpunit",
  },
  config = function()
    require("neotest").setup({
      ...,
      adapters = {
        require("neotest-phpunit")
      },
    }
  end
}

Packer

use({
  "nvim-neotest/neotest",
  requires = {
    ...,
    "olimorris/neotest-phpunit",
  },
  config = function()
    require("neotest").setup({
      ...,
      adapters = {
        require("neotest-phpunit"),
      }
    })
  end
})

๐Ÿ”ง Configuration

Default configuration

Note: You only need to the call the setup function if you wish to change any of the defaults.

Click to see the default configuration
adapters = {
  require("neotest-phpunit")({
    phpunit_cmd = function()
      return "vendor/bin/phpunit" -- for `dap` strategy then it must return string (table values will cause validation error)
    end,
    root_files = { "composer.json", "phpunit.xml", ".gitignore" },
    filter_dirs = { ".git", "node_modules" },
    env = {}, -- for example {XDEBUG_CONFIG = 'idekey=neotest'}
    dap = nil, -- to configure `dap` strategy put single element from `dap.configurations.php`
  }),
}

The test command

The command used to run tests can be changed via the phpunit_cmd option:

require("neotest-phpunit")({
  phpunit_cmd = function()
    return "vendor/bin/phpunit"
  end
})

Setting the root directory

For Neotest adapters to work, they need to define a project root whereby the process of discovering tests can take place. By default, the adapter looks for a composer.json, phpunit.xml or .gitignore file. These can be changed with:

require("neotest-phpunit")({
  root_files = { "README.md" }
})

You can even set root_files with a function which returns a table:

require("neotest-phpunit")({
  root_files = function() return { "README.md" } end
})

If there are projects you don't want discovered, you can instead set root_ignore_files to ignore any matching projects.

For example, if your project uses Pest and the appropriate neotest adapter, you'll need to set:

require("neotest-phpunit")({
    root_ignore_files = { "tests/Pest.php" }
})

Filtering directories

By default, the adapter will search test files in all dirs in the root with the exception of node_modules and .git. You can change this with:

require("neotest-phpunit")({
  filter_dirs = { "vendor" }
})

You can even set filter_dirs with a function which returns a table:

require("neotest-phpunit")({
  filter_dirs = function() return { "vendor" } end
})

Debugging with dap strategy

You need to install and configure nvim-dap with vscode-php-debug first. For example if you have

dap.configurations.php = {
  {
    log = true,
    type = "php",
    request = "launch",
    name = "Listen for XDebug",
    port = 9003,
    stopOnEntry = false,
    xdebugSettings = {
      max_children = 512,
      max_data = 1024,
      max_depth = 4,
    },
    breakpoints = {
      exception = {
        Notice = false,
        Warning = false,
        Error = false,
        Exception = false,
        ["*"] = false,
      },
    },
  }
}

you can set

require("neotest-phpunit")({
  env = {
      XDEBUG_CONFIG = "idekey=neotest",
  },
  dap = dap.configurations.php[1],
})

If you run a test with dap strategy from the summary window (by default by d) and see that window content replaced by debugged buffer content then consider setting dap.defaults.fallback.switchbuf or Neovim level switchbuf, f.e.

dap.defaults.fallback.switchbuf = "useopen"

๐Ÿš€ Usage

Test single method

To test a single test, hover over the test and run lua require("neotest").run.run()

Test file

To test a file run lua require("neotest").run.run(vim.fn.expand("%"))

Test directory

To test a directory run lua require("neotest").run.run("path/to/directory")

Test suite

To test the full test suite run lua require("neotest").run.run({ suite = true })

๐ŸŽ Contributing

This project is maintained by the Neovim PHP community. Please raise a PR if you are interested in adding new functionality or fixing any bugs. When submitting a bug, please include an example test that we can test against.

To trigger the tests for the adapter, run:

./scripts/test

neotest-phpunit's People

Contributors

olimorris avatar heimer16 avatar przepompownia avatar v13axel avatar rcarriga avatar

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.