Skip to content

Commit

Permalink
Merge pull request #47 from andypost/master
Browse files Browse the repository at this point in the history
Replace deprecated assertRegExp() with assertMatchesRegularExpression()
  • Loading branch information
dbu authored Nov 2, 2020
2 parents b63c2f5 + ea8151c commit dbc81e5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
34 changes: 22 additions & 12 deletions src/MessageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public function testGetHeaderLine()

$message = $this->getMessage()->withAddedHeader('content-type', 'text/html');
$message = $message->withAddedHeader('content-type', 'text/plain');
$this->assertRegExp('|text/html, ?text/plain|', $message->getHeaderLine('content-type'));
$this->assertRegExp('|text/html, ?text/plain|', $message->getHeaderLine('Content-Type'));
$this->assertRegExp('|text/html, ?text/plain|', $message->getHeaderLine('CONTENT-TYPE'));
$this->assertMatchesRegexp('|text/html, ?text/plain|', $message->getHeaderLine('content-type'));
$this->assertMatchesRegexp('|text/html, ?text/plain|', $message->getHeaderLine('Content-Type'));
$this->assertMatchesRegexp('|text/html, ?text/plain|', $message->getHeaderLine('CONTENT-TYPE'));

$this->assertSame('', $message->getHeaderLine('Bar'));
}
Expand All @@ -121,7 +121,7 @@ public function testWithHeader()
$this->assertEquals('text/script', $message->getHeaderLine('content-type'));

$message = $initialMessage->withHeader('x-foo', ['bar', 'baz']);
$this->assertRegExp('|bar, ?baz|', $message->getHeaderLine('x-foo'));
$this->assertMatchesRegexp('|bar, ?baz|', $message->getHeaderLine('x-foo'));

$message = $initialMessage->withHeader('Bar', '');
$this->assertTrue($message->hasHeader('Bar'));
Expand Down Expand Up @@ -162,8 +162,8 @@ public function testWithAddedHeader()

$message = $this->getMessage()->withAddedHeader('content-type', 'text/html');
$message = $message->withAddedHeader('CONTENT-type', 'text/plain');
$this->assertRegExp('|text/html, ?text/plain|', $message->getHeaderLine('content-type'));
$this->assertRegExp('|text/html, ?text/plain|', $message->getHeaderLine('Content-Type'));
$this->assertMatchesRegexp('|text/html, ?text/plain|', $message->getHeaderLine('content-type'));
$this->assertMatchesRegexp('|text/html, ?text/plain|', $message->getHeaderLine('Content-Type'));
}

/**
Expand Down Expand Up @@ -192,9 +192,9 @@ public function testWithAddedHeaderArrayValue()
$message = $message->withAddedHeader('content-type', ['text/plain', 'application/json']);

$headerLine = $message->getHeaderLine('content-type');
$this->assertRegExp('|text/html|', $headerLine);
$this->assertRegExp('|text/plain|', $headerLine);
$this->assertRegExp('|application/json|', $headerLine);
$this->assertMatchesRegexp('|text/html|', $headerLine);
$this->assertMatchesRegexp('|text/plain|', $headerLine);
$this->assertMatchesRegexp('|application/json|', $headerLine);
}

/**
Expand All @@ -210,9 +210,9 @@ public function testWithAddedHeaderArrayValueAndKeys()
$message = $message->withAddedHeader('content-type', ['foo' => 'text/plain', 'bar' => 'application/json']);

$headerLine = $message->getHeaderLine('content-type');
$this->assertRegExp('|text/html|', $headerLine);
$this->assertRegExp('|text/plain|', $headerLine);
$this->assertRegExp('|application/json|', $headerLine);
$this->assertMatchesRegexp('|text/html|', $headerLine);
$this->assertMatchesRegexp('|text/plain|', $headerLine);
$this->assertMatchesRegexp('|application/json|', $headerLine);
}

public function testWithoutHeader()
Expand Down Expand Up @@ -251,4 +251,14 @@ public function testBody()

$this->assertEquals($stream, $message->getBody());
}

private function assertMatchesRegexp(string $pattern, string $string, string $message = ''): void
{
// @TODO remove when package require phpunit 9.1
if (function_exists('PHPUnit\Framework\assertMatchesRegularExpression')) {
$this->assertMatchesRegularExpression($pattern, $string, $message);
} else {
$this->assertRegExp($pattern, $string, $message);
}
}
}
7 changes: 6 additions & 1 deletion src/UploadedFileIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ public function testGetSize()
$file = $this->createSubject();
$size = $file->getSize();
if ($size) {
$this->assertRegExp('|^[0-9]+$|', (string) $size);
// @TODO remove when package require phpunit 9.1
if (function_exists('PHPUnit\Framework\assertMatchesRegularExpression')) {
$this->assertMatchesRegularExpression('|^[0-9]+$|', (string) $size);
} else {
$this->assertRegExp('|^[0-9]+$|', (string) $size);
}
} else {
$this->assertNull($size);
}
Expand Down

0 comments on commit dbc81e5

Please sign in to comment.