Skip to content

Commit 2734c0b

Browse files
committed
Add test helper for warnings
1 parent 0d9ce99 commit 2734c0b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

tests/Model/CodecCursorFunctionalTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use const E_DEPRECATED;
1515
use const E_USER_DEPRECATED;
16+
use const E_USER_WARNING;
1617

1718
class CodecCursorFunctionalTest extends FunctionalTestCase
1819
{
@@ -30,10 +31,7 @@ public function testSetTypeMap(): void
3031

3132
$codecCursor = CodecCursor::fromCursor($cursor, $this->createMock(DocumentCodec::class));
3233

33-
$this->expectWarning();
34-
$this->expectExceptionMessage('Discarding type map for MongoDB\Model\CodecCursor::setTypeMap');
35-
36-
$codecCursor->setTypeMap(['root' => 'array']);
34+
$this->assertError(E_USER_WARNING, fn () => $codecCursor->setTypeMap(['root' => 'array']));
3735
}
3836

3937
public function testGetIdReturnTypeWithoutArgument(): void

tests/TestCase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,17 @@ final public static function provideInvalidStringValues(): array
160160
}
161161

162162
protected function assertDeprecated(callable $execution)
163+
{
164+
$this->assertError(E_USER_DEPRECATED | E_DEPRECATED, $execution);
165+
}
166+
167+
protected function assertError(int $levels, callable $execution): void
163168
{
164169
$errors = [];
165170

166171
set_error_handler(function ($errno, $errstr) use (&$errors): void {
167172
$errors[] = $errstr;
168-
}, E_USER_DEPRECATED | E_DEPRECATED);
173+
}, $levels);
169174

170175
try {
171176
$result = call_user_func($execution);

0 commit comments

Comments
 (0)