Closed junichi11 closed 1 year ago
The suite class file is checked whether it is a subclass of TestCase
:
https://github.com/sebastianbergmann/phpunit/blob/da707f3748773fbffd20289ae039e5e667d6b3a6/src/Runner/TestSuiteLoader.php#L42-L80
@tmysik What do you think? Any ideas?
Overall looks good to me. Here are my notes:
Thanks!
- cannot we use the PHPUnit 10 way also for older versions of PHPUnit? Maybe we could avoid the PHPUnit version selection at all?
Maybe, PHPUnit 9 works the same way (for a single file and directory). However, I'm not sure about the others...
- cannot we detect what version of PHPUnit is used? I mean, some cheap way, like existence of some file inside PHPUnit directory (not so nice but could work)
- cannot we improve error message so user knows what to do if the running of the tests does not work? Something like "Verify PHPUnit version in the Project Properties dialog"
I'll try thinking whether we can run unit test without selecting the version :) Thanks!
@tmysik We can detect the version via phpunit --version
. What do you think?
I have no ideas about multiple files yet...
@junichi11 The ideal solution, of course 👍
@junichi11 Looks good to me. However, we still need to solve situation when several files should be tested (e.g. user selects more files, or re-run the failed tests).
@tmysik
However, we still need to solve situation when several files should be tested (e.g. user selects more files, or re-run the failed tests).
Yes. I'll submit that problem as a new issue after this is merged. (I have no ideas although I investigated a bit...) Thank you for your review!
@junichi11 You are welcome!
I'll click the "Ready for review" button to merge this after CI passes. (This PR is merged by the release team.)
I tried to find way how to pass multiple files to PHPUnit, but there is no easy way.
Possible solution could be inspired by https://github.com/infection/infection.
It manipulates XML configuration for PHPUnit to suit its needs and creates temporary XML file.
This file is then passed to PHPUnit with -c
/--configuration
parameter.
See
Proposal
--configuration
and --testsuite
(https://docs.phpunit.de/en/10.1/textui.html) to test selected filesWhat do you think?
@KacerCZ
Thanks for looking into it! I was thinking about this solution also for the original solution (instead of NetBeansSuite.php
), however, it cannot work in cases when the user already has any existing PHPUnit configuration. Or am I missing something?
cc @junichi11
@KacerCZ
Let me improve my comment - I meant, can we always "extend" properly any existing configuration provided by the user? I am not so sure...
Existing configuration file must be copied to temporary file and modified - add test suite and update relative paths.
Configuration file can be configured in NetBeans or PHPUnit is looking for phpunit.xml
, phpunit.dist.xml
or phpunit.xml.dist
in working directory (root of project).
Cannot the existing configuration contain some suite already? I mean, can we always update it? Sorry if it is clear and my questions are unnecessary 🙈
@tmysik No need to apologize. Configuration file can contain one or more suites already defined. Idea is to add new test suite definition with and run this new suite.
Name of the suite could be something like "NetBeansTempSuite" with MD5 hash created from pathnames passed from Netbeans to prevent name collision with already existing suite.
Ha, if we can add a suite, then it seems to me to be the best way to go. Thanks for clarification!
Thanks for investigating it. I'll submit that problem as a new issue later.
I noticed that only one file is run with also PHPUnit 9 when we select several files. (I assumed that we can do it, sorry.)
Am I wrong something?
Rerun failed: tests are run with --filter
param
@junichi11
I can see 2 files were run, no?
@tmysik I should have written what I ran about that image, sorry. I selected the directory to show failed results for 2 files. I'm not sure how to run the selected 2 files actually. So, I've looked into it a bit.
It seems that the first item is returned when we select several files.
Uff :) Sorry, it has been a long time... Cannot we call filesForContextOrSelectedNodes()
? But maybe the current behavior is "good enough" and running tests in a folder is what users do? Anyway, thanks for looking into it.
Cannot we call
filesForContextOrSelectedNodes()
?
We should be able to do it. Then, we have to fix getTestRunInfoForFile()
or add getTestRunInfoForFiles()
.
But maybe the current behavior is "good enough"
Yes, I also think so :)
and running tests in a folder is what users do?
I'm not sure... but maybe, usage is the following via CLI, so users didn't report anything about running several test files, I guess.
Usage:
phpunit [options] UnitTest.php
phpunit [options] <directory>
It doesn't seem a big problem for users (I think we need not hurry) because there is no report from users for a long time. At least, PHPUnit 10 should work fine with this PR if there are no wrong fixes in my changes :)
I totally agree, not a big problem definitely.
BTW one more use-case is, if I remember it correctly 🙂, to rerun only failed tests. But that cannot work even now so all fine 👍 Let's create a ticket for it and merge this PR if there are no objections.
Thanks!
@tmysik I'll do that later :) This PR will be merged by the release team because I would like to include this in NB18. (We must not do it.) : https://lists.apache.org/thread/s3hnjtmr6t7dkyq1ofn4hdqmd0qh2d11 Thank you!
This PR will be merged by the release team because I would like to include this in NB18.
Don't worry, I've been following the conversation! :smile:
I know it's been moved out of draft, but wasn't 100% sure from the ongoing conversation if it is ready to merge. Please confirm, and I'll merge by tomorrow in time for 18-rc2.
@neilcsmith-net Thank you!
Created the issue: https://github.com/apache/netbeans/issues/5880
PhpUnitVersion
NetBeansSuite.php
with PHPUnit 10 becausesuite()
method is invoked no longer and we have to extendTestCase