diff --git a/tests/lib/Files/ObjectStore/ObjectStoreTestCase.php b/tests/lib/Files/ObjectStore/ObjectStoreTestCase.php index 03e7b9545e0..457d9209c99 100644 --- a/tests/lib/Files/ObjectStore/ObjectStoreTestCase.php +++ b/tests/lib/Files/ObjectStore/ObjectStoreTestCase.php @@ -61,6 +61,15 @@ abstract class ObjectStoreTestCase extends TestCase { $this->assertEquals('foobar', stream_get_contents($result)); } + protected function assertOnlyExpectedWarnings(array $warnings): void { + $onlyFopenWarnings = array_reduce( + $warnings, + fn (bool $ok, string $warning) => $ok && str_starts_with($warning, 'fopen('), + true, + ); + $this->assertTrue($onlyFopenWarnings); + } + public function testDelete(): void { $stream = $this->stringToStream('foobar'); @@ -70,25 +79,39 @@ abstract class ObjectStoreTestCase extends TestCase { $instance->deleteObject('2'); + $warnings = []; try { + set_error_handler( + function (int $errno, string $errstr) use (&$warnings): void { + $warnings[] = $errstr; + }, + ); // to to read to verify that the object no longer exists $instance->readObject('2'); $this->fail(); } catch (\Exception $e) { - // dummy assert to keep phpunit happy - $this->assertEquals(1, 1); + $this->assertOnlyExpectedWarnings($warnings); + } finally { + restore_error_handler(); } } public function testReadNonExisting(): void { $instance = $this->getInstance(); + $warnings = []; try { + set_error_handler( + function (int $errno, string $errstr) use (&$warnings): void { + $warnings[] = $errstr; + }, + ); $instance->readObject('non-existing'); $this->fail(); } catch (\Exception $e) { - // dummy assert to keep phpunit happy - $this->assertEquals(1, 1); + $this->assertOnlyExpectedWarnings($warnings); + } finally { + restore_error_handler(); } } diff --git a/tests/lib/Files/ObjectStore/S3Test.php b/tests/lib/Files/ObjectStore/S3Test.php index 2915ada0aab..b75536a214e 100644 --- a/tests/lib/Files/ObjectStore/S3Test.php +++ b/tests/lib/Files/ObjectStore/S3Test.php @@ -110,6 +110,13 @@ class S3Test extends ObjectStoreTestCase { $emptyStream = fopen('php://memory', 'r'); fwrite($emptyStream, ''); + $warnings = []; + set_error_handler( + function (int $errno, string $errstr) use (&$warnings): void { + $warnings[] = $errstr; + }, + ); + $s3->writeObject('emptystream', $emptyStream); $this->assertNoUpload('emptystream'); @@ -126,6 +133,8 @@ class S3Test extends ObjectStoreTestCase { self::assertTrue($thrown, 'readObject with range requests are not expected to work on empty objects'); $s3->deleteObject('emptystream'); + $this->assertOnlyExpectedWarnings($warnings); + restore_error_handler(); } /** File size to upload in bytes */