2

using version 8.1.6, and Given the following phpunit.xml :

<phpunit bootstrap="vendor/autoload.php">
  <testsuites>
    <testsuite name="SlimSkeleton">
      <directory>tests</directory>
      <exclude>./tests/Functional/BaseTestCase.php</exclude>
    </testsuite>
  </testsuites>
</phpunit>

And the following directory structure :

  • ./tests/Functional/serviceA/...
  • ./tests/Functional/BaseTestCase.php

I keep getting the following output :

...
1) Warning
No tests found in class "Tests\Functional\BaseTestCase".
...

I run the suitr via a scripts command in composer.json :

{
    ...
    "scripts": {
       "test": "phpunit"
      }
}

Is it expected ? Is there a way to silence this warning ?

Ben
  • 5,030
  • 6
  • 53
  • 94
  • what is exactly the PHP Unit version you use? – Jimmix Jun 02 '19 at 23:11
  • @Jimmix added in the original post (8.1.6) – Ben Jun 02 '19 at 23:50
  • 1
    in which part of the dir struct is localed the file `phpunit.xml`? have you tried also with `./tests` ? – Matteo Jun 03 '19 at 08:07
  • At the dame level as the tests folder – Ben Jun 03 '19 at 16:33
  • How do you invoke the test-runner? How do you ensure you execute *that* testsuite? - maybe exclude works for directory paths only? – hakre Jun 03 '19 at 19:24
  • 1
    Have you tried making `BaseTestCase` an `abstract` class? – ceejayoz Jun 03 '19 at 19:32
  • @hakre i've added the info about how i run. I just want to know whats the way to exclude a file from the runner, is that so hard ? Isnt there a single way to do it correctly? – Ben Jun 03 '19 at 19:34
  • @ceejayoz how would you do so ? Is doing so solves the problem ? I'm so surprised to receive question - it sounds like there's no identified way to do i correctly – Ben Jun 03 '19 at 19:36
  • @Ben You just add `abstract` to the class definition. See Laravel's, for example: https://github.com/laravel/laravel/blob/master/tests/TestCase.php – ceejayoz Jun 03 '19 at 20:05
  • @Ben: Just checked in a different test-suite w/ ``: It does not operate on file-path but only on directory-path. Also it can not be the same path as the `` entry. HTH. /e: And well this was hard for me back in 2011: https://stackoverflow.com/q/5934347/367456 - I think this is also similar to what @ceejayoz pointed to. – hakre Jun 03 '19 at 20:11

1 Answers1

1

phpunit by default finds *Test.php, so even without <exclude> in phpunit.xml it would ignore BaseTestCase.php by running composer test.

Using tests instead of tests/EmailTest would instruct the PHPUnit command-line test runner to execute all tests found declared in *Test.php sourcecode files in the tests directory.

https://phpunit.de/getting-started/phpunit-8.html

I see "No tests found" warning if I specify command-line argument like the below. But this is not the intended usage of BaseTestCase.php from Slim-Skelton.

$ composer test tests/Functional/BaseTestCase.php
> phpunit 'tests/Functional/BaseTestCase.php'
PHPUnit 8.1.6 by Sebastian Bergmann and contributors.

W                                                                   1 / 1 (100%)

Time: 21 ms, Memory: 4.00 MB

There was 1 warning:

1) Warning
No tests found in class "Tests\Functional\BaseTestCase".

WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.
Nobu
  • 9,965
  • 4
  • 40
  • 47