recca0120 / vscode-phpunit

The VS Code Test Explorer extension for PHPUnit
MIT License
127 stars 44 forks source link

[2.0.74] Single method test from codelens doesn't work #64

Closed rodber closed 4 years ago

rodber commented 4 years ago

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
MichMich commented 4 years ago

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

rodber commented 4 years ago

This might be a bit of a duplicate of: #63

I don't think that is a dupe. I'm not getting the "duplicated ID" message and in fact, the issue is on 2.0.74 as downgrading to 2.0.73 fixes the issue for me.

So, no dupe.

ntorga commented 4 years ago

I had the same issue, but I had to downgrade back to 2.0.72 cause 2.0.73 still didn't work. @rodolfoberrios can you confirm if you downgraded to .72 as well instead of .73?

rodber commented 4 years ago

I'ts very odd in my case as both 2.0.73 and 2.0.72 works fine for me. 2.0.74 breaks the single testing (never had the dupe thing).

I tested with combinations of this: {test,tests,Test,Tests}/**/*Test.php

Most likely there's a mixed issue here affecting certain file-systems.

I'm using Ubuntu 20.04.

aphix-mark commented 4 years ago

It looks as though the regex of /^.*::testCallAndRequestIsAjax.*$/ isn't working to identify the test (unrelated(?) to the case sensitivity)

Can you try run:

./bin/phpunit -c /home/rodolfo/git/recca/laravel-terminal/phpunit.xml.dist --filter '/^.*::testCallAndRequestIsAjax.*$/' /home/rodolfo/git/recca/laravel-terminal/tests/ApplicationTest.php

See if it does the same thing

Re #63 - this becoming this issue - but I think closing it because it was due to duplicate IDs is sorted and this ticket contains great info on the issue at hand.

hanak commented 4 years ago

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'
  ]
}
shawnhind commented 4 years ago

I'm having the same problem. For whatever reason, I can run full files of tests but running individual tests does not work. I'm having this problem on OpenSuse Tumbleweed. Mentioning the OS since others seem to think it might be related to specific filesystems.

shawnhind commented 4 years ago

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

dandoingdev commented 4 years ago

Same here. Single tests stop running after version 2.0.73

rodber commented 4 years ago

It looks as though the regex of /^.*::testCallAndRequestIsAjax.*$/ isn't working to identify the test (unrelated(?) to the case sensitivity)

Can you try run:

./bin/phpunit -c /home/rodolfo/git/recca/laravel-terminal/phpunit.xml.dist --filter '/^.*::testCallAndRequestIsAjax.*$/' /home/rodolfo/git/recca/laravel-terminal/tests/ApplicationTest.php

See if it does the same thing

Re #63 - this becoming this issue - but I think closing it because it was due to duplicate IDs is sorted and this ticket contains great info on the issue at hand.

I got the following (using vendor phpunit):

❯ vendor/bin/phpunit -c phpunit.xml.dist --filter '/^.*::testCallAndRequestIsAjax.*$/' tests/ApplicationTest.php
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

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

.                                                                   1 / 1 (100%)

Time: 353 ms, Memory: 8.00 MB

OK (1 test, 5 assertions)

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

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

As @hanak mentions, I've the same extra quotes under 2.0.74. It doesn't seem to be related to the actual regex, just the quotes.

alkin commented 4 years ago

Same here. Single tests not being executed. Downgrading to 2.0.72 worked.

kaloczikvn commented 4 years ago

Downgraded to 2.0.72 but still gives me "No tests executed!" when running a singular test.

musingfox commented 4 years ago

I have same issue and resolved after setting phpunit.shell

"phpunit.shell": "zsh"
shawnhind commented 4 years ago

Suggestion for @musingfox worked for me as well. I'd downgraded versions to fix the problem. I just tested upgrading again and confirmed I still had the issue. Then I added that for my setting and now it works again.

Am wondering if maybe this was only a problem for zsh users then?

johnnyhuy commented 4 years ago

I was able to use bash instead and it worked. I'm using this extension in a remote dev container as well.

"phpunit.shell": "bash"
tyler36 commented 4 years ago

Not working on 2.0.75 for me too. Single tests not being executed. Downgrading to 2.0.72 worked.

OS: Win10 VSCode: 1.49.0 Shell: PowerShell Core 7.0.3 PHP: 7.3.18 PHPUnit: 9.3.10

tyler36 commented 4 years ago

Confirming issue fixed after update to 2.0.76. 🎉

Thank you for the update.