Skip to content

Replace deprecated assertRegExp() with assertMatchesRegularExpression() #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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