From ea8151c742eb19fdb012c731928a1ade038cac4b Mon Sep 17 00:00:00 2001 From: Andy Postnikov Date: Sun, 1 Nov 2020 23:22:26 +0200 Subject: [PATCH] Replace deprecated assertRegExp() with assertMatchesRegularExpression() --- src/MessageTrait.php | 34 +++++++++++++++++++---------- src/UploadedFileIntegrationTest.php | 7 +++++- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/MessageTrait.php b/src/MessageTrait.php index 29cc4b7..5b30d16 100644 --- a/src/MessageTrait.php +++ b/src/MessageTrait.php @@ -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')); } @@ -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')); @@ -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')); } /** @@ -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); } /** @@ -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() @@ -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); + } + } } diff --git a/src/UploadedFileIntegrationTest.php b/src/UploadedFileIntegrationTest.php index 8451ce1..b00379b 100644 --- a/src/UploadedFileIntegrationTest.php +++ b/src/UploadedFileIntegrationTest.php @@ -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); }