diff --git a/src/FileInfo.php b/src/FileInfo.php index e40f922..be01137 100644 --- a/src/FileInfo.php +++ b/src/FileInfo.php @@ -94,7 +94,7 @@ public function __toString(): string return $this->link(); } - public function jsonSerialize(): array + public function toArray(): array { return [ 'path' => $this->pathInfo->getPath(), @@ -102,4 +102,9 @@ public function jsonSerialize(): array 'version' => $this->pathInfo->getVersion(), ]; } + + public function jsonSerialize(): array + { + return $this->toArray(); + } } diff --git a/src/FileInfoInterface.php b/src/FileInfoInterface.php index ca58999..6c7699b 100644 --- a/src/FileInfoInterface.php +++ b/src/FileInfoInterface.php @@ -12,6 +12,11 @@ public function getStorageName(): string; public function link(): string; + /** + * @return array{path: string, storage: string, version: ?string} + */ + public function toArray(): array; + /** * @return array{path: string, storage: string, version: ?string} */ diff --git a/tests/FileInfoTest.phpt b/tests/FileInfoTest.phpt index fe60a01..0d3ff14 100644 --- a/tests/FileInfoTest.phpt +++ b/tests/FileInfoTest.phpt @@ -180,6 +180,31 @@ final class FileInfoTest extends TestCase Assert::same('https://www.example.com/files/file.json', $fileInfo->link()); } + public function testFileInfoShouldBeConvertedToArray(): void + { + $linkGenerator = Mockery::mock(LinkGeneratorInterface::class); + $pathInfo = Mockery::mock(PathInfoInterface::class); + + $pathInfo->shouldReceive('getPath') + ->once() + ->andReturn('var/www/file.json'); + + $pathInfo->shouldReceive('getVersion') + ->once() + ->andReturn('123'); + + $fileInfo = new FileInfo($linkGenerator, $pathInfo, 'default'); + + Assert::same( + [ + 'path' => 'var/www/file.json', + 'storage' => 'default', + 'version' => '123', + ], + $fileInfo->toArray(), + ); + } + public function testFileInfoShouldBeSerializedIntoJson(): void { $linkGenerator = Mockery::mock(LinkGeneratorInterface::class);