mirror of
https://github.com/nextcloud/server.git
synced 2026-04-02 15:45:38 -04:00
fix(tests): Ignore expected warning for s3 tests
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
3e4531dd05
commit
8107f614d8
2 changed files with 36 additions and 4 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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…
Reference in a new issue