From abbe5a3714c9bc514dabf9e75ebde22a907ada56 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Tue, 15 Oct 2019 19:28:43 -0700 Subject: [PATCH] tests: @expectedException is deprecated Bug: T234597 Change-Id: Ib694f60dabc9a8ac94fb10ed187892af8f36377e --- .phpcs.xml | 2 -- tests/phpunit/MathFormatterTest.php | 8 ++----- tests/phpunit/MathRestbaseInterfaceTest.php | 26 ++++++++------------- tests/phpunit/MathValidatorTest.php | 8 ++----- 4 files changed, 14 insertions(+), 30 deletions(-) diff --git a/.phpcs.xml b/.phpcs.xml index cc4ded7c9..36777d3ba 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -7,8 +7,6 @@ - - . diff --git a/tests/phpunit/MathFormatterTest.php b/tests/phpunit/MathFormatterTest.php index c007c79eb..e89d0021d 100644 --- a/tests/phpunit/MathFormatterTest.php +++ b/tests/phpunit/MathFormatterTest.php @@ -42,19 +42,15 @@ class MathFormatterTest extends MediaWikiTestCase { $this->assertSame( SnakFormatter::FORMAT_PLAIN, $formatter->getFormat(), 'test getFormat' ); } - /** - * @expectedException InvalidArgumentException - */ public function testNotStringValue() { $formatter = new MathFormatter( SnakFormatter::FORMAT_PLAIN ); + $this->expectException( InvalidArgumentException::class ); $formatter->format( new NumberValue( 0 ) ); } - /** - * @expectedException InvalidArgumentException - */ public function testNullValue() { $formatter = new MathFormatter( SnakFormatter::FORMAT_PLAIN ); + $this->expectException( InvalidArgumentException::class ); $formatter->format( null ); } diff --git a/tests/phpunit/MathRestbaseInterfaceTest.php b/tests/phpunit/MathRestbaseInterfaceTest.php index 5b76a17eb..f0bbfdc0e 100644 --- a/tests/phpunit/MathRestbaseInterfaceTest.php +++ b/tests/phpunit/MathRestbaseInterfaceTest.php @@ -66,56 +66,50 @@ class MathRestbaseInterfaceTest extends MediaWikiTestCase { $this->assertContains( 'H', $rbi->getMathML() ); } - /** - * @expectedException MWException - * @expectedExceptionMessage TeX input is invalid. - */ public function testException() { $input = '\\newcommand'; $rbi = new MathRestbaseInterface( $input ); + $this->expectException( MWException::class ); + $this->expectExceptionMessage( 'TeX input is invalid.' ); $rbi->getMathML(); } - /** - * @expectedException MWException - * @expectedExceptionMessage TeX input is invalid. - */ public function testExceptionSvg() { $input = '\\newcommand'; $rbi = new MathRestbaseInterface( $input ); + $this->expectException( MWException::class ); + $this->expectExceptionMessage( 'TeX input is invalid.' ); $rbi->getFullSvgUrl(); } /** * Incorporate the "details" in the error message, if the check requests passes, but the * mml/svg/complete endpoints returns an error - * @expectedException MWException - * @expectedExceptionMessage Cannot get mml. TeX parse error: Missing close brace */ public function testLateError() { // phpcs:ignore Generic.Files.LineLength.TooLong $input = '{"type":"https://mediawiki.org/wiki/HyperSwitch/errors/bad_request","title":"Bad Request","method":"POST","detail":["TeX parse error: Missing close brace"],"uri":"/complete"}'; + $this->expectException( MWException::class ); + $this->expectExceptionMessage( 'Cannot get mml. TeX parse error: Missing close brace' ); MathRestbaseInterface::throwContentError( 'mml', $input ); } /** * Incorporate the "details" in the error message, if the check requests passes, but the * mml/svg/complete endpoints returns an error - * @expectedException MWException - * @expectedExceptionMessage Cannot get mml. TeX parse error: Missing close brace */ public function testLateErrorString() { // phpcs:ignore Generic.Files.LineLength.TooLong $input = '{"type":"https://mediawiki.org/wiki/HyperSwitch/errors/bad_request","title":"Bad Request","method":"POST","detail": "TeX parse error: Missing close brace","uri":"/complete"}'; + $this->expectException( MWException::class ); + $this->expectExceptionMessage( 'Cannot get mml. TeX parse error: Missing close brace' ); MathRestbaseInterface::throwContentError( 'mml', $input ); } - /** - * @expectedException MWException - * @expectedExceptionMessage Cannot get mml. Server problem. - */ public function testLateErrorNoDetail() { $input = ''; + $this->expectException( MWException::class ); + $this->expectExceptionMessage( 'Cannot get mml. Server problem.' ); MathRestbaseInterface::throwContentError( 'mml', $input ); } } diff --git a/tests/phpunit/MathValidatorTest.php b/tests/phpunit/MathValidatorTest.php index a46414c4f..0c0a0a8e5 100644 --- a/tests/phpunit/MathValidatorTest.php +++ b/tests/phpunit/MathValidatorTest.php @@ -37,19 +37,15 @@ class MathValidatorTest extends MediaWikiTestCase { parent::tearDown(); } - /** - * @expectedException InvalidArgumentException - */ public function testNotStringValue() { $validator = new MathValidator(); + $this->expectException( InvalidArgumentException::class ); $validator->validate( new NumberValue( 0 ) ); } - /** - * @expectedException InvalidArgumentException - */ public function testNullValue() { $validator = new MathValidator(); + $this->expectException( InvalidArgumentException::class ); $validator->validate( null ); }