Use assertStringContainsString in unit tests

Using assertContains() with string haystacks is deprecated and will not
be supported in PHPUnit 9. Refactor your test to use
assertStringContainsString() or assertStringContainsStringIgnoringCase()
instead.

Change-Id: Ic35f3c60a7f49dfe244b87192d7f161c117b37e1
This commit is contained in:
Umherirrender 2020-04-05 13:38:45 +02:00
parent f0a67751d0
commit e599afa6db
6 changed files with 42 additions and 35 deletions

View file

@ -58,7 +58,7 @@ class MathFormatterTest extends MediaWikiTestCase {
$formatter = new MathFormatter( 'unknown/unknown' );
$value = new StringValue( self::SOME_TEX );
$resultFormat = $formatter->format( $value );
$this->assertContains( '</math>', $resultFormat );
$this->assertStringContainsString( '</math>', $resultFormat );
}
/**
@ -68,7 +68,7 @@ class MathFormatterTest extends MediaWikiTestCase {
$formatter = new MathFormatter( 'unknown/unknown' );
$value = new StringValue( '\noTex' );
$resultFormat = $formatter->format( $value );
$this->assertContains( 'unknown function', $resultFormat );
$this->assertStringContainsString( 'unknown function', $resultFormat );
}
public function testFormatPlain() {
@ -82,18 +82,22 @@ class MathFormatterTest extends MediaWikiTestCase {
$formatter = new MathFormatter( SnakFormatter::FORMAT_HTML );
$value = new StringValue( self::SOME_TEX );
$resultFormat = $formatter->format( $value );
$this->assertContains( '</math>', $resultFormat, 'Result must contain math-tag' );
$this->assertStringContainsString( '</math>', $resultFormat, 'Result must contain math-tag' );
}
public function testFormatDiffHtml() {
$formatter = new MathFormatter( SnakFormatter::FORMAT_HTML_DIFF );
$value = new StringValue( self::SOME_TEX );
$resultFormat = $formatter->format( $value );
$this->assertContains( '</math>', $resultFormat, 'Result must contain math-tag' );
$this->assertContains( '</h4>', $resultFormat, 'Result must contain a <h4> tag' );
$this->assertContains( '</code>', $resultFormat, 'Result must contain a <code> tag' );
$this->assertContains( 'wb-details', $resultFormat, 'Result must contain wb-details class' );
$this->assertContains(
$this->assertStringContainsString( '</math>', $resultFormat, 'Result must contain math-tag' );
$this->assertStringContainsString( '</h4>', $resultFormat, 'Result must contain a <h4> tag' );
$this->assertStringContainsString( '</code>', $resultFormat, 'Result must contain a <code> tag' );
$this->assertStringContainsString(
'wb-details',
$resultFormat,
'Result must contain wb-details class'
);
$this->assertStringContainsString(
htmlspecialchars( self::SOME_TEX ),
$resultFormat,
'Result must contain the TeX source'

View file

@ -42,7 +42,7 @@ class MathInputCheckRestbaseTest extends MediaWikiTestCase {
$expectedMessage = wfMessage(
'math_unknown_function', '\newcommand'
)->inContentLanguage()->escaped();
$this->assertContains( $expectedMessage, $this->BadObject->getError() );
$this->assertStringContainsString( $expectedMessage, $this->BadObject->getError() );
}
/**
@ -52,7 +52,7 @@ class MathInputCheckRestbaseTest extends MediaWikiTestCase {
$o = new MathInputCheckRestbase( '\left(' );
$this->assertFalse( $o->isValid() );
$expectedMessage = wfMessage( 'math_syntax_error' )->inContentLanguage()->escaped();
$this->assertContains( $expectedMessage, $o->getError() );
$this->assertStringContainsString( $expectedMessage, $o->getError() );
}
/**
@ -67,7 +67,7 @@ class MathInputCheckRestbaseTest extends MediaWikiTestCase {
// [-+*=], [0-9], [><~], [\\/|] or [a-zA-Z] but "\\u0301" found.
// is more expressive anyhow.
$expectedMessage = wfMessage( 'math_syntax_error' )->inContentLanguage()->escaped();
$this->assertContains( $expectedMessage, $o->getError() );
$this->assertStringContainsString( $expectedMessage, $o->getError() );
}
/**

View file

@ -54,18 +54,21 @@ class MathMLRdfBuilderTest extends MediaWikiTestCase {
public function testValidInput() {
$triples = $this->makeCase( 'a^2' );
$this->assertContains( self::ACME_PREFIX_URL . self::ACME_REF . '> "<math', $triples );
$this->assertContains( '<mi>a</mi>\n', $triples );
$this->assertContains( '<mn>2</mn>\n', $triples );
$this->assertContains( 'a^{2}', $triples );
$this->assertContains( '^^<http://www.w3.org/1998/Math/MathML> .', $triples );
$this->assertStringContainsString(
self::ACME_PREFIX_URL . self::ACME_REF . '> "<math',
$triples
);
$this->assertStringContainsString( '<mi>a</mi>\n', $triples );
$this->assertStringContainsString( '<mn>2</mn>\n', $triples );
$this->assertStringContainsString( 'a^{2}', $triples );
$this->assertStringContainsString( '^^<http://www.w3.org/1998/Math/MathML> .', $triples );
}
public function testInvalidInput() {
$triples = $this->makeCase( '\notExists' );
$this->assertContains( '<math', $triples );
$this->assertContains( 'unknown function', $triples );
$this->assertContains( 'notExists', $triples );
$this->assertContains( '^^<http://www.w3.org/1998/Math/MathML> .', $triples );
$this->assertStringContainsString( '<math', $triples );
$this->assertStringContainsString( 'unknown function', $triples );
$this->assertStringContainsString( 'notExists', $triples );
$this->assertStringContainsString( '^^<http://www.w3.org/1998/Math/MathML> .', $triples );
}
}

View file

@ -82,7 +82,7 @@ class MathMathMLTest extends MediaWikiTestCase {
$this->assertNull( $res,
"res is null if HTTP::post returns false." );
$errmsg = wfMessage( 'math_invalidresponse', '', $url, '' )->inContentLanguage()->escaped();
$this->assertContains( $errmsg, $error,
$this->assertStringContainsString( $errmsg, $error,
"return an error if HTTP::post returns false" );
}
@ -120,7 +120,7 @@ class MathMathMLTest extends MediaWikiTestCase {
$this->assertFalse( $requestReturn, "timeout call return" );
$this->assertFalse( $res, "timeout call return" );
$errmsg = wfMessage( 'math_timeout', '', $url )->inContentLanguage()->escaped();
$this->assertContains( $errmsg, $error, "timeout call errormessage" );
$this->assertStringContainsString( $errmsg, $error, "timeout call errormessage" );
}
/**
@ -188,8 +188,8 @@ class MathMathMLTest extends MediaWikiTestCase {
$po = ParserOptions::newFromAnon();
$t = Title::newFromText( __METHOD__ );
$res = $p->parse( '[[test|<math forcemathmode="png">a+b</math>]]', $t, $po )->getText();
$this->assertContains( '</a>', $res );
$this->assertContains( 'png', $res );
$this->assertStringContainsString( '</a>', $res );
$this->assertStringContainsString( 'png', $res );
}
/**
@ -247,13 +247,13 @@ class MathMathMLTest extends MediaWikiTestCase {
public function testGetHtmlOutputQID() {
$math = new MathMathML( "a+b", [ "qid" => "Q123" ] );
$out = $math->getHtmlOutput();
$this->assertContains( "data-qid=\"Q123\"", $out );
$this->assertStringContainsString( "data-qid=\"Q123\"", $out );
}
public function testGetHtmlOutputInvalidQID() {
// test with not valid ID. An ID must match /Q\d+/
$math = new MathMathML( "a+b", [ "qid" => "123" ] );
$out = $math->getHtmlOutput();
$this->assertNotContains( "data-qid", $out );
$this->assertStringNotContainsString( "data-qid", $out );
}
}

View file

@ -40,12 +40,12 @@ class MathRestbaseInterfaceTest extends MediaWikiTestCase {
$rbi = new MathRestbaseInterface( $input );
$this->assertTrue( $rbi->getSuccess(), "Assuming that $input is valid input." );
$this->assertEquals( '\\sin x^{2}', $rbi->getCheckedTex() );
$this->assertContains( '<mi>sin</mi>', $rbi->getMathML() );
$this->assertStringContainsString( '<mi>sin</mi>', $rbi->getMathML() );
$url = $rbi->getFullSvgUrl();
$req = MWHttpRequest::factory( $url );
$status = $req->execute();
$this->assertTrue( $status->isOK() );
$this->assertContains( '</svg>', $req->getContent() );
$this->assertStringContainsString( '</svg>', $req->getContent() );
}
public function testFail() {
@ -62,8 +62,8 @@ class MathRestbaseInterfaceTest extends MediaWikiTestCase {
$this->assertTrue( $rbi->checkTeX(), "Assuming that $input is valid input." );
$this->assertTrue( $rbi->getSuccess(), "Assuming that $input is valid input." );
$this->assertEquals( '{\ce {H2O}}', $rbi->getCheckedTex() );
$this->assertContains( '<msubsup>', $rbi->getMathML() );
$this->assertContains( '<mtext>H</mtext>', $rbi->getMathML() );
$this->assertStringContainsString( '<msubsup>', $rbi->getMathML() );
$this->assertStringContainsString( '<mtext>H</mtext>', $rbi->getMathML() );
}
public function testException() {

View file

@ -35,7 +35,7 @@ class MathoidCliTest extends MediaWikiTestCase {
$input = [ 'good' => [ $mml ] ];
MathMathMLCli::batchEvaluate( $input );
$this->assertTrue( $mml->render(), 'assert that renders' );
$this->assertContains( '</mo>', $mml->getMathml() );
$this->assertStringContainsString( '</mo>', $mml->getMathml() );
}
public function testUndefinedFunctionError() {
@ -43,7 +43,7 @@ class MathoidCliTest extends MediaWikiTestCase {
$input = [ 'bad' => [ $mml ] ];
MathMathMLCli::batchEvaluate( $input );
$this->assertFalse( $mml->render(), 'assert that fails' );
$this->assertContains( 'newcommand', $mml->getLastError() );
$this->assertStringContainsString( 'newcommand', $mml->getLastError() );
}
public function testSyntaxError() {
@ -51,7 +51,7 @@ class MathoidCliTest extends MediaWikiTestCase {
$input = [ 'bad' => [ $mml ] ];
MathMathMLCli::batchEvaluate( $input );
$this->assertFalse( $mml->render(), 'assert that fails' );
$this->assertContains( 'SyntaxError', $mml->getLastError() );
$this->assertStringContainsString( 'SyntaxError', $mml->getLastError() );
}
public function testCeError() {
@ -59,7 +59,7 @@ class MathoidCliTest extends MediaWikiTestCase {
$input = [ 'bad' => [ $mml ] ];
MathMathMLCli::batchEvaluate( $input );
$this->assertFalse( $mml->render(), 'assert that fails' );
$this->assertContains( 'SyntaxError', $mml->getLastError() );
$this->assertStringContainsString( 'SyntaxError', $mml->getLastError() );
}
public function testEmpty() {
@ -68,7 +68,7 @@ class MathoidCliTest extends MediaWikiTestCase {
MathMathMLCli::batchEvaluate( $input );
$this->assertFalse( $mml->render(), 'assert that renders' );
$this->assertFalse( $mml->isTexSecure() );
$this->assertContains( 'empty', $mml->getLastError() );
$this->assertStringContainsString( 'empty', $mml->getLastError() );
}
}