Skip to content

Commit 57a61cf

Browse files
Do not emit event for tests from PHPUnit's own test suite
1 parent cb23234 commit 57a61cf

File tree

7 files changed

+24
-21
lines changed

7 files changed

+24
-21
lines changed

src/Framework/TestCase.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
use function set_exception_handler;
5151
use function sprintf;
5252
use function str_contains;
53+
use function str_starts_with;
5354
use function stream_get_contents;
5455
use function stream_get_meta_data;
5556
use function tmpfile;
@@ -1398,14 +1399,16 @@ private function verifyMockObjects(): void
13981399
{
13991400
foreach ($this->mockObjects as $mockObject) {
14001401
if (!$mockObject['mockObject']->__phpunit_hasMatchers()) {
1401-
Event\Facade::emitter()->testTriggeredPhpunitNotice(
1402-
$this->testValueObjectForEvents,
1403-
sprintf(
1404-
'No expectations were configured for the mock object for %s. ' .
1405-
'You should refactor your test code and use a test stub instead.',
1406-
$mockObject['type'],
1407-
),
1408-
);
1402+
if (!str_starts_with($this::class, 'PHPUnit\\')) {
1403+
Event\Facade::emitter()->testTriggeredPhpunitNotice(
1404+
$this->testValueObjectForEvents,
1405+
sprintf(
1406+
'No expectations were configured for the mock object for %s. ' .
1407+
'You should refactor your test code and use a test stub instead.',
1408+
$mockObject['type'],
1409+
),
1410+
);
1411+
}
14091412

14101413
continue;
14111414
}

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)