-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathTestCase.annotationThrows.phpt
166 lines (124 loc) · 3.12 KB
/
TestCase.annotationThrows.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
declare(strict_types=1);
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
class MyException extends Exception
{
}
class MyTest extends Tester\TestCase
{
/** @throws Exception */
public function testThrows()
{
throw new Exception;
}
/** @throws Exception */
public function testThrowsButDont()
{
}
/** @throws Exception With message */
public function testThrowsMessage()
{
throw new Exception('With message');
}
/** @throws Exception */
public function testFailAssertPass()
{
Assert::fail('failed');
}
/** @throws MyException */
public function testThrowsBadClass()
{
throw new Exception;
}
/** @throws Exception With message */
public function testThrowsBadMessage()
{
throw new Exception('Bad message');
}
/** @throws E_NOTICE */
public function testNotice()
{
$a = &pi();
}
/** @throws E_NOTICE Only variables should be assigned by reference */
public function testNoticeMessage()
{
$a = &pi();
}
/** @throws E_WARNING */
public function testBadError()
{
$a = &pi();
}
/** @throws E_NOTICE With message */
public function testNoticeBadMessage()
{
$a = &pi();
}
// Without @throws
public function testWithoutThrows()
{
throw new Exception;
}
public function dataProvider()
{
return [[1]];
}
/**
* @dataProvider dataProvider
* @throws Exception
*/
public function testThrowsWithDataprovider($x)
{
}
}
$test = new MyTest;
$test->runTest('testThrows');
$test->runTest('testThrowsMessage');
Assert::exception(
fn() => $test->runTest('testThrowsButDont'),
Tester\AssertException::class,
'Exception was expected, but none was thrown in testThrowsButDont()',
);
Assert::exception(
fn() => $test->runTest('testFailAssertPass'),
Tester\AssertException::class,
'failed in testFailAssertPass()',
);
Assert::exception(
fn() => $test->runTest('testThrowsBadClass'),
Tester\AssertException::class,
'MyException was expected but got Exception in testThrowsBadClass()',
);
Assert::exception(
fn() => $test->runTest('testThrowsBadMessage'),
Tester\AssertException::class,
"Exception with a message matching 'With message' was expected but got 'Bad message' in testThrowsBadMessage()",
);
Assert::exception(
fn() => $test->runTest('testWithoutThrows'),
Exception::class,
);
Assert::exception(
fn() => $test->runTest('testThrowsWithDataprovider'),
Exception::class,
"Exception was expected, but none was thrown in testThrowsWithDataprovider(1) (data set '0')",
);
Assert::exception(
fn() => $test->runTest('testUndefinedMethod'),
Tester\TestCaseException::class,
"Method 'testUndefinedMethod' does not exist.",
);
$test->runTest('testNotice');
$test->runTest('testNoticeMessage');
Assert::exception(
fn() => $test->runTest('testBadError'),
Tester\AssertException::class,
'E_WARNING was expected, but E_NOTICE (Only variables should be assigned by reference) was generated in %a%testBadError()',
);
Assert::exception(
fn() => $test->runTest('testNoticeBadMessage'),
Tester\AssertException::class,
"E_NOTICE with a message matching 'With message' was expected but got 'Only variables should be assigned by reference' in testNoticeBadMessage()",
);