Skip to content

Commit e54c415

Browse files
committed
Add test helper for warnings
1 parent 70b74e1 commit e54c415

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
@@ -159,12 +159,17 @@ final public static function provideInvalidStringValues(): array
159159
}
160160

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

165170
set_error_handler(function ($errno, $errstr) use (&$errors): void {
166171
$errors[] = $errstr;
167-
}, E_USER_DEPRECATED);
172+
}, $levels);
168173

169174
try {
170175
call_user_func($execution);

0 commit comments

Comments
 (0)