Coder Social home page Coder Social logo

neotest-phpunit's People

Contributors

cgimenes avatar heimer16 avatar miduddin avatar olimorris avatar przepompownia avatar rcarriga avatar v13axel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

neotest-phpunit's Issues

Support data sets in data provider

Even primitive detection (without pointing the method the provider belongs to) of yielded keys as named dataset

    (yield_expression
      (array_element_initializer
        (string
          (string_value) @dataset )))

could prove helpful in tests where yield is used in data provider.

At the moment I need some free time to answer myself how to pass the data set here

if position.type == "test" then
local filter_args = vim.tbl_flatten({
"--filter",
'::' .. position.name .. '( with data set .*)?$',
})

or into any better place and (optionally) how to list detected data set on the summary view. Any hints (as well as PR) can be helpful.

Allow passing arguments

I want to be able to pass arguments to the phpunit process. For example, I would like to pass

-c ohter-phpunit.xml

Make phpunit binary path configurable

Hello,

as i can see the path to the binary of phpunit seems to be hardcoded in init.lua file. Correct me if i am wrong :)
I would wish that i can define the path to the executable in the setup section of the plugin.

Can you hint me how i can change the path in the meantime?

Allow to swap executable

Hey,

Here again :).

So in my work I regularly have nested projects. For example a laravel installation, with a set of packages.

LaravelRoot/
  packages/
    package1/
      composer.json
      vendor/...

I do not know if it is possible to somehow swap the executable to use the closest vendor folder? This so it uses the phpunit config corresponding to the context it is in.

(package1 should use /LaravelRoot/packages/package1/vendor/bin/phpunit instead of /LaravelRoot/vendor/bin/phpunit)

if vim.fn.filereadable("vendor/bin/phpunit") then

How do I run Test from within Docker?

I would like to migrate from vim-test but it seems I'm missing something.
My development environment is running inside Docker, so the way to execute the tests is:

docker exec -it $(docker ps -n=-1 -q --filter name=cityoffer_phpfpm --format="{{.ID}}") vendor/bin/phpunit

but if I configure the phpunit_cmd like this

local neotest = require("neotest")
neotest.setup({
    adapters = {
        require('neotest-phpunit')({
            phpunit_cmd = function()
                return 'docker exec -it $(docker ps -n=-1 -q --filter name=phpfpm --format="{{.ID}}") vendor/bin/phpunit'
            end
        }),
    },
})

I'm getting this error

Invalid value for argument cmd: 'docker exec -it $(docker ps -n=-1 -q --filter name=phpfpm --format="{{.ID}}") vendor/bin/phpunit' is not executable

I also tried to substitute $(docker ps -n=-1 -q --filter name=phpfpm --format="{{.ID}}") with the real ID with no luck.
And also I tried to through a shell script and got high CPU usage without a running test (and without any errors)

So how do I execute tests inside Docker?

DAP configuration ?

Is there a way to set this up so running lua tests.run.run(strategy = {"dap"}) works? Currently using that strategy says that phpunit doesn't support that adapter.

Issues with weird monorepo structures, can't get to work

Hi, apologies as I don't think this is an issue with the adapter itself, but I for the life of me cannot get this to work and have spent about 3+days trying to now. If you wouldn't mind, I'd love a little help.

For work we have a monorepo with the following structure:

root
root/platform
root/platform/vendor/bin/phpunit
root/platform/resources/client

the platform directory contains backend php code, and frontend code (inside resources client).
When using neovim I open the platform directory, so for all intents and purposes this is my root dir.

platform contains the vendor dir in which phpunit is located.

platform contains a phpunit.xml & composer.json.

What I am seeing is if I open neovim from the platform directory, no tests are found. I have php parser installed via treesitter, treesitters checkhealth is all fine, and highlighting etc works as expected.

If I open the root/platform/resources/client directory directly then tests are found, but do not run (failing immediately, due to it trying to test the live DB (which it isn't)). However I need to have the root/platform directory as my "root" dir.

This is my neotest config:

{
        'nvim-neotest/neotest',
        dependencies = {
            'nvim-neotest/nvim-nio',
            'antoinemadec/FixCursorHold.nvim',
            'nvim-lua/plenary.nvim',
            'nvim-treesitter/nvim-treesitter',
            'nvim-neotest/neotest-jest',
            'olimorris/neotest-phpunit',
            'nvim-neotest/nvim-nio',
        },
        config = function()
            local neotest = require 'neotest'
            ---@diagnostic disable-next-line: missing-fields
            neotest.setup {
                adapters = {
                    require 'neotest-jest' {
                        -- TODO: make this dynamic based on the project, currently it's hardcoded for ous weird monorepo
                        cwd = '/Users/caligula/oneupsales/platform/resources/client',
                        jestCommand = 'npm test --',
                    },
                    require 'neotest-phpunit' {
                        phpunit_cmd = function()
                            return 'vendor/bin/phpunit'
                        end,
                        root_files = { 'phpunit.xml', 'pint.json', 'composer.json' },
                        -- filter_dirs = { '.git', 'node_modules' },
                        -- root_ignore_files = { 'vite.config.ts' },
                    },
                    -- require 'neotest-phpunit' {
                    --     phpunit_cmd = function()
                    --         return 'vendor/bin/phpunit'
                    --     end,
                    --     root_files = { 'phpunit.xml', 'pint.json', 'composer.json' },
                    --     filter_dirs = { '.git', 'node_modules', 'vendor' },
                    --     root_ignore_files = { 'vite.config.ts' },
                    -- },
                },
                ---@diagnostic disable-next-line: missing-fields
                diagnostic = {
                    enabled = true,
                },
                icons = {
                    failed = test_icons.failed,
                    passed = test_icons.passed,
                    running = test_icons.running,
                    skipped = test_icons.skipped,
                },
            }
        end,
        -- stylua: ignore
        keys = {
            { "<leader>tr", function() require("neotest").run.run() end, desc = "[T]est [r]un nearest" },

            { "<leader>tR", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "[T]est [R]un file" },

            { "<leader>tc", function() require("neotest").run.stop() end, desc = "[T]est [c]ancel nearest" },

            { "<leader>ta", function() require("neotest").run.attach() end, desc = "[T]est [a]ttach to nearest" },

            { "<leader>to", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "[T]est [o]utput open" },

            { "<leader>tO", function() require("neotest").output_panel.toggle() end, desc = "[T]est [O]utput panel" },

            { "<leader>ts", function() require("neotest").summary.toggle() end, desc = "[T]est [s]ummary" },

            { "<leader>tw", function() require("neotest").summary.toggle() end, desc = "[T]est [w]atch" },

            { "]t", function() require("neotest").jump.next({status = 'failed'}) end, desc = "Jump to next failed [t]est" },

            { "[t", function() require("neotest").jump.prev({status = 'failed'}) end, desc = "Jump to previous failed [t]est" },
        },
    },

As you can see from the various commented out lines, I have tried and continue to try may different options to get this to work.

my neotest.log is outputting the following error:

โ”‚ WARN | 2024-04-27T10:45:42Z+0100 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:164 | CHILD | Error in remote call ...0.9.5/share/nvim/runtime/lua/vim/treesitter/language.lua:87: '' is not a valid lang
       โ”‚ uage name
 104   โ”‚ stack traceback:
 105   โ”‚     [C]: in function 'error'
 106   โ”‚     ...0.9.5/share/nvim/runtime/lua/vim/treesitter/language.lua:87: in function 'add'
 107   โ”‚     ...5/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:98: in function 'get_string_parser'
 108   โ”‚     ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:119: in function 'get_parse_root'
 109   โ”‚     ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:160: in function 'parse_positions_from_string'
 110   โ”‚     ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:207: in function 'func'
 111   โ”‚     ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:156: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:155>
 112   โ”‚     [C]: in function 'xpcall'
 113   โ”‚     ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:155: in function <...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:154>

which makes it seem like a treesitter issue, but as explained above I have checked and everything seems to be working as expected in regards to php and treesitter (execpt in regards to neotest).

I have uninstalled treesitter, and the php parser, reinstalled, stripped my treesitter config, down to it's most basic etc. nothing seems to help.

The tests run via the cli & in phpstorm fine.

I'm at a bit of a loss here, so if you have any thoughts I'd hugely appreciate it. Thank you!

Cannot make it work

Hi,

Very curious about using this. However I cannot seem to make it work. Always receiving No tests found

I have a composer(laravel) project with phpunit.xml and composer.json in the root.

Path to the test is tests/Unit/ExampleTest.php

Test content:

<?php

namespace Tests\Unit;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function test_example()
    {
        $this->assertTrue(true);
    }
}

If you like more info let me know, can also setup screen sharing if it would help.

I tested dumping NeotestAdapter.is_test_file, and it does "see" the test.

Test nearest runs multiple test with similar name

When running the default "test nearest" require("neotest").run.run() if another test starts with the same string as the test that is run, both are run.

for example:

test_something()
{
  $this->assertTrue(true); | <-- cursor when executing
}

test_something_else()  // <-- this test also runs if function starts with the same string "test_something"
{
  $this->assertTrue(true);
}

screenshot with the status after running the first test: status indicator shows both tests were run

2022-10-19-100039_558x302_scrot

also on test failures, results show multiple tests were run:

2022-10-19-100204_1146x599_scrot

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.