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 · 17 comments
Open

Wrong call to phpunit when asking for test groups #8082

tenzap opened this issue Dec 22, 2024 · 17 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. ...

@tenzap
Copy link
Author

tenzap commented Dec 25, 2024

Sorry for misunderstanding.

For all use cases below, in the project properties / testing / testdirs, set the path to "/absolute/path/to/project/tests" dir.

Group A

This is the expected result for the branch nb24-issue8082 of https://github.com/tenzap/phpunit-simple-example/tree/nb24-issue8082

Case A1

Check only

  • use Custom PHPUnit Script (/absolute/path/to/project/vendor/bin/phpunit)
  • Test project using just phpunit command

Run tests (ALT+F6)

Doesn't work as expected: ie. phpunit is invoked without the testdir argument which is correct and since there is no check for 'use XML configuration', no configuration is added to the command line which is correct. However, phpunit prints the usage. This is because it is likely that it is not invoked from the root dir of the project.

Expected behavior: phpunit should be invoked from the root dir of the project. With this changed, phpunit will be able to run the tests.

Case A2

Check only

  • use XML configuration (/absolute/path/to/project/phpunit.xml)
  • use Custom PHPUnit Script (/absolute/path/to/project/vendor/bin/phpunit)
  • Test project using just phpunit command

Run tests (ALT+F6)

Works as expected: ie. phpunit is invoked without with the testdir argument and phpunit runs the test according to xml file.

Case A3

Check only

  • use XML configuration (/absolute/path/to/project/phpunit.xml)
  • use Custom PHPUnit Script (/absolute/path/to/project/vendor/bin/phpunit)
  • Test project using just phpunit command
  • Ask for test groups before running tests

Run tests (ALT+F6)

Doesn't work as expected: ie. netbeans invokes phpunit with the "." argument.

Expected behavior: It should invoke phpunit without the "." dir

Case A4

Check only

  • use Custom PHPUnit Script (/absolute/path/to/project/vendor/bin/phpunit)
  • Test project using just phpunit command
  • Ask for test groups before running tests

Run tests (ALT+F6)

Doesn't work as expected: ie. netbeans invokes phpunit with the "." argument.

Expected behavior: It should invoke phpunit without the testdir argument. And since there is not check for 'use XML configuration', no configuration is added to the command line which is correct. Moreover, phpunit should be invoked from the root dir of the project (I can't check if this is the case, but I think it is already the case)

Group B

This is the expected result for the branch nb24-issue8082-caseB of https://github.com/tenzap/phpunit-simple-example/tree/nb24-issue8082-caseB. The checkboxes to tick are like the 4 use cases above, except that we always keep Test project using just phpunit command unchecked.

Case B1

Check only

  • use Custom PHPUnit Script (/absolute/path/to/project/vendor/bin/phpunit)

Run tests (ALT+F6)

Works as expected: ie. phpunit is invoked with the testdir argument which is correct and since there is no check for 'use XML configuration', no configuration is added to the command line which is correct.

Case B2

Check only

  • use XML configuration (/absolute/path/to/project/phpunit.xml)
  • use Custom PHPUnit Script (/absolute/path/to/project/vendor/bin/phpunit)

Run tests (ALT+F6)

Works as expected: ie. phpunit is invoked with the testdir argument and phpunit runs the test according to xml file.

Case B3

Check only

  • use XML configuration (/absolute/path/to/project/phpunit.xml)
  • use Custom PHPUnit Script (/absolute/path/to/project/vendor/bin/phpunit)
  • Ask for test groups before running tests

Run tests (ALT+F6)

Doesn't work as expected: ie. netbeans invokes phpunit with the "." argument.

Expected behavior: It should invoke phpunit with the testdir argument as set in the project properties / testing / testdirs, ie "/absolute/path/to/project/tests" dir.

Case B4

Check only

  • use Custom PHPUnit Script (/absolute/path/to/project/vendor/bin/phpunit)
  • Ask for test groups before running tests

Run tests (ALT+F6)

Doesn't work as expected: ie. netbeans invokes phpunit with the "." argument. While it lists the groups in netbeans, I think the behavior could be different to be more consistent with the behavior when "use xml configuration" is set.

Expected behavior: It should invoke phpunit with the testdir argument. And since there is no check of 'use XML configuration', no configuration is added to the command line which is correct. Moreover, phpunit should be invoked from the root dir of the project (I can't check if this is the case, but I think it is already the case).

Group A & B

So in all cases:

  • if "Test project using just phpunit command" is ticked, the testdir or "." (in case of --list-groups) should never be appended. If it is unticked, it should always add the testdir (also in case of --list-group) to the phpunit invocation.
  • phpunit should be invoked from the root dir of the project in all cases

Hopefully I haven't made mistakes or misunderstood the way phpunit works.

@junichi11
Copy link
Member

@tenzap Thanks!

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