# neotest-phpunit This plugin provides a [PHPUnit](https://phpunit.de) adapter for the [Neotest](https://github.com/nvim-neotest/neotest) framework. This is a fork of `neotest-pest` originally by [@V13Axel](https://github.com/V13Axel/neotest-pest) modified for phpunit - Support for (and automatic detection of) Laravel Sail - Note: This also moves phpunit output files into `storage/app/` - Parallel testing support :warning: _Ive only focused on making this work for me. Please test against your phpunit tests_ :warning: ## :package: Installation Install the plugin using your favorite package manager. Here's an example using lazy.nvim: ```lua { 'nvim-neotest/neotest', dependencies = { ..., 'pnx/neotest-phpunit', }, config = function() require('neotest').setup({ ..., adapters = { require('neotest-phpunit'), } }) end } ``` ## :wrench: Configuration > [!TIP] > Any of these options can be set to a lua function that returns the desired result. For example, wanna run tests in parallel, one for each CPU core? > `parallel = function() return #vim.loop.cpu_info() end,` ```lua adapters = { require('neotest-pest')({ -- Ignore these directories when looking for tests -- -- Default: { "vendor", "node_modules" } ignore_dirs = { "vendor", "node_modules" } -- Ignore any projects containing "no_phpunit" -- -- Default: {} root_ignore_files = { "no_phpunit" }, -- Specify suffixes for files that should be considered tests -- -- Default: { "Test.php" } test_file_suffixes = { "Test.php", "_test.php" }, -- Sail not properly detected? Explicitly enable it. -- -- Default: function() that checks for sail presence sail_enabled = function() return false end, -- Custom sail executable. Not running in Sail, but running bare Docker? -- Set `sail_enabled` = true and `sail_executable` to { "docker", "exec", "[somecontainer]" } -- -- Default: "vendor/bin/sail" sail_executable = "vendor/bin/sail", -- Custom sail project root path. -- -- Default: "/var/www/html" sail_project_path = "/var/www/html", -- Custom pest binary. -- -- Default: function that checks for sail presence phpunit_cmd = "vendor/bin/phpunit", -- Run N tests in parallel, <=1 doesn't pass --parallel to phpunit at all -- -- Default: 0 parallel = 16 -- Set a custom path for the results XML file, parsed by this adapter -- ------------------------------------------------------------------------------------ -- NOTE: This must be a path accessible by both your test runner AND your editor! -- ------------------------------------------------------------------------------------ -- -- -- Default: function that checks for sail presence. -- -- - If no sail: Numbered file in randomized /tmp/ directory (using async.fn.tempname()) -- -- - If sail: "storage/app/" .. os.date("junit-%Y%m%d-%H%M%S") results_path = function() "/some/accessible/path" end, }), } ``` ## :rocket: Usage #### Test single method To test a single test, hover over the test and run `lua require('neotest').run.run()`. As an example, I have mine setup with t(est)n(earest) as such: ```lua vim.keymap.set('n', 'tn', function() require('neotest').run.run() end) ``` #### Test file To test a file run `lua require('neotest').run.run(vim.fn.expand('%'))` Example - t(est)f(ile): ```lua vim.keymap.set('n', 'tf', function() require('neotest').run.run(vim.fn.expand('%')) end) ``` #### 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 })` ## :gift: Contributing 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 I can test against. To trigger the tests for the adapter, run: ```sh ./scripts/test ``` ## :clap: Prior Art This package is a fork of [neotest-pest](https://github.com/V13Axel/neotest-pest) by [@V13Axel](https://github.com/V13Axel) which is a fork of [neotest-pest](https://github.com/theutz/neotest-pest) by [@theutz](https://github.com/olimorris), which relied _heavily_ on [olimorris/neotest-phpunit](https://github.com/olimorris/neotest-phpunit) by [@olimorris](https://github.com/olimorris).