Skip to content

foobar1643/neotest-phpunit

 
 

Repository files navigation

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"
    end,
    root_files = { "composer.json", "phpunit.xml", ".gitignore" },
    filter_dirs = { ".git", "node_modules" }
  }),
}

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
})

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
})

🚀 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

About

🧪 Neotest adapter for PHPUnit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 83.3%
  • PHP 14.4%
  • Shell 2.1%
  • Vim Script 0.2%