Browse Source

fix(tests): Ignore expected warning for s3 tests

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/54905/head
Côme Chilliet 3 weeks ago
parent
commit
8107f614d8
No known key found for this signature in database GPG Key ID: A3E2F658B28C760A
  1. 31
      tests/lib/Files/ObjectStore/ObjectStoreTestCase.php
  2. 9
      tests/lib/Files/ObjectStore/S3Test.php

31
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();
}
}

9
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 */

Loading…
Cancel
Save