Skip to content

Commit a77d5fe

Browse files
committed
Replace calls to setExpectedException by Pollyfill
1 parent 70d308f commit a77d5fe

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

Tests/InlineTest.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,8 @@ public function testParseUnquotedAsteriskFollowedByAComment()
307307
*/
308308
public function testParseUnquotedScalarStartingWithReservedIndicator($indicator)
309309
{
310-
if (method_exists($this, 'expectExceptionMessage')) {
311-
$this->expectException(ParseException::class);
312-
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
313-
} else {
314-
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
315-
}
310+
$this->expectException(ParseException::class);
311+
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
316312

317313
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
318314
}
@@ -327,12 +323,8 @@ public function getReservedIndicators()
327323
*/
328324
public function testParseUnquotedScalarStartingWithScalarIndicator($indicator)
329325
{
330-
if (method_exists($this, 'expectExceptionMessage')) {
331-
$this->expectException(ParseException::class);
332-
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
333-
} else {
334-
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
335-
}
326+
$this->expectException(ParseException::class);
327+
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
336328

337329
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
338330
}
@@ -700,11 +692,7 @@ public function getBinaryData()
700692
*/
701693
public function testParseInvalidBinaryData($data, $expectedMessage)
702694
{
703-
if (method_exists($this, 'expectException')) {
704-
$this->expectExceptionMessageRegExp($expectedMessage);
705-
} else {
706-
$this->setExpectedExceptionRegExp(ParseException::class, $expectedMessage);
707-
}
695+
$this->expectExceptionMessageRegExp($expectedMessage);
708696

709697
Inline::parse($data);
710698
}

Tests/ParserTest.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,11 +1488,7 @@ public function getBinaryData()
14881488
*/
14891489
public function testParseInvalidBinaryData($data, $expectedMessage)
14901490
{
1491-
if (method_exists($this, 'expectException')) {
1492-
$this->expectExceptionMessageRegExp($expectedMessage);
1493-
} else {
1494-
$this->setExpectedExceptionRegExp(ParseException::class, $expectedMessage);
1495-
}
1491+
$this->expectExceptionMessageRegExp($expectedMessage);
14961492

14971493
$this->parser->parse($data);
14981494
}
@@ -1559,12 +1555,8 @@ public function testParseDateAsMappingValue()
15591555
*/
15601556
public function testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml)
15611557
{
1562-
if (method_exists($this, 'expectException')) {
1563-
$this->expectException('\Symfony\Component\Yaml\Exception\ParseException');
1564-
$this->expectExceptionMessage(sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber));
1565-
} else {
1566-
$this->setExpectedException('\Symfony\Component\Yaml\Exception\ParseException', sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber));
1567-
}
1558+
$this->expectException('\Symfony\Component\Yaml\Exception\ParseException');
1559+
$this->expectExceptionMessage(sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber));
15681560

15691561
$this->parser->parse($yaml);
15701562
}

0 commit comments

Comments
 (0)