feat: implement phpunit adapter

This commit is contained in:
kbwo 2024-08-24 22:54:18 +09:00
parent daa8db434c
commit 3e3d4c5db1
15 changed files with 2125 additions and 9 deletions

View file

@ -3,17 +3,17 @@
"testing": {
"command": "testing-language-server",
"trace.server": "verbose",
"filetypes": ["rust", "javascript", "go", "typescript"],
"filetypes": ["rust", "javascript", "go", "typescript", "php"],
"initializationOptions": {
"adapterCommand": {
// "cargo-test": [
// {
// "path": "testing-ls-adapter",
// "extra_args": ["--test-kind=cargo-test"],
// "include_patterns": ["/**/src/**/*.rs"],
// "exclude_patterns": ["/**/target/**"]
// }
// ],
"cargo-test": [
{
"path": "testing-ls-adapter",
"extra_args": ["--test-kind=cargo-test"],
"include_patterns": ["/**/src/**/*.rs"],
"exclude_patterns": ["/**/target/**"]
}
],
"cargo-nextest": [
{
"path": "testing-ls-adapter",
@ -56,6 +56,14 @@
"include_patterns": ["/**/*.go"],
"exclude_patterns": []
}
],
"phpunit": [
{
"path": "testing-ls-adapter",
"extra_args": ["--test-kind=phpunit"],
"include_patterns": ["/**/*Test.php"],
"exclude_patterns": ["/phpunit/vendor/**/*.php"]
}
]
}
}

1
demo/phpunit/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
vendor

2
demo/phpunit/.mise.toml Normal file
View file

@ -0,0 +1,2 @@
[tools]
php = "8.3"

View file

@ -0,0 +1,17 @@
{
"name": "kbwo/phpunit",
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"authors": [
{
"name": "kbwo",
"email": "kabaaa1126@gmail.com"
}
],
"require-dev": {
"phpunit/phpunit": "^11.3"
}
}

1651
demo/phpunit/composer.lock generated Normal file

File diff suppressed because it is too large Load diff

15
demo/phpunit/output.xml Normal file
View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="CLI Arguments" tests="3" assertions="3" errors="0" failures="1" skipped="0" time="0.002791">
<testsuite name="Tests\CalculatorTest" file="/home/kbwo/testing-language-server/demo/phpunit/src/CalculatorTest.php" tests="3" assertions="3" errors="0" failures="1" skipped="0" time="0.002791">
<testcase name="testAdd" file="/home/kbwo/testing-language-server/demo/phpunit/src/CalculatorTest.php" line="10" class="Tests\CalculatorTest" classname="Tests.CalculatorTest" assertions="1" time="0.000695"/>
<testcase name="testSubtract" file="/home/kbwo/testing-language-server/demo/phpunit/src/CalculatorTest.php" line="17" class="Tests\CalculatorTest" classname="Tests.CalculatorTest" assertions="1" time="0.000046"/>
<testcase name="testFail1" file="/home/kbwo/testing-language-server/demo/phpunit/src/CalculatorTest.php" line="24" class="Tests\CalculatorTest" classname="Tests.CalculatorTest" assertions="1" time="0.002051">
<failure type="PHPUnit\Framework\ExpectationFailedException">Tests\CalculatorTest::testFail1
Failed asserting that 8 matches expected 1.
/home/kbwo/testing-language-server/demo/phpunit/src/CalculatorTest.php:28</failure>
</testcase>
</testsuite>
</testsuite>
</testsuites>

View file

@ -0,0 +1,16 @@
<?php
namespace App;
class Calculator
{
public function add($a, $b)
{
return $a + $b;
}
public function subtract($a, $b)
{
return $a - $b;
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace Tests;
use App\Calculator;
use PHPUnit\Framework\TestCase;
class CalculatorTest extends TestCase
{
public function testAdd()
{
$calculator = new Calculator();
$result = $calculator->add(2, 3);
$this->assertEquals(5, $result);
}
public function testSubtract()
{
$calculator = new Calculator();
$result = $calculator->subtract(5, 3);
$this->assertEquals(2, $result);
}
public function testFail1()
{
$calculator = new Calculator();
$result = $calculator->subtract(10, 2);
$this->assertEquals(1, $result);
}
}