mirror of
https://github.com/pnx/neotest-phpunit
synced 2026-06-16 03:54:55 +02:00
Further simplification
This commit is contained in:
parent
9f7192cee5
commit
05a3a8fe97
4 changed files with 61 additions and 46 deletions
|
|
@ -34,6 +34,14 @@ function M.env.sail_enabled()
|
||||||
return M.sail_available()
|
return M.sail_available()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.env.pest_cmd()
|
||||||
|
if M('sail_enabled') then
|
||||||
|
return { "vendor/bin/sail", "bin", "pest" }
|
||||||
|
end
|
||||||
|
|
||||||
|
return { "vendor/bin/pest" }
|
||||||
|
end
|
||||||
|
|
||||||
function M.env.results_path()
|
function M.env.results_path()
|
||||||
if M('sail_enabled') then
|
if M('sail_enabled') then
|
||||||
return "storage/app/" .. os.date("junit-%Y%m%d-%H%M%S")
|
return "storage/app/" .. os.date("junit-%Y%m%d-%H%M%S")
|
||||||
|
|
@ -48,6 +56,7 @@ end
|
||||||
|
|
||||||
function M.sail_available()
|
function M.sail_available()
|
||||||
if vim.fn.filereadable(M('sail_executable')) == 1 then
|
if vim.fn.filereadable(M('sail_executable')) == 1 then
|
||||||
|
M._sail_enabled = true
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ local logger = require('neotest.logging')
|
||||||
local utils = require('neotest-pest.utils')
|
local utils = require('neotest-pest.utils')
|
||||||
local config = require('neotest-pest.config')
|
local config = require('neotest-pest.config')
|
||||||
|
|
||||||
|
local info = logger.info
|
||||||
|
local debug = logger.debug
|
||||||
|
|
||||||
---@class neotest.Adapter
|
---@class neotest.Adapter
|
||||||
---@field name string
|
---@field name string
|
||||||
local NeotestAdapter = { name = "neotest-pest" }
|
local NeotestAdapter = { name = "neotest-pest" }
|
||||||
|
|
@ -16,31 +19,31 @@ local NeotestAdapter = { name = "neotest-pest" }
|
||||||
function NeotestAdapter.root(dir)
|
function NeotestAdapter.root(dir)
|
||||||
local result = nil
|
local result = nil
|
||||||
|
|
||||||
logger.debug("Finding root...")
|
debug("Finding root...")
|
||||||
|
|
||||||
for _, root_ignore_file in ipairs(config("root_ignore_files")) do
|
for _, root_ignore_file in ipairs(config("root_ignore_files")) do
|
||||||
logger.debug("Checking root ignore file", root_ignore_file)
|
debug("Checking root ignore file", root_ignore_file)
|
||||||
|
|
||||||
result = lib.files.match_root_pattern(root_ignore_file)(dir)
|
result = lib.files.match_root_pattern(root_ignore_file)(dir)
|
||||||
|
|
||||||
if result then
|
if result then
|
||||||
logger.debug("Ignoring root because file", root_ignore_file)
|
debug("Ignoring root because file", root_ignore_file)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, root_file in ipairs(config("root_files")) do
|
for _, root_file in ipairs(config("root_files")) do
|
||||||
logger.debug("Checking root file", root_file)
|
debug("Checking root file", root_file)
|
||||||
|
|
||||||
result = lib.files.match_root_pattern(root_file)(dir)
|
result = lib.files.match_root_pattern(root_file)(dir)
|
||||||
|
|
||||||
if result then
|
if result then
|
||||||
logger.debug("Found root", result)
|
debug("Found root", result)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
logger.debug("Root not found")
|
debug("Root not found")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
@ -95,45 +98,34 @@ end
|
||||||
function NeotestAdapter.build_spec(args)
|
function NeotestAdapter.build_spec(args)
|
||||||
local position = args.tree:data()
|
local position = args.tree:data()
|
||||||
local results_path = config('results_path')
|
local results_path = config('results_path')
|
||||||
local binary = config('pest_cmd')
|
|
||||||
|
|
||||||
logger.info("Building spec for:", position)
|
info("Building spec for:", position)
|
||||||
logger.info("Results path:", results_path)
|
info("Results path:", results_path)
|
||||||
|
|
||||||
local command = {}
|
local path = position.path;
|
||||||
|
|
||||||
if config('sail_enabled') then
|
if config('sail_enabled') then
|
||||||
logger.info("Sail enabled")
|
info("Sail enabled, adjusting path")
|
||||||
command = vim.tbl_flatten({
|
path = "/var/www/html" .. string.sub(position.path, string.len(vim.loop.cwd() or "") + 1)
|
||||||
"vendor/bin/sail", "bin", "pest",
|
|
||||||
position.name ~= "tests" and ("/var/www/html" .. string.sub(position.path, string.len(vim.loop.cwd() or "") + 1)),
|
|
||||||
})
|
|
||||||
else
|
|
||||||
logger.info("Sail not enabled")
|
|
||||||
command = vim.tbl_flatten({
|
|
||||||
binary,
|
|
||||||
position.name ~= "tests" and position.path,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
command = vim.tbl_flatten({
|
local command = vim.tbl_flatten({
|
||||||
command,
|
config('pest_cmd'),
|
||||||
|
path,
|
||||||
"--log-junit=" .. results_path,
|
"--log-junit=" .. results_path,
|
||||||
})
|
})
|
||||||
|
|
||||||
if position.type == "test" then
|
if position.type == "test" then
|
||||||
local script_args = vim.tbl_flatten({
|
command = vim.tbl_flatten({
|
||||||
|
command,
|
||||||
"--filter",
|
"--filter",
|
||||||
position.name,
|
position.name,
|
||||||
})
|
})
|
||||||
|
else
|
||||||
command = vim.tbl_flatten({
|
debug("Position type:", position.type)
|
||||||
command,
|
|
||||||
script_args,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
logger.info("Command:", command)
|
info("Command:", command)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
command = command,
|
command = command,
|
||||||
|
|
|
||||||
28
phpunit.xml
28
phpunit.xml
|
|
@ -1,18 +1,14 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="src/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
|
||||||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
|
<testsuites>
|
||||||
bootstrap="src/autoload.php"
|
<testsuite name="Test Suite">
|
||||||
colors="true"
|
<directory suffix="Test.php">./tests</directory>
|
||||||
>
|
</testsuite>
|
||||||
<testsuites>
|
</testsuites>
|
||||||
<testsuite name="Test Suite">
|
<source>
|
||||||
<directory suffix="Test.php">./tests</directory>
|
<include>
|
||||||
</testsuite>
|
<directory suffix=".php">./app</directory>
|
||||||
</testsuites>
|
<directory suffix=".php">./src</directory>
|
||||||
<coverage processUncoveredFiles="true">
|
</include>
|
||||||
<include>
|
</source>
|
||||||
<directory suffix=".php">./app</directory>
|
|
||||||
<directory suffix=".php">./src</directory>
|
|
||||||
</include>
|
|
||||||
</coverage>
|
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
|
||||||
18
phpunit.xml.bak
Normal file
18
phpunit.xml.bak
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
|
||||||
|
bootstrap="src/autoload.php"
|
||||||
|
colors="true"
|
||||||
|
>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Test Suite">
|
||||||
|
<directory suffix="Test.php">./tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<coverage processUncoveredFiles="true">
|
||||||
|
<include>
|
||||||
|
<directory suffix=".php">./app</directory>
|
||||||
|
<directory suffix=".php">./src</directory>
|
||||||
|
</include>
|
||||||
|
</coverage>
|
||||||
|
</phpunit>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue