Skip to content

Commit

Permalink
Closes #4979
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 10, 2023
1 parent 3b8daff commit 5ff9aa4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
22 changes: 17 additions & 5 deletions src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use PHPUnit\Metadata\Api\HookMethods;
use PHPUnit\Metadata\Api\Requirements;
use PHPUnit\Metadata\MetadataCollection;
use PHPUnit\Runner\Exception as RunnerException;
use PHPUnit\Runner\Filter\Factory;
use PHPUnit\Runner\PhptTestCase;
use PHPUnit\Runner\TestSuiteLoader;
Expand Down Expand Up @@ -236,20 +237,31 @@ public function addTestSuite(ReflectionClass $testClass): void
* added, a <code>PHPUnit\Framework\WarningTestCase</code> will be created instead,
* leaving the current test run untouched.
*
* @throws \PHPUnit\Runner\Exception
* @throws Exception
*/
public function addTestFile(string $filename): void
{
if (is_file($filename) && str_ends_with($filename, '.phpt')) {
$this->addTest(new PhptTestCase($filename));
try {
$this->addTest(new PhptTestCase($filename));
} catch (RunnerException $e) {
Event\Facade::emitter()->testRunnerTriggeredWarning(
$e->getMessage()
);
}

return;
}

$this->addTestSuite(
(new TestSuiteLoader)->load($filename)
);
try {
$this->addTestSuite(
(new TestSuiteLoader)->load($filename)
);
} catch (RunnerException $e) {
Event\Facade::emitter()->testRunnerTriggeredWarning(
$e->getMessage()
);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
--TEST--
phpunit ../../../_files/abstract/with-test-suffix
--SKIPIF--
<?php declare(strict_types=1);
print 'skip: https://github.com/sebastianbergmann/phpunit/issues/4979';
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
Expand All @@ -12,3 +9,17 @@ $_SERVER['argv'][] = __DIR__ . '/../../../_files/abstract/with-test-suffix';
require_once __DIR__ . '/../../../bootstrap.php';
PHPUnit\TextUI\Application::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

. 1 / 1 (100%)

Time: %s, Memory: %s

There was 1 PHPUnit warning:

1) Class PHPUnit\TestFixture\AbstractTest declared in %sAbstractTest.php is abstract

WARNINGS!
Tests: 1, Assertions: 1, Warnings: 1.
17 changes: 10 additions & 7 deletions tests/end-to-end/generic/filename-matches-class-name.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ $_SERVER['argv'][] = __DIR__ . '/../../_files/OneClassPerFile/wrongClassName/';

require_once __DIR__ . '/../../bootstrap.php';

try {
PHPUnit\TextUI\Application::main();
} catch (\Exception $e) {
echo $e->getMessage();
}
?>
PHPUnit\TextUI\Application::main();
--EXPECTF--
Class WrongClassNameTest cannot be found in %sWrongClassNameTest.php
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

There was 1 PHPUnit warning:

1) Class WrongClassNameTest cannot be found in %sWrongClassNameTest.php

No tests executed!

0 comments on commit 5ff9aa4

Please sign in to comment.