Forward compatibility for PHP 8.2
Add anonymous classes in tests to avoid setting dynamic properties.
Also, inform PHPUnit that some tests will not perform assertions making the output of PHPUnit less verbose.
MODIFY
test/Db/NoRecordExistsTest.php
test/Db/NoRecordExistsTest.php
@@ -31,7 +31,10 @@ class NoRecordExistsTest extends TestCase
$mockConnection = $this->createMock(ConnectionInterface::class);
// Mock has result
- $mockHasResultRow = new ArrayObject();
+ $mockHasResultRow = new class extends ArrayObject {
+ public ?string $one = null;
+ };
+
$mockHasResultRow->one = 'one';
$mockHasResult = $this->createMock(ResultInterface::class);

MODIFY
test/Db/RecordExistsTest.php
test/Db/RecordExistsTest.php
@@ -35,7 +35,10 @@ class RecordExistsTest extends TestCase
$mockConnection = $this->createMock(ConnectionInterface::class);
// Mock has result
- $mockHasResultRow = new ArrayObject();
+ $mockHasResultRow = new class extends ArrayObject {
+ public ?string $one = null;
+ };
+
$mockHasResultRow->one = 'one';
$mockHasResult = $this->createMock(ResultInterface::class);

MODIFY
test/File/Crc32Test.php
test/File/Crc32Test.php
@@ -104,6 +104,8 @@ class Crc32Test extends TestCase
if (! $expected) {
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
+ } else {
+ $this->expectNotToPerformAssertions();
}
}

MODIFY
test/File/ExcludeExtensionTest.php
test/File/ExcludeExtensionTest.php
@@ -100,6 +100,8 @@ class ExcludeExtensionTest extends TestCase
if (! $expected) {
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
+ } else {
+ $this->expectNotToPerformAssertions();
}
}

MODIFY
test/File/ExistsTest.php
test/File/ExistsTest.php
@@ -78,6 +78,8 @@ class ExistsTest extends TestCase
if (is_array($isValidParam)) {
$validator = new File\Exists($options);
$this->assertEquals($expected, $validator->isValid($isValidParam['tmp_name'], $isValidParam));
+ } else {
+ $this->expectNotToPerformAssertions();
}
}

MODIFY
test/File/ExtensionTest.php
test/File/ExtensionTest.php
@@ -101,6 +101,8 @@ class ExtensionTest extends TestCase
if (! $expected) {
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
+ } else {
+ $this->expectNotToPerformAssertions();
}
}

MODIFY
test/File/HashTest.php
test/File/HashTest.php
@@ -132,6 +132,8 @@ class HashTest extends TestCase
if (! $expected) {
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
+ } else {
+ $this->expectNotToPerformAssertions();
}
}

MODIFY
test/File/ImageSizeTest.php
test/File/ImageSizeTest.php
@@ -168,6 +168,8 @@ class ImageSizeTest extends TestCase
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
}
+ } else {
+ $this->expectNotToPerformAssertions();
}
}

MODIFY
test/File/Md5Test.php
test/File/Md5Test.php
@@ -126,6 +126,8 @@ class Md5Test extends TestCase
if (! $expected) {
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
+ } else {
+ $this->expectNotToPerformAssertions();
}
}

MODIFY
test/File/NotExistsTest.php
test/File/NotExistsTest.php
@@ -79,6 +79,8 @@ class NotExistsTest extends TestCase
if (is_array($isValidParam)) {
$validator = new File\NotExists($options);
$this->assertEquals($expected, $validator->isValid($isValidParam['tmp_name'], $isValidParam));
+ } else {
+ $this->expectNotToPerformAssertions();
}
}

MODIFY
test/File/Sha1Test.php
test/File/Sha1Test.php
@@ -109,6 +109,8 @@ class Sha1Test extends TestCase
if (! $expected) {
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
+ } else {
+ $this->expectNotToPerformAssertions();
}
}

MODIFY
test/File/SizeTest.php
test/File/SizeTest.php
@@ -87,6 +87,8 @@ class SizeTest extends TestCase
if (is_array($isValidParam)) {
$validator = new File\Size($options);
$this->assertEquals($expected, $validator->isValid($isValidParam['tmp_name'], $isValidParam));
+ } else {
+ $this->expectNotToPerformAssertions();
}
}

MODIFY
test/File/WordCountTest.php
test/File/WordCountTest.php
@@ -82,6 +82,8 @@ class WordCountTest extends TestCase
if (is_array($isValidParam)) {
$validator = new File\WordCount($options);
$this->assertEquals($expected, $validator->isValid($isValidParam['tmp_name'], $isValidParam));
+ } else {
+ $this->expectNotToPerformAssertions();
}
}

Forward compatibility for PHP 8.2

Add anonymous classes in tests to avoid setting dynamic properties.
Also, inform PHPUnit that some tests will not perform assertions making the output of PHPUnit less verbose.

Signed-off-by: George Steel <george@net-glue.co.uk>