mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-01 20:43:49 +00:00
Use "createdAt" from database to compute the last modified datetime in StoredObjectManager
The code has been updated to use 'createdAt' from StoredObjectVersion entity in StoredObjectManager. Specifically, if a 'createdAt' datetime is set, we return that datetime. This change also includes corresponding test cases to validate the functionality. The situation helps deal with files created before July 2024.
This commit is contained in:
@@ -233,6 +233,64 @@ final class StoredObjectManagerTest extends TestCase
|
||||
$manager->write($storedObject, 'ok');
|
||||
}
|
||||
|
||||
public function testGetLastModifiedWithDateTimeInEntity(): void
|
||||
{
|
||||
$version = ($storedObject = new StoredObject())->registerVersion();
|
||||
$version->setCreatedAt(new \DateTimeImmutable('2024-07-09 15:09:47', new \DateTimeZone('+00:00')));
|
||||
$client = $this->createMock(HttpClientInterface::class);
|
||||
$client->expects(self::never())->method('request')->withAnyParameters();
|
||||
|
||||
$tempUrlGenerator = $this->createMock(TempUrlGeneratorInterface::class);
|
||||
$tempUrlGenerator
|
||||
->expects($this->never())
|
||||
->method('generate')
|
||||
->with($this->identicalTo('HEAD'), $this->isType('string'))
|
||||
->willReturnCallback(function (string $method, string $objectName) {
|
||||
return new SignedUrl(
|
||||
$method,
|
||||
'https://example.com/'.$objectName,
|
||||
new \DateTimeImmutable('1 hours'),
|
||||
$objectName
|
||||
);
|
||||
});
|
||||
|
||||
$manager = new StoredObjectManager($client, $tempUrlGenerator);
|
||||
|
||||
$actual = $manager->getLastModified($storedObject);
|
||||
|
||||
self::assertEquals(new \DateTimeImmutable('2024-07-09 15:09:47 GMT'), $actual);
|
||||
}
|
||||
|
||||
public function testGetLastModifiedWithDateTimeFromResponse(): void
|
||||
{
|
||||
$storedObject = (new StoredObject())->registerVersion()->getStoredObject();
|
||||
|
||||
$client = new MockHttpClient(
|
||||
new MockResponse('', ['http_code' => 200, 'response_headers' => [
|
||||
'last-modified' => 'Tue, 09 Jul 2024 15:09:47 GMT',
|
||||
]])
|
||||
);
|
||||
|
||||
$tempUrlGenerator = $this->createMock(TempUrlGeneratorInterface::class);
|
||||
$tempUrlGenerator
|
||||
->expects($this->atLeastOnce())
|
||||
->method('generate')
|
||||
->with($this->identicalTo('HEAD'), $this->isType('string'))
|
||||
->willReturnCallback(function (string $method, string $objectName) {
|
||||
return new SignedUrl(
|
||||
$method,
|
||||
'https://example.com/'.$objectName,
|
||||
new \DateTimeImmutable('1 hours')
|
||||
);
|
||||
});
|
||||
|
||||
$manager = new StoredObjectManager($client, $tempUrlGenerator);
|
||||
|
||||
$actual = $manager->getLastModified($storedObject);
|
||||
|
||||
self::assertEquals(new \DateTimeImmutable('2024-07-09 15:09:47 GMT'), $actual);
|
||||
}
|
||||
|
||||
private function getHttpClient(string $encodedContent): HttpClientInterface
|
||||
{
|
||||
$callback = static function ($method, $url, $options) use ($encodedContent) {
|
||||
@@ -283,7 +341,8 @@ final class StoredObjectManagerTest extends TestCase
|
||||
return new SignedUrl(
|
||||
$method,
|
||||
'https://example.com/'.$objectName,
|
||||
new \DateTimeImmutable('1 hours')
|
||||
new \DateTimeImmutable('1 hours'),
|
||||
$objectName
|
||||
);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user