Skip to content
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

Wrong call to phpunit when asking for test groups #8082

Open
tenzap opened this issue Dec 22, 2024 · 15 comments
Open

Wrong call to phpunit when asking for test groups #8082

tenzap opened this issue Dec 22, 2024 · 15 comments
Labels
kind:bug Bug report or fix PHP [ci] enable extra PHP tests (php/php.editor)

Comments

@tenzap
Copy link

tenzap commented Dec 22, 2024

Apache NetBeans version

Apache NetBeans 24

What happened

The call to phpunit when asking for test groups isn't correct so that it reports that there is no group.

Updating the call would fix the issue.

Language / Project Type / NetBeans Component

PHP, testing with phpunit

How to reproduce

I setup a PHP project to run tests with PHPUnit
In the phpunit config (project properties / Testing / PHPUnit) I check "Ask for test groups before running tests".
I also have "test project using phpunit command only" set. As well as the XML file, and path to phpunit.

netbeans will invoke phpunit with

"/usr/bin/php" ".../vendor/bin/phpunit" "--colors" "--configuration" ".../application/tests/phpunit.xml" "--list-groups" "."

Output it

PHPUnit 10.5.40 by Sebastian Bergmann and contributors.

Available test group(s):
Done.

The part "--list-groups" "." should actually be "--list-groups" (ie. without the "." part).

When I run the command myself without the "." part), phpunit returns the list of groups, otherwise it doesn't.

"/usr/bin/php" ".../vendor/bin/phpunit" "--colors" "--configuration" ".../application/tests/phpunit.xml" "--list-groups"
PHPUnit 10.5.40 by Sebastian Bergmann and contributors.

Available test group(s):
 - default
 - html5

Did this work correctly in an earlier version?

No / Don't know

Operating System

Debian 12

JDK

Java: 17.0.13; OpenJDK 64-Bit Server VM 17.0.13+11-Debian-2deb12u1

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

No response

Are you willing to submit a pull request?

No

@tenzap tenzap added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Dec 22, 2024
@KacerCZ KacerCZ added the PHP [ci] enable extra PHP tests (php/php.editor) label Dec 22, 2024
@junichi11
Copy link
Member

@tenzap Can you provide an example project as a zip file to reproduce it?

@tenzap
Copy link
Author

tenzap commented Dec 23, 2024

See: https://github.com/tenzap/phpunit-simple-example/tree/nb24-issue8082
(branch nb24-issue8082)

Launching composer install should be sufficient to install phpunit 10.5

For the configuration:
image
image

It looks like if I tick "test project using just phpunit", it shouldn't add the . to the phpunit command.

Actually the . refers to the directory in which phpunit searches test files. For phpunit, if --test-suffix is not set, it defaults searching only for files having suffix Test.php,.phpt. However, in this project the suffix is _test.php, so the . wouldn't find the test files, and that would explain why no groups are found.

BTW, if I tick "use XML configuration", maybe netbeans shouldn't even append the test dir to any phpunit call? I don't know if this makes sense.

@junichi11
Copy link
Member

@tenzap Thanks for the example.

@junichi11
Copy link
Member

@tmysik Can we remove .? (Is there a problem?)

List<String> params = createParams(true);
addBootstrap(phpModule, params);
addConfiguration(phpModule, params);
params.add(LIST_GROUPS_PARAM);
// list test groups from the current workdir
params.add("."); // NOI18N
phpUnit.additionalParameters(params);

@junichi11 junichi11 removed the needs:triage Requires attention from one of the committers label Dec 24, 2024
@tmysik
Copy link
Member

tmysik commented Dec 24, 2024

@tmysik Can we remove .? (Is there a problem?)

List<String> params = createParams(true);
addBootstrap(phpModule, params);
addConfiguration(phpModule, params);
params.add(LIST_GROUPS_PARAM);
// list test groups from the current workdir
params.add("."); // NOI18N
phpUnit.additionalParameters(params);

@junichi11 I would guess so, if it works correctly without it. You know, this was implemented a very long time ago, so PHPUnit CLI could have changed several times already 🙂

@junichi11
Copy link
Member

@tmysik OK, I thought it may have a specific reason :)
Thank you, Tomas!

@tmysik
Copy link
Member

tmysik commented Dec 24, 2024

It was not working without it, definitely 😁 In ~2010 or so 😁

@tenzap
Copy link
Author

tenzap commented Dec 24, 2024

I think that if a XML config file is set or if we tick to use just phpunit, the dir should not be set,
Otherwise it should be set to the same dir as the one used when not ticking to use just phpunit.
The '.' just reflects the dir in which to search for tests (see phpunit command line options). If not set it would work according to XML config (either the default one, or the one set by '-c' argument) I suppose.

@junichi11
Copy link
Member

junichi11 commented Dec 25, 2024

It doesn't work without . if a config file is not set. So, I will fix it to not add . if a config file is set. Thanks!

@tenzap
Copy link
Author

tenzap commented Dec 25, 2024

Why do you use '.' instead of the test dirs? Wouldn't it be more correct to run the command with the test dir as set in the 'properties/testing' window of the project (which is the value used in the phounit command when not ticking 'use just phpunit' option)?

@tmysik
Copy link
Member

tmysik commented Dec 25, 2024

Maybe, because you can run it on a directory underneath the test one? In such a case, you need the actual directory. Just guessing, I can be wrong, of course.

@tenzap
Copy link
Author

tenzap commented Dec 25, 2024

For example, with phpunit 10.5

$ vendor/bin/phpunit --help
PHPUnit 10.5.40 by Sebastian Bergmann and contributors.

Usage:
  phpunit [options] <directory|file> ...

From what I understand in source code of phpunit 10.5

So netbeans could work like this:

  • if user checks/ticks Test project using just phpunit command, don't append the <directory|file>, the inclusions of the dirs would be determined as per the XML config file if set, or as per the phpunit default. Otherwise, <directory|file> should be the director(y/ies) set in the "project properties / testing / test dirs" window of netbeans.

  • if user checks/ticks Ask for test groups before running tests, it should append the <directory|file> depending on whether Test project using just phpunit command is ticked. That's because one would want the list of groups for the tests that phpunit would run based on the way it is configured in netbeans.

@junichi11
Copy link
Member

  • if user checks/ticks Test project using just phpunit command, don't append the <directory|file>, the inclusions of the dirs would be determined as per the XML config file if set, or as per the phpunit default. Otherwise, <directory|file> should be the director(y/ies) set in the "project properties / testing / test dirs" window of netbeans.
  • if user checks/ticks Ask for test groups before running tests, it should append the <directory|file> depending on whether Test project using just phpunit command is ticked. That's because one would want the list of groups for the tests that phpunit would run based on the way it is configured in netbeans.

Can you provide examples(work/don't work) with exact steps to reproduce them?

@tenzap
Copy link
Author

tenzap commented Dec 25, 2024

isn't the sample I provided sufficient?
It's just about checking/unchecking the boxes in netbeans.
BTW I'm new to phpunit, so that's just supposition and would probably be above my skills to do this in a time-efficient manner.

@junichi11
Copy link
Member

Well, Misunderstandings often occur because I'm not you...(We can't often reproduce issues.)
So, please write exact steps.
e.g.

Works fine:

  1. check ...
  2. ...
  3. Run the test file
  4. ...

Don't work:

  1. check ...
  2. ...
  3. ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Bug report or fix PHP [ci] enable extra PHP tests (php/php.editor)
Projects
None yet
Development

No branches or pull requests

4 participants