/
Assert.exception.phpt
56 lines (43 loc) 路 1.6 KB
/
Assert.exception.phpt
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
$e = Assert::exception(function () {
throw new Exception;
}, Exception::class);
Assert::true($e instanceof Exception);
Assert::exception(function () {
throw new Exception('Text 123');
}, Exception::class, 'Text %d%');
Assert::exception(function () {
eval('*');
}, Error::class, 'syntax error%a%');
Assert::exception(function () {
Assert::exception(function () {
}, Exception::class);
}, Tester\AssertException::class, 'Exception was expected, but none was thrown');
$e = Assert::exception(function () use (&$inner) {
Assert::exception(function () use (&$inner) {
throw $inner = new Exception('message');
}, 'UnknownException');
}, Tester\AssertException::class, 'UnknownException was expected but got Exception (message)');
Assert::same($inner, $e->getPrevious());
$e = Assert::exception(function () {
Assert::exception(function () {
throw new Exception('Text');
}, Exception::class, 'Abc');
}, Tester\AssertException::class, "Exception with a message matching 'Abc' was expected but got 'Text'");
Assert::null($e->getPrevious());
Assert::exception(function () {
throw new Exception('Text', 42);
}, Exception::class, null, 42);
$e = Assert::exception(function () {
Assert::exception(function () {
throw new Exception('Text', 1);
}, Exception::class, null, 42);
}, Tester\AssertException::class, 'Exception with a code 42 was expected but got 1');
Assert::null($e->getPrevious());
$old = Assert::$onFailure;
Assert::$onFailure = function () {};
$e = Assert::exception(function () {}, Exception::class);
Assert::$onFailure = $old;
Assert::null($e);