1
0
Fork 0
mirror of https://github.com/pnx/neotest-phpunit synced 2026-06-16 03:54:55 +02:00
No description
Find a file
2025-09-29 15:14:53 +02:00
.github/workflows Add github workflow 2022-11-17 01:36:49 +03:00
lua/neotest-phpunit phpunit 2025-09-23 19:50:41 +02:00
scripts Update tests of the plugin itself 2024-06-11 11:02:08 -04:00
specs Update tests of the plugin itself 2024-06-11 11:02:08 -04:00
src Pest runs with dummy code 2022-11-14 22:24:22 +03:00
tests convert tests from pest to phpunit 2025-09-29 15:14:53 +02:00
.gitignore Ignore testing packpath 2024-02-19 13:01:47 -05:00
.phpactor.json phpunit 2025-09-23 19:50:41 +02:00
.stylua.toml Add stylua 2022-11-14 22:15:39 +03:00
composer.json Update neotest-pest to work with Pest 2.0 2024-02-05 17:02:48 -05:00
composer.lock Update neotest-pest to work with Pest 2.0 2024-02-05 17:02:48 -05:00
LICENSE Remove leftover notify calls 2024-02-21 09:11:28 -05:00
phpstan.neon Setup phpstan and pint 2022-11-15 15:08:38 +03:00
phpunit.xml Further simplification 2024-02-17 13:28:03 -05:00
phpunit.xml.bak Further simplification 2024-02-17 13:28:03 -05:00
README.md phpunit 2025-09-23 19:50:41 +02:00

neotest-phpunit

This plugin provides a PHPUnit adapter for the Neotest framework.

This is a fork of neotest-pest originally by @V13Axel modified for phpunit

  • Support for (and automatic detection of) Laravel Sail
    • Note: This also moves phpunit output files into storage/app/
  • Parallel testing support

⚠️ Ive only focused on making this work for me. Please test against your phpunit tests ⚠️

📦 Installation

Install the plugin using your favorite package manager.

Here's an example using lazy.nvim:

{
    'nvim-neotest/neotest',
    dependencies = {
        ...,
        'pnx/neotest-phpunit',
    },
    config = function()
        require('neotest').setup({
            ...,
            adapters = {
                require('neotest-phpunit'),
            }
        })
    end
}

🔧 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,

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

🚀 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:

vim.keymap.set('n', '<leader>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):

vim.keymap.set('n', '<leader>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 })

🎁 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:

./scripts/test

👏 Prior Art

This package is a fork of neotest-pest by @V13Axel which is a fork of neotest-pest by @theutz, which relied heavily on olimorris/neotest-phpunit by @olimorris.