-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDmsAsserts.php
More file actions
42 lines (36 loc) · 970 Bytes
/
DmsAsserts.php
File metadata and controls
42 lines (36 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Dms\Common\Testing;
/**
* The common asserts used throughout the dms testing suite.
*
* @author Elliot Levin <elliotlevin@hotmail.com>
*/
trait DmsAsserts
{
/**
* @param callable $operation
* @param string $exception
* @param string $message
*
* @return \Throwable|null
* @throws \Throwable
*/
public function assertThrows(callable $operation, $exception = \Exception::class, $message = 'Failed asserting that the operation throws an exception')
{
$thrownException = true;
try {
$operation();
$thrownException = false;
} catch (\Throwable $e) {
if (strpos(get_class($e), 'PHPUnit_Framework') === 0) {
throw $e;
}
$this->assertInstanceOf($exception, $e);
return $e;
}
if (!$thrownException) {
$this->fail($message);
}
return null;
}
}