Skip to content

Commit 33d931d

Browse files
Merge branch '12.5'
* 12.5: Do not emit event for tests from PHPUnit's own test suite Handle PhpunitNoticeTriggered event
2 parents dad1b4b + 57a61cf commit 33d931d

File tree

9 files changed

+56
-21
lines changed

9 files changed

+56
-21
lines changed

src/Framework/TestCase.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
use function set_exception_handler;
5252
use function sprintf;
5353
use function str_contains;
54+
use function str_starts_with;
5455
use function stream_get_contents;
5556
use function stream_get_meta_data;
5657
use function tmpfile;
@@ -1384,14 +1385,16 @@ private function verifyMockObjects(): void
13841385
{
13851386
foreach ($this->mockObjects as $mockObject) {
13861387
if (!$mockObject['mockObject']->__phpunit_hasMatchers()) {
1387-
Event\Facade::emitter()->testTriggeredPhpunitNotice(
1388-
$this->testValueObjectForEvents,
1389-
sprintf(
1390-
'No expectations were configured for the mock object for %s. ' .
1391-
'You should refactor your test code and use a test stub instead.',
1392-
$mockObject['type'],
1393-
),
1394-
);
1388+
if (!str_starts_with($this::class, 'PHPUnit\\')) {
1389+
Event\Facade::emitter()->testTriggeredPhpunitNotice(
1390+
$this->testValueObjectForEvents,
1391+
sprintf(
1392+
'No expectations were configured for the mock object for %s. ' .
1393+
'You should refactor your test code and use a test stub instead.',
1394+
$mockObject['type'],
1395+
),
1396+
);
1397+
}
13951398

13961399
continue;
13971400
}

src/TextUI/Output/Default/ProgressPrinter/ProgressPrinter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ public function testTriggeredPhpunitDeprecation(): void
188188
$this->updateTestStatus(TestStatus::deprecation());
189189
}
190190

191+
public function testTriggeredPhpunitNotice(): void
192+
{
193+
$this->updateTestStatus(TestStatus::notice());
194+
}
195+
191196
public function testConsideredRisky(): void
192197
{
193198
$this->updateTestStatus(TestStatus::risky());
@@ -316,6 +321,7 @@ private function registerSubscribers(Facade $facade): void
316321
new TestTriggeredPhpDeprecationSubscriber($this),
317322
new TestTriggeredPhpNoticeSubscriber($this),
318323
new TestTriggeredPhpunitDeprecationSubscriber($this),
324+
new TestTriggeredPhpunitNoticeSubscriber($this),
319325
new TestTriggeredPhpunitWarningSubscriber($this),
320326
new TestTriggeredPhpWarningSubscriber($this),
321327
new TestTriggeredWarningSubscriber($this),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TextUI\Output\Default\ProgressPrinter;
11+
12+
use PHPUnit\Event\Test\PhpunitNoticeTriggered;
13+
use PHPUnit\Event\Test\PhpunitNoticeTriggeredSubscriber;
14+
15+
/**
16+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
17+
*
18+
* @internal This class is not covered by the backward compatibility promise for PHPUnit
19+
*/
20+
final readonly class TestTriggeredPhpunitNoticeSubscriber extends Subscriber implements PhpunitNoticeTriggeredSubscriber
21+
{
22+
public function notify(PhpunitNoticeTriggered $event): void
23+
{
24+
$this->printer()->testTriggeredPhpunitNotice();
25+
}
26+
}

tests/end-to-end/event/_files/MockWithoutExpectationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
namespace PHPUnit\TestFixture\Event;
10+
namespace TestFixture\PHPUnit\Event;
1111

1212
use PHPUnit\Framework\TestCase;
13+
use PHPUnit\TestFixture\Event\Example;
1314

1415
final class MockWithoutExpectationTest extends TestCase
1516
{

tests/end-to-end/event/mock-object-without-expectation.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ Test Suite Loaded (1 test)
2121
Test Runner Started
2222
Test Suite Sorted
2323
Test Runner Execution Started (1 test)
24-
Test Suite Started (PHPUnit\TestFixture\Event\MockWithoutExpectationTest, 1 test)
25-
Test Preparation Started (PHPUnit\TestFixture\Event\MockWithoutExpectationTest::testSuccess)
26-
Test Prepared (PHPUnit\TestFixture\Event\MockWithoutExpectationTest::testSuccess)
24+
Test Suite Started (TestFixture\PHPUnit\Event\MockWithoutExpectationTest, 1 test)
25+
Test Preparation Started (TestFixture\PHPUnit\Event\MockWithoutExpectationTest::testSuccess)
26+
Test Prepared (TestFixture\PHPUnit\Event\MockWithoutExpectationTest::testSuccess)
2727
Mock Object Created (PHPUnit\TestFixture\Event\Example)
28-
Test Triggered PHPUnit Notice (PHPUnit\TestFixture\Event\MockWithoutExpectationTest::testSuccess)
28+
Test Triggered PHPUnit Notice (TestFixture\PHPUnit\Event\MockWithoutExpectationTest::testSuccess)
2929
No expectations were configured for the mock object for PHPUnit\TestFixture\Event\Example. You should refactor your test code and use a test stub instead.
30-
Test Passed (PHPUnit\TestFixture\Event\MockWithoutExpectationTest::testSuccess)
31-
Test Finished (PHPUnit\TestFixture\Event\MockWithoutExpectationTest::testSuccess)
32-
Test Suite Finished (PHPUnit\TestFixture\Event\MockWithoutExpectationTest, 1 test)
30+
Test Passed (TestFixture\PHPUnit\Event\MockWithoutExpectationTest::testSuccess)
31+
Test Finished (TestFixture\PHPUnit\Event\MockWithoutExpectationTest::testSuccess)
32+
Test Suite Finished (TestFixture\PHPUnit\Event\MockWithoutExpectationTest, 1 test)
3333
Test Runner Execution Finished
3434
Test Runner Finished
3535
PHPUnit Finished (Shell Exit Code: 0)

tests/end-to-end/generic/exception-in-mock-destructor.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ Exception: Some exception.
2525
%sExceptionInMockDestructor.php:%d
2626

2727
ERRORS!
28-
Tests: 1, Assertions: 1, Errors: 1, PHPUnit Notices: 1.
28+
Tests: 1, Assertions: 1, Errors: 1.

tests/end-to-end/logging/teamcity/teamcity-directory.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,4 @@ This test did not perform any assertions
133133
%s%eStatusTest.php:%d
134134

135135
ERRORS!
136-
Tests: 18, Assertions: 6, Errors: 6, Failures: 2, PHPUnit Notices: 1, Skipped: 3, Incomplete: 2, Risky: 2.
136+
Tests: 18, Assertions: 6, Errors: 6, Failures: 2, Skipped: 3, Incomplete: 2, Risky: 2.

tests/end-to-end/logging/teamcity/teamcity-file.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@ This test did not perform any assertions
9797
%s%eStatusTest.php:%d
9898

9999
ERRORS!
100-
Tests: 13, Assertions: 4, Errors: 2, Failures: 2, PHPUnit Notices: 1, Skipped: 3, Incomplete: 2, Risky: 2.
100+
Tests: 13, Assertions: 4, Errors: 2, Failures: 2, Skipped: 3, Incomplete: 2, Risky: 2.

tests/end-to-end/regression/5891.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ Runtime: %s
1717

1818
Time: %s, Memory: %s MB
1919

20-
OK, but there were issues!
21-
Tests: 2, Assertions: 4, PHPUnit Notices: 2.
20+
OK (2 tests, 4 assertions)

0 commit comments

Comments
 (0)