Skip to content

Commit 05b1d00

Browse files
committed
bug #38680 [PhpUnitBridge] Support new expect methods in test case polyfill (alcaeus)
This PR was merged into the 4.4 branch. Discussion ---------- [PhpUnitBridge] Support new expect methods in test case polyfill | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | no | License | MIT This PR adds the `expectError`, `expectWarning`, `expectNotice`, ~and `expectDeprecation`~ methods to the test case polyfill. ~Note that I saw a `expectDeprecation` message in `ExpectDeprecationTrait`, but I couldn't quite figure out what it's supposed to do. Please let me know if the `expectDeprecation` method needs to be removed from the test polyfill.~ Commits ------- 8a49a263a2 Add expectDeprecation, expectNotice, expectWarning, and expectError to TestCase polyfill
2 parents d5477cd + 83fc0dd commit 05b1d00

File tree

1 file changed

+95
-3
lines changed

1 file changed

+95
-3
lines changed

Legacy/PolyfillTestCaseTrait.php

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\Bridge\PhpUnit\Legacy;
1313

14+
use PHPUnit\Framework\Error\Error;
15+
use PHPUnit\Framework\Error\Notice;
16+
use PHPUnit\Framework\Error\Warning;
1417
use PHPUnit\Framework\MockObject\MockObject;
1518
use PHPUnit\Framework\TestCase;
1619

@@ -66,9 +69,7 @@ protected function createPartialMock($originalClassName, array $methods)
6669
*/
6770
public function expectException($exception)
6871
{
69-
$property = new \ReflectionProperty(TestCase::class, 'expectedException');
70-
$property->setAccessible(true);
71-
$property->setValue($this, $exception);
72+
$this->doExpectException($exception);
7273
}
7374

7475
/**
@@ -116,4 +117,95 @@ public function expectExceptionMessageRegExp($messageRegExp)
116117
$property->setAccessible(true);
117118
$property->setValue($this, $messageRegExp);
118119
}
120+
121+
/**
122+
* @return void
123+
*/
124+
public function expectNotice()
125+
{
126+
$this->doExpectException(Notice::class);
127+
}
128+
129+
/**
130+
* @param string $message
131+
*
132+
* @return void
133+
*/
134+
public function expectNoticeMessage($message)
135+
{
136+
$this->expectExceptionMessage($message);
137+
}
138+
139+
/**
140+
* @param string $regularExpression
141+
*
142+
* @return void
143+
*/
144+
public function expectNoticeMessageMatches($regularExpression)
145+
{
146+
$this->expectExceptionMessageMatches($regularExpression);
147+
}
148+
149+
/**
150+
* @return void
151+
*/
152+
public function expectWarning()
153+
{
154+
$this->doExpectException(Warning::class);
155+
}
156+
157+
/**
158+
* @param string $message
159+
*
160+
* @return void
161+
*/
162+
public function expectWarningMessage($message)
163+
{
164+
$this->expectExceptionMessage($message);
165+
}
166+
167+
/**
168+
* @param string $regularExpression
169+
*
170+
* @return void
171+
*/
172+
public function expectWarningMessageMatches($regularExpression)
173+
{
174+
$this->expectExceptionMessageMatches($regularExpression);
175+
}
176+
177+
/**
178+
* @return void
179+
*/
180+
public function expectError()
181+
{
182+
$this->doExpectException(Error::class);
183+
}
184+
185+
/**
186+
* @param string $message
187+
*
188+
* @return void
189+
*/
190+
public function expectErrorMessage($message)
191+
{
192+
$this->expectExceptionMessage($message);
193+
}
194+
195+
/**
196+
* @param string $regularExpression
197+
*
198+
* @return void
199+
*/
200+
public function expectErrorMessageMatches($regularExpression)
201+
{
202+
$this->expectExceptionMessageMatches($regularExpression);
203+
}
204+
205+
private function doExpectException($exception)
206+
{
207+
$property = new \ReflectionProperty(TestCase::class, 'expectedException');
208+
$property->setAccessible(true);
209+
$property->setValue($this, $exception);
210+
}
119211
}

0 commit comments

Comments
 (0)