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

Exit with non-zero code if no file/directory to test was found #4519

Closed
mvorisek opened this issue Nov 15, 2020 · 6 comments
Closed

Exit with non-zero code if no file/directory to test was found #4519

mvorisek opened this issue Nov 15, 2020 · 6 comments
Labels
feature/test-runner CLI test runner type/enhancement A new idea that should be implemented

Comments

@mvorisek
Copy link
Contributor

mvorisek commented Nov 15, 2020

(opening as a feature request, even it looks like a bug to me)

This is a feature request to exit phpunit with non-zero status code if no file to test was found.

Currently, phpunit exits with zero status code which is dangerous, as tests passes even if data directory with tests is completely missing.

Example config (phpunit passes even if tests directory does not exist):

<phpunit bootstrap="vendor/autoload.php" colors="true">
    <testsuites>
        <testsuite name="tests">
            <directory>tests</directory>
        </testsuite>
    </testsuites>
</phpunit>
``
@mvorisek mvorisek added the type/enhancement A new idea that should be implemented label Nov 15, 2020
@sebastianbergmann
Copy link
Owner

Duplicate of #4493.

@sebastianbergmann sebastianbergmann added feature/test-runner CLI test runner type/bug Something is broken type/enhancement A new idea that should be implemented and removed type/enhancement A new idea that should be implemented type/bug Something is broken labels Nov 16, 2020
@mvorisek
Copy link
Contributor Author

mvorisek commented Dec 3, 2020

@sebastianbergmann can you please advise why I am getting the following error:

PHPUnit 9.5-dev by Sebastian Bergmann and contributors.
Runtime:       PHP 8.0.0
Configuration: prefix-phpunit.xml.dist
Call to undefined method Maha\PhpCiTestProject\Tests\ExampleTest::getAnnotations()
ERROR: Job failed: exit code 1

when I use dev phpunit downloaded by:

composer require 'phpunit/phpunit:dev-master#60890a4 as 9.5.0-alpha0' --ansi --prefer-dist --prefer-stable --no-progress --classmap-authoritative

I think this error must be in phpunit, tested with this minimalistic configuration and one simple test:

<phpunit bootstrap="vendor/autoload.php" colors="true">
    <testsuites>
        <testsuite name="tests">
            <directory>tests</directory>
        </testsuite>
    </testsuites>
    <listeners>
        <listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
    </listeners>
</phpunit>
<?php

declare(strict_types=1);

namespace Maha\PhpCiTestProject\Tests;

use Maha\PhpCiTestProject\Example;

class ExampleTest extends \PHPUnit\Framework\TestCase
{
    public function testBasic(): void
    {
        $this->assertTrue(1 === 1);
    }
}

thanks in advance.

PS: with 09ba0b8 commit it works, with 60890a4 (used above) it does not even CI here is green

@sebastianbergmann
Copy link
Owner

I would not call a setup that includes a PHPUnit extension (<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />) minimal.

@sebastianbergmann
Copy link
Owner

PHPUnit 9.4 has a TestCase::getAnnotations() method that is annotated with @internal This method is not covered by the backward compatibility promise for PHPUnit. This method no longer exists in what will be PHPUnit 9.5. @johnkary's SpeedTrapListener class uses this method when it should not.

@mvorisek
Copy link
Contributor Author

mvorisek commented Dec 3, 2020

thanks!

@johnkary
Copy link

Thank you @sebastianbergmann for explaining the fix. johnkary/phpunit-speedtrap listener has been updated to address this issue.

Thank you for your continued efforts on PHPUnit and within the PHP community :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-runner CLI test runner type/enhancement A new idea that should be implemented
Projects
None yet
Development

No branches or pull requests

3 participants