Skip to content

Commit d1c6dcd

Browse files
Improve message
1 parent 0ae4df9 commit d1c6dcd

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

ChangeLog-12.5.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 12.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [12.5.3] - 2025-MM-DD
6+
7+
### Changed
8+
9+
* The message emitted when a test method creates a mock object but does not configure any expectations for it has been improved
10+
511
## [12.5.2] - 2025-12-08
612

713
### Added
@@ -26,6 +32,7 @@ All notable changes of the PHPUnit 12.5 release series are documented in this fi
2632
* [#6380](https://github.com/sebastianbergmann/phpunit/pull/6380): Allow `Throwable` in `expectExceptionObject()`
2733
* A PHPUnit notice is now emitted for test methods that create a mock object but do not configure an expectation for it
2834

35+
[12.5.3]: https://github.com/sebastianbergmann/phpunit/compare/12.5.2...12.5
2936
[12.5.2]: https://github.com/sebastianbergmann/phpunit/compare/12.5.1...12.5.2
3037
[12.5.1]: https://github.com/sebastianbergmann/phpunit/compare/12.5.0...12.5.1
3138
[12.5.0]: https://github.com/sebastianbergmann/phpunit/compare/12.4.5...12.5.0

src/Framework/TestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,8 @@ private function verifyMockObjects(): void
14081408
$this->testValueObjectForEvents,
14091409
sprintf(
14101410
'No expectations were configured for the mock object for %s. ' .
1411-
'You should refactor your test code and use a test stub instead.',
1411+
'Consider refactoring your test code to use a test stub instead. ' .
1412+
'The #[AllowMockObjectsWithoutExpectations] attribute can be used to opt out of this check.',
14121413
$mockObject['type'],
14131414
),
14141415
);

tests/end-to-end/event/mock-object-created-with-MockBuilder-without-expectations.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Test Suite Started (TestFixture\PHPUnit\Event\MockBuilderWithoutExpectationsTest
2525
Test Preparation Started (TestFixture\PHPUnit\Event\MockBuilderWithoutExpectationsTest::testOne)
2626
Test Prepared (TestFixture\PHPUnit\Event\MockBuilderWithoutExpectationsTest::testOne)
2727
Test Triggered PHPUnit Notice (TestFixture\PHPUnit\Event\MockBuilderWithoutExpectationsTest::testOne)
28-
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.
28+
No expectations were configured for the mock object for PHPUnit\TestFixture\Event\Example. Consider refactoring your test code to use a test stub instead. The #[AllowMockObjectsWithoutExpectations] attribute can be used to opt out of this check.
2929
Test Passed (TestFixture\PHPUnit\Event\MockBuilderWithoutExpectationsTest::testOne)
3030
Test Finished (TestFixture\PHPUnit\Event\MockBuilderWithoutExpectationsTest::testOne)
3131
Test Suite Finished (TestFixture\PHPUnit\Event\MockBuilderWithoutExpectationsTest, 1 test)

tests/end-to-end/event/mock-object-created-with-createMock-without-expectations.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Test Preparation Started (TestFixture\PHPUnit\Event\CreateMockWithoutExpectation
2626
Test Prepared (TestFixture\PHPUnit\Event\CreateMockWithoutExpectationsTest::testOne)
2727
Mock Object Created (PHPUnit\TestFixture\Event\Example)
2828
Test Triggered PHPUnit Notice (TestFixture\PHPUnit\Event\CreateMockWithoutExpectationsTest::testOne)
29-
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.
29+
No expectations were configured for the mock object for PHPUnit\TestFixture\Event\Example. Consider refactoring your test code to use a test stub instead. The #[AllowMockObjectsWithoutExpectations] attribute can be used to opt out of this check.
3030
Test Passed (TestFixture\PHPUnit\Event\CreateMockWithoutExpectationsTest::testOne)
3131
Test Finished (TestFixture\PHPUnit\Event\CreateMockWithoutExpectationsTest::testOne)
3232
Test Suite Finished (TestFixture\PHPUnit\Event\CreateMockWithoutExpectationsTest, 1 test)

tests/end-to-end/event/mock-object-created-with-createPartialMock-without-expectations.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Test Preparation Started (TestFixture\PHPUnit\Event\CreatePartialMockWithoutExpe
2626
Test Prepared (TestFixture\PHPUnit\Event\CreatePartialMockWithoutExpectationsTest::testOne)
2727
Partial Mock Object Created (PHPUnit\TestFixture\Event\Example)
2828
Test Triggered PHPUnit Notice (TestFixture\PHPUnit\Event\CreatePartialMockWithoutExpectationsTest::testOne)
29-
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.
29+
No expectations were configured for the mock object for PHPUnit\TestFixture\Event\Example. Consider refactoring your test code to use a test stub instead. The #[AllowMockObjectsWithoutExpectations] attribute can be used to opt out of this check.
3030
Test Passed (TestFixture\PHPUnit\Event\CreatePartialMockWithoutExpectationsTest::testOne)
3131
Test Finished (TestFixture\PHPUnit\Event\CreatePartialMockWithoutExpectationsTest::testOne)
3232
Test Suite Finished (TestFixture\PHPUnit\Event\CreatePartialMockWithoutExpectationsTest, 1 test)

0 commit comments

Comments
 (0)