-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: detect tests via annotation #1
Comments
That looks to be a problem with your functionRegex. The function regex currently only searches a single line, so there is no regex that will recognize a function is a test function based on the annotation. If there is no consistent naming for test functions I would recommend using the following functionRegex. "phpunit.functionRegex": "\\s*(public\\s+){0,1}function", This will recognize all functions that start with any number of spaces followed by public function or function as test functions. Also, if you do not want the tests within your vendor folder showing up, you would have to change the glob pattern to exclude that folder. The I typically use the site regex101.com to test out different regular expressions. If you are still not seeing those tests let me know and I will look further into this issue. |
In version "phpunit.functionRegex": "\\/\\*.*?@test.*?\\*\\/\\s*?(public\\s+){0,1}function",
"phpunit.multilineFunctionRegex": true, |
Thank you for the update. I tried "phpunit.discoverAllTests": true,
"phpunit.folderPattern": "./tests/**/*Test.php",
"phpunit.fileRegex": ".*(Test).php",
"phpunit.functionRegex": "\\/\\*.*?@test.*?\\*\\/\\s*?(public\\s+){0,1}function",
"phpunit.multilineFunctionRegex": true, The "testing" icon does not appear until I open a test file. Then, icon appears and I see a list of the file test. This feels like the "phpunit.discoverAllTests" isn't working for my setup. |
I currently have the extension only initializing once a php file is opened, I will make an update to change that so the tests are recognized when VSCode is opened. However, as it currently works you should see all your tests once any php file is opened, so if you are not seeing that functionality it probably means you need to change the "phpunit.folderPattern": "**/tests/**/*Test.php" or possibly "phpunit.folderPattern": "**/tests/**/*.php" The folderPatter setting is used in combination with the fileRegex when finding tests, which is why you probably would not need to be specific about the ending and could use *.php instead of *Test.php. |
On second thought, if the files are showing up in your view explorer, but just the individual tests are not showing up then that might be a problem with parsing unopened files using the |
Thanks for the follow-up. Tests show up after I open a test file, or if I have previously opened a file. It sounds to me like it might be in |
I have released version I took a quick look at the code and do not see a reason that the "phpunit.discoverAllTests": true,
"phpunit.folderPattern": "**/tests/**/*.php",
"phpunit.fileRegex": "^(?!.*vendor).*Test.php$", // if you want to exclude files with "vendor" in the path
// "phpunit.fileRegex": ".*(Test).php" // if you want to include all test files
"phpunit.functionRegex": "\\/\\*.*?@test.*?\\*\\/\\s*?(public\\s+){0,1}function",
"phpunit.multilineFunctionRegex": true, |
Have you tried changing the |
Just tried the following, reloading the extension after change: "phpunit.folderPattern": "**/*Test.php", "phpunit.folderPattern": "**/tests/**/*.php", "phpunit.folderPattern": "**/*.php", "phpunit.folderPattern": "./**/*.php", |
Hmm, that is unfortunate. When you say you reloaded the extension do you mean reloaded the VSCode window, or exited out of VSCode? Simply disabling and re-enabling the extension might not be enough. I should probably add a reload window prompt whenever the But assuming you did reload the window then I am out of ideas. Given that you are able to see, and I assume run, the tests once you open a test file that means the "phpunit.folderPattern": "./tests/*Test.php" would not work, but using "phpunit.folderPattern": "**/*.php" should effectively watch all the php files in the workspace. Also, knowing that those other values are working that should mean the test files would get added to the test explorer. I have not been able to recreate this problem on my end so I am stumped as to the problem here. You mentioned in your first comment that once you opened a test file then all the tests are populated, do you have any idea why this stopped happening? I do not think any of the updates I made would have changed that. |
OK ... I think my problem was with VSCode settings/cache somewhere.
{
"phpunit.discoverAllTests": true,
"phpunit.folderPattern": "**/tests/**/*.php",
"phpunit.fileRegex": "^(?!.*vendor).*Test.php$", // if you want to exclude files with "vendor" in the path
// "phpunit.fileRegex": ".*(Test).php" // if you want to include all test files
"phpunit.functionRegex": "\\/\\*.*?@test.*?\\*\\/\\s*?(public\\s+){0,1}function",
"phpunit.multilineFunctionRegex": true
} And everything worked; saw icon withonly my tests (no vendor tests). Next, replaced my "normal" Vscode install with the above settings and same old "problems". I completely uninstalled VScode, and renamed my Thank you for taking the time to help debug the problem. I really appreciate it. |
More feedback. While I had it working on Win10, when I tried to access a WSL projects, it failed. I tried deleting the I had "Setting Sync" & VSCode sync turned on so perhaps there was conflict between these (which might have caused the original problem too). |
Interesting...thanks for the feedback. And glad you were able to figure it out and get everything working! Once you have some time to try out the extension I'd appreciate if you could leave a review on the marketplace. And if you have any other problems or think something could be improved you can always create another issue. |
Thank you for the extension.
I've been looking for a replacement for "recca0120.vscode-phpunit" for a while and came across this one.
I'm havign trouble getting this extension to recognise my tests.
Basically,
./tests
Test.php
When I install this extension, I can't see the test icon unless I open a test file. At that point, it populates with every test in my workspace, including
vendor
.I think my tests are not displaying because this extension assumes a "functionRegex", and can't detect
@test
annotations, but I'm not really sure. Regex is a crazy powerful, but I still struggle writing & parsing it.My current config is the following.
What am I doing wrong?
PHPunit Extended with TestExplorter:
0.2.5
Test Explorer:
2.21.1
Test Adapter:
0.1.4
Vscode:
1.62.3
OS: Remote: WSL
0.58.5
, Ubuntu via Win10 WSL2The text was updated successfully, but these errors were encountered: