olimorris / neotest-phpunit Goto Github PK
View Code? Open in Web Editor NEW๐งช Neotest adapter for PHPUnit
License: MIT License
๐งช Neotest adapter for PHPUnit
License: MIT License
Even primitive detection (without pointing the method the provider belongs to) of yield
ed 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
neotest-phpunit/lua/neotest-phpunit/init.lua
Lines 137 to 141 in 5799a4e
I want to be able to pass arguments to the phpunit process. For example, I would like to pass
-c ohter-phpunit.xml
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?
Think it's to do with some deep nesting in the test outputs
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)
after get last updates the DAP is not working anymore :/
I tried to do this
dap = dap.configurations.php[1],
...
dap.defaults.fallback.switchbuf = "useopen"
But it is not working :/
it is my config: https://github.com/eerison/lazyvim/blob/main/lua/plugins/php.lua#L34
do you have any example to set this with lazyvim?
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?
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.
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!
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.
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
also on test failures, results show multiple tests were run:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.