vscode-phpunit: [2.0.74] Single method test from codelens doesn't work

I’ve found that it is unable to run individual tests by using the “Run” button shown in codelens or in the test explorer sidebar.

This doesn’t affect when you run an entire TestCase for all the test class.

I’ve tested with a couple of repos, for example, your Laravel terminal:

git clone git@github.com:recca0120/laravel-terminal.git
cd laravel-terminal/
composer install
[Trace - 12:52:34 PM] Received request 'TestRunStartedEvent-7230d859cf71e9b67259b2a955550626 - (11)'.
Params: {
    "tests": [
        "Recca0120\\Terminal\\Tests\\ApplicationTest::testCallAndRequestIsAjax"
    ],
    "events": [
        {
            "type": "test",
            "test": "Recca0120\\Terminal\\Tests\\ApplicationTest::testCallAndRequestIsAjax",
            "state": "running"
        }
    ]
}


[Trace - 12:52:34 PM] Sending response 'TestRunStartedEvent-7230d859cf71e9b67259b2a955550626 - (11)'. Processing request took 0ms
No result returned.


[Trace - 12:52:34 PM] Received notification 'TestRunFinishedEvent'.
Params: {
    "command": {
        "title": "PHPUnit LSP",
        "command": "/home/rodolfo/git/recca/laravel-terminal/vendor/bin/phpunit",
        "arguments": [
            "-c",
            "/home/rodolfo/git/recca/laravel-terminal/phpunit.xml.dist",
            "--filter",
            "'/^.*::testCallAndRequestIsAjax.*$/'",
            "/home/rodolfo/git/recca/laravel-terminal/tests/ApplicationTest.php"
        ]
    },
    "events": [
        {
            "type": "test",
            "test": "Recca0120\\Terminal\\Tests\\ApplicationTest::testCallAndRequestIsAjax",
            "state": "errored",
            "message": "PHPUnit 8.5.8 by Sebastian Bergmann and contributors.\n\nRuntime:       PHP 7.4.6 with Xdebug 2.9.3\nConfiguration: /home/rodolfo/git/recca/laravel-terminal/phpunit.xml.dist\n\nNo tests executed!\n\nGenerating code coverage report in Clover XML format ... done [122 ms]\n\nGenerating code coverage report in HTML format ... done [49 ms]\n"
        }
    ]
}


[Trace - 12:52:34 PM] Received request 'TestRunFinishedEvent-7230d859cf71e9b67259b2a955550626 - (12)'.
Params: {
    "command": {
        "title": "PHPUnit LSP",
        "command": "/home/rodolfo/git/recca/laravel-terminal/vendor/bin/phpunit",
        "arguments": [
            "-c",
            "/home/rodolfo/git/recca/laravel-terminal/phpunit.xml.dist",
            "--filter",
            "'/^.*::testCallAndRequestIsAjax.*$/'",
            "/home/rodolfo/git/recca/laravel-terminal/tests/ApplicationTest.php"
        ]
    },
    "events": [
        {
            "type": "test",
            "test": "Recca0120\\Terminal\\Tests\\ApplicationTest::testCallAndRequestIsAjax",
            "state": "errored",
            "message": "PHPUnit 8.5.8 by Sebastian Bergmann and contributors.\n\nRuntime:       PHP 7.4.6 with Xdebug 2.9.3\nConfiguration: /home/rodolfo/git/recca/laravel-terminal/phpunit.xml.dist\n\nNo tests executed!\n\nGenerating code coverage report in Clover XML format ... done [122 ms]\n\nGenerating code coverage report in HTML format ... done [49 ms]\n"
        }
    ]
}


[Trace - 12:52:34 PM] Sending response 'TestRunFinishedEvent-7230d859cf71e9b67259b2a955550626 - (12)'. Processing request took 3ms
No result returned.


[Trace - 12:52:34 PM] Received notification 'window/logMessage'.
Params: {
    "type": 4,
    "message": "PHPUnit 8.5.8 by Sebastian Bergmann and contributors.\n\nRuntime:       PHP 7.4.6 with Xdebug 2.9.3\nConfiguration: /home/rodolfo/git/recca/laravel-terminal/phpunit.xml.dist\n\nNo tests executed!\n\nGenerating code coverage report in Clover XML format ... done [122 ms]\n\nGenerating code coverage report in HTML format ... done [49 ms]\n"
}


PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.6 with Xdebug 2.9.3
Configuration: /home/rodolfo/git/recca/laravel-terminal/phpunit.xml.dist

No tests executed!

Generating code coverage report in Clover XML format ... done [122 ms]

Generating code coverage report in HTML format ... done [49 ms]


Same with Slim Framework:

git clone git@github.com:slimphp/Slim.git
cd Slim/
composer install
[Trace - 12:45:31 PM] Received request 'TestRunStartedEvent-011e96e0d8b6ed43f2e253ed1c0559ee - (23)'.
Params: {
    "tests": [
        "Slim\\Tests\\CallableResolverTest::testFunctionName"
    ],
    "events": [
        {
            "type": "test",
            "test": "Slim\\Tests\\CallableResolverTest::testFunctionName",
            "state": "running"
        }
    ]
}


[Trace - 12:45:31 PM] Sending response 'TestRunStartedEvent-011e96e0d8b6ed43f2e253ed1c0559ee - (23)'. Processing request took 0ms
No result returned.


[Trace - 12:45:32 PM] Received notification 'TestRunFinishedEvent'.
Params: {
    "command": {
        "title": "PHPUnit LSP",
        "command": "/home/rodolfo/git/chevere/Slim/vendor/bin/phpunit",
        "arguments": [
            "-c",
            "/home/rodolfo/git/chevere/Slim/phpunit.xml.dist",
            "--filter",
            "'/^.*::testFunctionName.*$/'",
            "/home/rodolfo/git/chevere/Slim/tests/CallableResolverTest.php"
        ]
    },
    "events": [
        {
            "type": "test",
            "test": "Slim\\Tests\\CallableResolverTest::testFunctionName",
            "state": "errored",
            "message": "PHPUnit 8.5.8 by Sebastian Bergmann and contributors.\n\nNo tests executed!\n\nGenerating code coverage report in HTML format ... done [578 ms]\n"
        }
    ]
}


[Trace - 12:45:32 PM] Received request 'TestRunFinishedEvent-011e96e0d8b6ed43f2e253ed1c0559ee - (24)'.
Params: {
    "command": {
        "title": "PHPUnit LSP",
        "command": "/home/rodolfo/git/chevere/Slim/vendor/bin/phpunit",
        "arguments": [
            "-c",
            "/home/rodolfo/git/chevere/Slim/phpunit.xml.dist",
            "--filter",
            "'/^.*::testFunctionName.*$/'",
            "/home/rodolfo/git/chevere/Slim/tests/CallableResolverTest.php"
        ]
    },
    "events": [
        {
            "type": "test",
            "test": "Slim\\Tests\\CallableResolverTest::testFunctionName",
            "state": "errored",
            "message": "PHPUnit 8.5.8 by Sebastian Bergmann and contributors.\n\nNo tests executed!\n\nGenerating code coverage report in HTML format ... done [578 ms]\n"
        }
    ]
}


[Trace - 12:45:32 PM] Sending response 'TestRunFinishedEvent-011e96e0d8b6ed43f2e253ed1c0559ee - (24)'. Processing request took 9ms
No result returned.


[Trace - 12:45:32 PM] Received notification 'window/logMessage'.
Params: {
    "type": 4,
    "message": "PHPUnit 8.5.8 by Sebastian Bergmann and contributors.\n\nNo tests executed!\n\nGenerating code coverage report in HTML format ... done [578 ms]\n"
}


PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

No tests executed!

Generating code coverage report in HTML format ... done [578 ms]


I also tried with PHPUnit 9 and it is the same result.

PHP 7.4.6 with Xdebug 2.9.3
Ubuntu 20.04

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 7
  • Comments: 17

Commits related to this issue

Most upvoted comments

As others mentioned, reverting the extension to version 2.0.73 solves the issue so that’s what I’ve done for now.

I have same issue and resolved after setting phpunit.shell

"phpunit.shell": "zsh"

Looking PhpUnit.log I have noticed that around July 30, 2020, the 3rd parameter (value of --filter) became decorated with “'”. I tried it on a command line and after removing “'”, PhpUnit executed tests. With “'” around the expression, I just got “No tests executed!”. I am using Windows.

Example (PhpUnit.log): Before July 30:

{
  title: 'PHPUnit LSP',
  command: '...\\php.exe',
  arguments: [
    '...\\phpunit',
    '--filter',
    '^.*::(testRenderEmail)( with data set .*)?$',
    '...SomePhpFile.php'
  ]
}

After July 30:

{
  title: 'PHPUnit LSP',
  command: 'c:\\wamp64\\bin\\php\\php7.2.10\\php.exe',
  arguments: [
    '...\\phpunit',
    '--filter',
    "'/^.*::testGetUrlHost.*$/'",
    '...SomePhpFile.php'
  ]
}

This might be a bit of a duplicate of: https://github.com/recca0120/vscode-phpunit/issues/63